Skip to content

[libc][bazel] Add a flag to configure LIBC_NAMESPACE #68093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load(
)
load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH")

package(
Expand All @@ -35,8 +35,6 @@ MEMORY_COPTS = [
# "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
]

llvm_libc_namespace = "__llvm_libc_{}_{}_{}_git".format(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERSION_PATCH)

# A flag to pick which `mpfr` to use for math tests.
# Usage: `--@llvm-project//libc:mpfr=<disable|external|system>`.
# Flag documentation: https://bazel.build/extending/config
Expand Down Expand Up @@ -65,14 +63,34 @@ config_setting(
flag_values = {":mpfr": "system"},
)

default_libc_namespace = "__llvm_libc_{}_{}_{}_git".format(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, LLVM_VERSION_PATCH)

release_libc_namespace = "__llvm_libc"

# When set, The ':libc_root' target below will define 'LIBC_NAMESPACE' to
# 'release_libc_namespace' instead of 'default_libc_namespace'.
# Usage: `--@llvm-project//libc:release`.
bool_flag(
name = "release",
build_setting_default = False,
)

config_setting(
name = "use_release_namespace",
flag_values = {":release": "true"},
)

# This empty root library helps us add an include path to this directory
# using the 'includes' attribute. The strings listed in the includes attribute
# are relative paths wrt this library but are inherited by the dependents
# appropriately. Hence, using this as a root dependency avoids adding include
# paths of the kind "../../" to other libc targets.
cc_library(
name = "libc_root",
defines = ["LIBC_NAMESPACE=" + llvm_libc_namespace],
defines = select({
":use_release_namespace": ["LIBC_NAMESPACE=" + release_libc_namespace],
"//conditions:default": ["LIBC_NAMESPACE=" + default_libc_namespace],
}),
includes = ["."],
)

Expand Down