-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: Limit define scope to specific cc targets (see #3757)
- Add `declare_[cc|objc]_library` macros to configure common `copts` and `local_defines` (where supported) on `[cc|objc]_library` targets. This limits the scope of defines to the specific target without inheritance by dependent targets. - `objc_library` does not currently support `local_defines` so we use `copts` instead of MacOS. - Use `**kwargs` to pass all other arguments to the actual cc target declaration.
- Loading branch information
1 parent
2038753
commit bdde55a
Showing
9 changed files
with
149 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# 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. | ||
|
||
load("//bazel/win:variables.bzl", | ||
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_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", | ||
MAC_COMMON_COPTS="COMMON_COPTS", | ||
MAC_COMMON_COPTS_RELEASE="COMMON_COPTS_RELEASE", | ||
MAC_COMMON_COPTS_DEBUG="COMMON_COPTS_DEBUG") | ||
load("@rules_cc//cc:defs.bzl", "cc_library", "objc_library") | ||
|
||
def declare_cc_library(copts=[], local_defines=[], **kwargs): | ||
""" | ||
cc_library wrapper that applies common copts and local_defines. | ||
""" | ||
# NOTE: objc_library does not support local_defines on MacOS, so on | ||
# that platform we put the defines in copts instead. | ||
cc_library( | ||
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, | ||
}) + copts, | ||
local_defines = select({ | ||
"@platforms//os:windows": WIN_COMMON_DEFINES, | ||
"@platforms//os:linux": LINUX_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, | ||
"//conditions:default": None, | ||
}) + local_defines, | ||
**kwargs | ||
) | ||
|
||
def declare_objc_library(copts=[], **kwargs): | ||
""" | ||
objc_library wrapper that applies common copts. | ||
""" | ||
# NOTE: objc_library does not support local_defines on MacOS, so on | ||
# that platform we put the defines in copts instead. | ||
objc_library( | ||
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, | ||
}) + copts, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.