[libc] customizable namespace 1/4 (#65321)

This implements the first step of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079

Make required Bazel and CMake preparatory changes which define the var
for the customizable namespace and use it (pass it as a compile option
-DLIBC_NAMESPACE=<...>).

Differential Revision: https://reviews.llvm.org/D159112
This commit is contained in:
Guillaume Chatelet 2023-09-06 08:27:56 +00:00 committed by GitHub
parent c0703eaec1
commit 56426c6cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -44,10 +44,23 @@ if(("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND NOT LLVM_RUNTIMES_BUILD) OR
endif()
option(LIBC_CMAKE_VERBOSE_LOGGING
"Log details warnings and notifications during CMake configuration." OFF)
"Log details warnings and notifications during CMake configuration." OFF)
# Path libc/scripts directory.
set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
# Defining a global namespace to enclose all libc functions.
set(LIBC_NAMESPACE "__llvm_libc_${LLVM_VERSION_MAJOR}_${LLVM_VERSION_MINOR}_${LLVM_VERSION_PATCH}_${LLVM_VERSION_SUFFIX}"
CACHE STRING "The namespace to use to enclose internal implementations. Must start with '__llvm_libc'."
)
if(NOT LIBC_NAMESPACE MATCHES "^__llvm_libc")
message(FATAL_ERROR "Invalid LIBC_NAMESPACE. Must start with '__llvm_libc' was '${LIBC_NAMESPACE}'")
endif()
message(STATUS "Setting LIBC_NAMESPACE namespace to '${LIBC_NAMESPACE}'")
add_compile_definitions(LIBC_NAMESPACE=${LIBC_NAMESPACE})
# Flags to pass down to the compiler while building the libc functions.
set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
@ -181,7 +194,8 @@ if(LLVM_LIBC_ENABLE_LINTING)
OUTPUT_VARIABLE CLANG_TIDY_OUTPUT)
string(REGEX MATCH "[0-9]+" CLANG_TIDY_VERSION "${CLANG_TIDY_OUTPUT}")
string(REGEX MATCH "[0-9]+" CLANG_MAJOR_VERSION
"${CMAKE_CXX_COMPILER_VERSION}")
"${CMAKE_CXX_COMPILER_VERSION}")
if(NOT CLANG_TIDY_VERSION EQUAL CLANG_MAJOR_VERSION)
set(LLVM_LIBC_ENABLE_LINTING OFF)
message(WARNING "

View File

@ -12,6 +12,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("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH")
package(
default_visibility = ["//visibility:public"],
@ -34,6 +35,8 @@ 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
@ -69,6 +72,7 @@ config_setting(
# paths of the kind "../../" to other libc targets.
cc_library(
name = "libc_root",
defines = ["LIBC_NAMESPACE=" + llvm_libc_namespace],
includes = ["."],
)