From 980cc4b9fef332869d40b316481a683e200031c0 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 5 Nov 2024 11:46:31 -0500 Subject: [PATCH] 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. --- bazel/win/exe_helpers.bzl | 3 ++- bazel/win/variables.bzl | 2 +- tools/distrib/bazel/BUILD.bazel | 42 ++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/bazel/win/exe_helpers.bzl b/bazel/win/exe_helpers.bzl index ba4576c07..23da465ab 100644 --- a/bazel/win/exe_helpers.bzl +++ b/bazel/win/exe_helpers.bzl @@ -47,10 +47,10 @@ def declare_exe(name, srcs, manifest_srcs, rc_file, resources_srcs, resources_de srcs = srcs, deps = [ "@cef//:cef_wrapper", - "@cef//:cef", "@cef//:cef_sandbox", ] + deps, linkopts = [ + "$(location @cef//:cef_lib)", "$(location :{})".format(res_target), ] + COMMON_LINKOPTS + linkopts, copts = COMMON_COPTS + select({ @@ -62,6 +62,7 @@ def declare_exe(name, srcs, manifest_srcs, rc_file, resources_srcs, resources_de "//conditions:default": COMMON_DEFINES_RELEASE, }) + local_defines, additional_linker_inputs = [ + "@cef//:cef_lib", ":{}".format(res_target), ] + additional_linker_inputs, data = [ diff --git a/bazel/win/variables.bzl b/bazel/win/variables.bzl index a3dd5742a..d9f136078 100644 --- a/bazel/win/variables.bzl +++ b/bazel/win/variables.bzl @@ -6,10 +6,10 @@ # Distribution DLLs. # -# NOTE: libcef.dll is included via the //:cef dependency. DLLS = [ "chrome_elf.dll", "d3dcompiler_47.dll", + "libcef.dll", "libEGL.dll", "libGLESv2.dll", "vk_swiftshader.dll", diff --git a/tools/distrib/bazel/BUILD.bazel b/tools/distrib/bazel/BUILD.bazel index 1dc25e899..d78179990 100755 --- a/tools/distrib/bazel/BUILD.bazel +++ b/tools/distrib/bazel/BUILD.bazel @@ -274,29 +274,19 @@ alias( }) ) -# Only available on Linux/Windows. +# Only available on Linux. cc_import( name = "cef_dbg", - interface_library = select({ - "@platforms//os:windows": "Debug/libcef.lib", - "//conditions:default": None, - }), shared_library = select({ "@platforms//os:linux": "Debug/libcef.so", - "@platforms//os:windows": "Debug/libcef.dll", "//conditions:default": None, }), ) cc_import( name = "cef_opt", - interface_library = select({ - "@platforms//os:windows": "Release/libcef.lib", - "//conditions:default": None, - }), shared_library = select({ "@platforms//os:linux": "Release/libcef.so", - "@platforms//os:windows": "Release/libcef.dll", "//conditions:default": None, }), ) @@ -309,6 +299,36 @@ alias( }), ) +# Only available on Windows. +# 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. +alias( + name = "cef_lib_dbg", + actual = select({ + "@platforms//os:windows": "Debug/libcef.lib", + "//conditions:default": None, + }), +) + +alias( + name = "cef_lib_opt", + actual = select({ + "@platforms//os:windows": "Release/libcef.lib", + "//conditions:default": None, + }), +) + +alias( + name = "cef_lib", + actual = select({ + "@cef//:dbg": "@cef//:cef_lib_dbg", + "//conditions:default": "@cef//:cef_lib_opt", + }), +) + # Copy the CEF framework into the app bundle but do not link it. See # https://groups.google.com/g/cef-announce/c/Fith0A3kWtw/m/6ds_mJVMCQAJ # for background. Use `copy_directory` instead of `filegroup` to remove