Skip to content

Commit 980cc4b

Browse files
committed
bazel: win: Explicitly link libcef.lib in cc_binary (see #3757)
Using cc_import + interface_library/shared_library to link libcef.lib causes libcef.dll to be copied as a transitive dependency, leading to issues with complex Bazel configs. Instead, we explicitly link libcef.lib in the binary target (cc_binary + linkopts/additional_linker_inputs) and explicitly copy libcef.dll to the target directory.
1 parent 213c028 commit 980cc4b

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

bazel/win/exe_helpers.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def declare_exe(name, srcs, manifest_srcs, rc_file, resources_srcs, resources_de
4747
srcs = srcs,
4848
deps = [
4949
"@cef//:cef_wrapper",
50-
"@cef//:cef",
5150
"@cef//:cef_sandbox",
5251
] + deps,
5352
linkopts = [
53+
"$(location @cef//:cef_lib)",
5454
"$(location :{})".format(res_target),
5555
] + COMMON_LINKOPTS + linkopts,
5656
copts = COMMON_COPTS + select({
@@ -62,6 +62,7 @@ def declare_exe(name, srcs, manifest_srcs, rc_file, resources_srcs, resources_de
6262
"//conditions:default": COMMON_DEFINES_RELEASE,
6363
}) + local_defines,
6464
additional_linker_inputs = [
65+
"@cef//:cef_lib",
6566
":{}".format(res_target),
6667
] + additional_linker_inputs,
6768
data = [

bazel/win/variables.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# Distribution DLLs.
77
#
88

9-
# NOTE: libcef.dll is included via the //:cef dependency.
109
DLLS = [
1110
"chrome_elf.dll",
1211
"d3dcompiler_47.dll",
12+
"libcef.dll",
1313
"libEGL.dll",
1414
"libGLESv2.dll",
1515
"vk_swiftshader.dll",

tools/distrib/bazel/BUILD.bazel

+31-11
Original file line numberDiff line numberDiff line change
@@ -274,29 +274,19 @@ alias(
274274
})
275275
)
276276

277-
# Only available on Linux/Windows.
277+
# Only available on Linux.
278278
cc_import(
279279
name = "cef_dbg",
280-
interface_library = select({
281-
"@platforms//os:windows": "Debug/libcef.lib",
282-
"//conditions:default": None,
283-
}),
284280
shared_library = select({
285281
"@platforms//os:linux": "Debug/libcef.so",
286-
"@platforms//os:windows": "Debug/libcef.dll",
287282
"//conditions:default": None,
288283
}),
289284
)
290285

291286
cc_import(
292287
name = "cef_opt",
293-
interface_library = select({
294-
"@platforms//os:windows": "Release/libcef.lib",
295-
"//conditions:default": None,
296-
}),
297288
shared_library = select({
298289
"@platforms//os:linux": "Release/libcef.so",
299-
"@platforms//os:windows": "Release/libcef.dll",
300290
"//conditions:default": None,
301291
}),
302292
)
@@ -309,6 +299,36 @@ alias(
309299
}),
310300
)
311301

302+
# Only available on Windows.
303+
# Using cc_import + interface_library/shared_library to link libcef.lib causes
304+
# libcef.dll to be copied as a transitive dependency, leading to issues with
305+
# complex Bazel configs. Instead, we explicitly link libcef.lib in the binary
306+
# target (cc_binary + linkopts/additional_linker_inputs) and explicitly copy
307+
# libcef.dll to the target directory.
308+
alias(
309+
name = "cef_lib_dbg",
310+
actual = select({
311+
"@platforms//os:windows": "Debug/libcef.lib",
312+
"//conditions:default": None,
313+
}),
314+
)
315+
316+
alias(
317+
name = "cef_lib_opt",
318+
actual = select({
319+
"@platforms//os:windows": "Release/libcef.lib",
320+
"//conditions:default": None,
321+
}),
322+
)
323+
324+
alias(
325+
name = "cef_lib",
326+
actual = select({
327+
"@cef//:dbg": "@cef//:cef_lib_dbg",
328+
"//conditions:default": "@cef//:cef_lib_opt",
329+
}),
330+
)
331+
312332
# Copy the CEF framework into the app bundle but do not link it. See
313333
# https://groups.google.com/g/cef-announce/c/Fith0A3kWtw/m/6ds_mJVMCQAJ
314334
# for background. Use `copy_directory` instead of `filegroup` to remove

0 commit comments

Comments
 (0)