bazel: mac: Copy but don't link the CEF framework (see #3757)

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 `**kwargs` to pass all other arguments to the actual
`macos_application` target declaration.
This commit is contained in:
Marshall Greenblatt 2024-08-09 13:16:28 -04:00
parent a5544b6fb1
commit c1d356f5ab
3 changed files with 24 additions and 13 deletions

View File

@ -5,10 +5,13 @@
load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application") load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application")
load("//bazel:variables.bzl", "VERSION_PLIST") load("//bazel:variables.bzl", "VERSION_PLIST")
load("//bazel/mac:variables.bzl", "MACOS_DEPLOYMENT_TARGET", "MACOS_BUNDLE_ID_BASE", load("//bazel/mac:variables.bzl",
"MACOS_DEPLOYMENT_TARGET",
"MACOS_BUNDLE_ID_BASE",
"CEF_FRAMEWORK_NAME",
"COMMON_LINKOPTS") "COMMON_LINKOPTS")
def _declare_helper_app(name, info_plist, deps, helper_base_name, helper_suffix): def _declare_helper_app(name, info_plist, deps, helper_base_name, helper_suffix, **kwargs):
""" """
Creates a Helper .app target. Creates a Helper .app target.
""" """
@ -43,6 +46,7 @@ def _declare_helper_app(name, info_plist, deps, helper_base_name, helper_suffix)
deps = [ deps = [
"@cef//:cef_sandbox", "@cef//:cef_sandbox",
] + deps, ] + deps,
**kwargs,
) )
HELPERS = { HELPERS = {
@ -53,7 +57,7 @@ HELPERS = {
"HelperRenderer": "Renderer", "HelperRenderer": "Renderer",
} }
def declare_all_helper_apps(name, info_plist, deps): def declare_all_helper_apps(name, info_plist, deps, **kwargs):
""" """
Creates all Helper .app targets. Creates all Helper .app targets.
""" """
@ -63,9 +67,10 @@ def declare_all_helper_apps(name, info_plist, deps):
deps = deps, deps = deps,
helper_base_name = h, helper_base_name = h,
helper_suffix = v, helper_suffix = v,
**kwargs,
) for h, v in HELPERS.items()] ) for h, v in HELPERS.items()]
def declare_main_app(name, info_plist, deps, resources, linkopts=[]): def declare_main_app(name, info_plist, deps, resources, linkopts=[], **kwargs):
""" """
Creates the main .app target. Creates the main .app target.
""" """
@ -92,6 +97,7 @@ def declare_main_app(name, info_plist, deps, resources, linkopts=[]):
":HelperGPU": "Frameworks", ":HelperGPU": "Frameworks",
":HelperPlugin": "Frameworks", ":HelperPlugin": "Frameworks",
":HelperRenderer": "Frameworks", ":HelperRenderer": "Frameworks",
"@cef//:cef_framework": "Frameworks/{}.framework".format(CEF_FRAMEWORK_NAME),
}, },
bundle_name = name, bundle_name = name,
bundle_id = "{}.{}".format(MACOS_BUNDLE_ID_BASE, name.lower()), bundle_id = "{}.{}".format(MACOS_BUNDLE_ID_BASE, name.lower()),
@ -102,7 +108,6 @@ def declare_main_app(name, info_plist, deps, resources, linkopts=[]):
target_compatible_with = [ target_compatible_with = [
"@platforms//os:macos", "@platforms//os:macos",
], ],
deps = [ deps = deps,
"@cef//:cef_framework", **kwargs,
] + deps,
) )

View File

@ -7,8 +7,8 @@ package(default_visibility = [
"//visibility:public", "//visibility:public",
]) ])
load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory")
load("@bazel_skylib//lib:selects.bzl", "selects") load("@bazel_skylib//lib:selects.bzl", "selects")
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_dynamic_framework_import")
load("//bazel:library_helpers.bzl", "declare_cc_library", "declare_objc_library") load("//bazel:library_helpers.bzl", "declare_cc_library", "declare_objc_library")
load("//bazel/win:variables.bzl", load("//bazel/win:variables.bzl",
WIN_DLLS="DLLS", WIN_DLLS="DLLS",
@ -309,10 +309,15 @@ alias(
}), }),
) )
apple_dynamic_framework_import( # 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
# the Debug/Release path prefix.
copy_directory(
name = "cef_framework", name = "cef_framework",
framework_imports = select({ src = select({
"@cef//:dbg": glob(["Debug/{}.framework/**".format(CEF_FRAMEWORK_NAME)]), "@cef//:dbg": "Debug/{}.framework".format(CEF_FRAMEWORK_NAME),
"//conditions:default": glob(["Release/{}.framework/**".format(CEF_FRAMEWORK_NAME)]), "//conditions:default": "Release/{}.framework".format(CEF_FRAMEWORK_NAME),
}), }),
out = "{}.framework".format(CEF_FRAMEWORK_NAME),
) )

View File

@ -15,3 +15,4 @@ bazel_dep(name = "rules_apple", version = "3.6.0", repo_name = "build_bazel_rule
bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "rules_cc", version = "0.0.9")
# Add other dependencies here. # Add other dependencies here.
bazel_dep(name = "aspect_bazel_lib", version = "2.7.9")