Skip to content

Commit dd65427

Browse files
authored
[libc][bazel] Add a flag to configure LIBC_NAMESPACE (#68093)
1 parent 4812eec commit dd65427

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load(
1111
)
1212
load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64")
1313
load("@bazel_skylib//lib:selects.bzl", "selects")
14-
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
14+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
1515
load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH")
1616

1717
package(
@@ -35,8 +35,6 @@ MEMORY_COPTS = [
3535
# "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
3636
]
3737

38-
llvm_libc_namespace = "__llvm_libc_{}_{}_{}_git".format(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERSION_PATCH)
39-
4038
# A flag to pick which `mpfr` to use for math tests.
4139
# Usage: `--@llvm-project//libc:mpfr=<disable|external|system>`.
4240
# Flag documentation: https://bazel.build/extending/config
@@ -65,14 +63,34 @@ config_setting(
6563
flag_values = {":mpfr": "system"},
6664
)
6765

66+
default_libc_namespace = "__llvm_libc_{}_{}_{}_git".format(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERSION_PATCH)
67+
68+
release_libc_namespace = "__llvm_libc"
69+
70+
# When set, The ':libc_root' target below will define 'LIBC_NAMESPACE' to
71+
# 'release_libc_namespace' instead of 'default_libc_namespace'.
72+
# Usage: `--@llvm-project//libc:release`.
73+
bool_flag(
74+
name = "release",
75+
build_setting_default = False,
76+
)
77+
78+
config_setting(
79+
name = "use_release_namespace",
80+
flag_values = {":release": "true"},
81+
)
82+
6883
# This empty root library helps us add an include path to this directory
6984
# using the 'includes' attribute. The strings listed in the includes attribute
7085
# are relative paths wrt this library but are inherited by the dependents
7186
# appropriately. Hence, using this as a root dependency avoids adding include
7287
# paths of the kind "../../" to other libc targets.
7388
cc_library(
7489
name = "libc_root",
75-
defines = ["LIBC_NAMESPACE=" + llvm_libc_namespace],
90+
defines = select({
91+
":use_release_namespace": ["LIBC_NAMESPACE=" + release_libc_namespace],
92+
"//conditions:default": ["LIBC_NAMESPACE=" + default_libc_namespace],
93+
}),
7694
includes = ["."],
7795
)
7896

0 commit comments

Comments
 (0)