cef/tools/distrib/bazel/BUILD.bazel

367 lines
10 KiB
Python
Raw Normal View History

# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.
# Allow access from targets in other packages.
package(default_visibility = [
"//visibility:public",
])
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_dynamic_framework_import")
load("//bazel/win:variables.bzl",
WIN_DLLS="DLLS",
WIN_DLLS_X64="DLLS_X64",
WIN_SANDBOX_LIBS="SANDBOX_LIBS",
WIN_COMMON_COPTS="COMMON_COPTS",
WIN_COMMON_COPTS_RELEASE="COMMON_COPTS_RELEASE",
WIN_COMMON_COPTS_DEBUG="COMMON_COPTS_DEBUG",
WIN_COMMON_DEFINES="COMMON_DEFINES",
WIN_COMMON_DEFINES_RELEASE="COMMON_DEFINES_RELEASE",
WIN_COMMON_DEFINES_DEBUG="COMMON_DEFINES_DEBUG")
load("//bazel/linux:variables.bzl",
LINUX_SOS="SOS",
LINUX_COMMON_COPTS="COMMON_COPTS",
LINUX_COMMON_COPTS_RELEASE="COMMON_COPTS_RELEASE",
LINUX_COMMON_COPTS_DEBUG="COMMON_COPTS_DEBUG",
LINUX_COMMON_DEFINES="COMMON_DEFINES",
LINUX_COMMON_DEFINES_RELEASE="COMMON_DEFINES_RELEASE",
LINUX_COMMON_DEFINES_DEBUG="COMMON_DEFINES_DEBUG")
load("//bazel/mac:variables.bzl",
"CEF_FRAMEWORK_NAME",
MAC_COMMON_COPTS="COMMON_COPTS",
MAC_COMMON_COPTS_RELEASE="COMMON_COPTS_RELEASE",
MAC_COMMON_COPTS_DEBUG="COMMON_COPTS_DEBUG",
MAC_COMMON_DEFINES="COMMON_DEFINES",
MAC_COMMON_DEFINES_RELEASE="COMMON_DEFINES_RELEASE",
MAC_COMMON_DEFINES_DEBUG="COMMON_DEFINES_DEBUG")
load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library", "objc_library")
#
# Define supported configurations.
# See https://bazel.build/docs/configurable-attributes
#
# Normal build (ARM64 host):
# % bazel build //tests/cefsimple [-c dbg]
#
# Cross-compile build (ARM64 host):
# % bazel build //tests/cefsimple --cpu=darwin_x86_64 [-c dbg]
#
config_setting(
name = "dbg",
values = {"compilation_mode": "dbg"},
)
config_setting(
name = "fastbuild",
values = {"compilation_mode": "fastbuild"},
)
config_setting(
name = "opt",
values = {"compilation_mode": "opt"},
)
selects.config_setting_group(
name = "windows_32",
match_all = ["@platforms//os:windows", "@platforms//cpu:x86_32"],
)
selects.config_setting_group(
name = "windows_64",
match_all = ["@platforms//os:windows", "@platforms//cpu:x86_64"],
)
selects.config_setting_group(
name = "windows_dbg",
match_all = ["@platforms//os:windows", "@cef//:dbg"],
)
selects.config_setting_group(
name = "windows_fastbuild",
match_all = ["@platforms//os:windows", "@cef//:fastbuild"],
)
selects.config_setting_group(
name = "windows_opt",
match_all = ["@platforms//os:windows", "@cef//:opt"],
)
selects.config_setting_group(
name = "linux_dbg",
match_all = ["@platforms//os:linux", "@cef//:dbg"],
)
selects.config_setting_group(
name = "linux_fastbuild",
match_all = ["@platforms//os:linux", "@cef//:fastbuild"],
)
selects.config_setting_group(
name = "linux_opt",
match_all = ["@platforms//os:linux", "@cef//:opt"],
)
selects.config_setting_group(
name = "macos_dbg",
match_all = ["@platforms//os:macos", "@cef//:dbg"],
)
selects.config_setting_group(
name = "macos_fastbuild",
match_all = ["@platforms//os:macos", "@cef//:fastbuild"],
)
selects.config_setting_group(
name = "macos_opt",
match_all = ["@platforms//os:macos", "@cef//:opt"],
)
#
# Define common build targets.
#
# Public headers for cef_wrapper here.
# Seperated from the actual cef_wrapper since the *.mm file needs access to these as well.
cc_library(
name = "cef_wrapper_headers",
hdrs = glob(
[
"include/**/*.h",
],
exclude = [
"include/base/internal/**/*.*",
"include/internal/**/*.*",
],
),
)
objc_library(
name = "cef_wrapper_apple",
srcs = [
"libcef_dll/wrapper/cef_library_loader_mac.mm",
],
implementation_deps = [":cef_wrapper_headers"],
)
cc_library(
name = "cef_wrapper",
srcs = glob(
[
"libcef_dll/**/*.cc",
"libcef_dll/**/*.h",
"libcef_dll_wrapper/**/*.cc",
"libcef_dll_wrapper/**/*.h",
"include/base/internal/**/*.h",
"include/base/internal/**/*.inc",
"include/internal/**/*.h",
"include/test/*.h",
],
),
copts = select({
"@platforms//os:windows": WIN_COMMON_COPTS,
"@platforms//os:linux": LINUX_COMMON_COPTS,
"@platforms//os:macos": MAC_COMMON_COPTS,
"//conditions:default": None,
}) + select({
"@cef//:windows_opt": WIN_COMMON_COPTS_RELEASE,
"@cef//:windows_dbg": WIN_COMMON_COPTS_DEBUG,
"@cef//:windows_fastbuild": WIN_COMMON_COPTS_RELEASE,
"@cef//:linux_opt": LINUX_COMMON_COPTS_RELEASE,
"@cef//:linux_dbg": LINUX_COMMON_COPTS_DEBUG,
"@cef//:linux_fastbuild": LINUX_COMMON_COPTS_RELEASE,
"@cef//:macos_opt": MAC_COMMON_COPTS_RELEASE,
"@cef//:macos_dbg": MAC_COMMON_COPTS_DEBUG,
"@cef//:macos_fastbuild": MAC_COMMON_COPTS_RELEASE,
"//conditions:default": None,
}),
defines = [
"WRAPPING_CEF_SHARED",
] + select({
"@platforms//os:windows": WIN_COMMON_DEFINES,
"@platforms//os:linux": LINUX_COMMON_DEFINES,
"@platforms//os:macos": MAC_COMMON_DEFINES,
"//conditions:default": None,
}) + select({
"@cef//:windows_opt": WIN_COMMON_DEFINES_RELEASE,
"@cef//:windows_dbg": WIN_COMMON_DEFINES_DEBUG,
"@cef//:windows_fastbuild": WIN_COMMON_DEFINES_RELEASE,
"@cef//:linux_opt": LINUX_COMMON_DEFINES_RELEASE,
"@cef//:linux_dbg": LINUX_COMMON_DEFINES_DEBUG,
"@cef//:linux_fastbuild": LINUX_COMMON_DEFINES_RELEASE,
"@cef//:macos_opt": MAC_COMMON_DEFINES_RELEASE,
"@cef//:macos_dbg": MAC_COMMON_DEFINES_DEBUG,
"@cef//:macos_fastbuild": MAC_COMMON_DEFINES_RELEASE,
"//conditions:default": None,
}),
deps = [":cef_wrapper_headers"] +
select({
"@platforms//os:macos": [":cef_wrapper_apple"],
"@platforms//os:windows": [":cef"],
"//conditions:default": None,
}),
)
# Only available on MacOS/Windows.
cc_library(
name = "cef_sandbox_linkflags",
linkopts = select({
"@platforms//os:macos": ["-lsandbox"],
"@platforms//os:windows": [
"/DEFAULTLIB:{}".format(lib) for lib in WIN_SANDBOX_LIBS
],
"//conditions:default": [],
}),
)
cc_import(
name = "cef_sandbox_debug",
static_library = select({
"@platforms//os:macos": "Debug/cef_sandbox.a",
"@platforms//os:windows": "Debug/cef_sandbox.lib",
"//conditions:default": None,
}),
deps = [":cef_sandbox_linkflags"],
)
cc_import(
name = "cef_sandbox_release",
static_library = select({
"@platforms//os:macos": "Release/cef_sandbox.a",
"@platforms//os:windows": "Release/cef_sandbox.lib",
"//conditions:default": None,
}),
deps = [":cef_sandbox_linkflags"],
)
alias(
name = "cef_sandbox",
actual = select({
"@cef//:dbg": "@cef//:cef_sandbox_debug",
"//conditions:default": "@cef//:cef_sandbox_release",
}),
)
filegroup(
name = "dlls_opt",
srcs = ["Release/{}".format(name) for name in WIN_DLLS] +
select({
"@cef//:windows_64": ["Release/{}".format(name) for name in WIN_DLLS_X64],
"//conditions:default": None,
}),
)
filegroup(
name = "dlls_dbg",
srcs = ["Debug/{}".format(name) for name in WIN_DLLS] +
select({
"@cef//:windows_64": ["Debug/{}".format(name) for name in WIN_DLLS_X64],
"//conditions:default": None,
}),
)
alias(
name = "dlls",
actual = select({
"@cef//:dbg": "@cef//:dlls_dbg",
"//conditions:default": "@cef//:dlls_opt",
})
)
filegroup(
name = "sos_opt",
srcs = ["Release/{}".format(name) for name in LINUX_SOS],
)
filegroup(
name = "sos_dbg",
srcs = ["Debug/{}".format(name) for name in LINUX_SOS],
)
alias(
name = "sos",
actual = select({
"@cef//:dbg": "@cef//:sos_dbg",
"//conditions:default": "@cef//:sos_opt",
})
)
filegroup(
name = "resources_common",
srcs = glob([
"Resources/**",
]),
)
filegroup(
name = "resources_opt",
srcs = [
"Release/snapshot_blob.bin",
"Release/v8_context_snapshot.bin",
"Release/vk_swiftshader_icd.json",
"@cef//:resources_common",
],
)
filegroup(
name = "resources_dbg",
srcs = [
"Debug/snapshot_blob.bin",
"Debug/v8_context_snapshot.bin",
"Debug/vk_swiftshader_icd.json",
"@cef//:resources_common",
],
)
alias(
name = "resources",
actual = select({
"@cef//:opt": "@cef//:resources_opt",
"//conditions:default": "@cef//:resources_dbg",
})
)
# Only available on Linux/Windows.
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,
}),
)
alias(
name = "cef",
actual = select({
"@cef//:dbg": "@cef//:cef_dbg",
"//conditions:default": "@cef//:cef_opt",
}),
)
apple_dynamic_framework_import(
name = "cef_framework",
framework_imports = select({
"@cef//:dbg": glob(["Debug/{}.framework/**".format(CEF_FRAMEWORK_NAME)]),
"//conditions:default": glob(["Release/{}.framework/**".format(CEF_FRAMEWORK_NAME)]),
}),
)