[llvm] [Bazel] Make LLVM config headers configurable (PR #126729)

Aaron Siddhartha Mondal via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 10:29:21 PST 2025


================
@@ -2,118 +2,331 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-"""Defines variables that use selects to configure LLVM based on platform."""
+"""Substitutions for use in templates related to the LLVM configuration."""
 
+load("@bazel_skylib//lib:selects.bzl", "selects")
 load(
     "//:vars.bzl",
     "LLVM_VERSION_MAJOR",
     "LLVM_VERSION_MINOR",
     "LLVM_VERSION_PATCH",
     "PACKAGE_VERSION",
 )
+load("//llvm:targets.bzl", "llvm_targets")
+load(
+    ":cmakehelpers.bzl",
+    "cmakedefine",
+    "cmakedefine01",
+    "cmakedefine01_off",
+    "cmakedefine01_on",
+    "cmakedefine_set",
+    "cmakedefine_string",
+    "cmakedefine_unset",
+)
 
-def native_arch_defines(arch, triple):
-    return [
-        r'LLVM_NATIVE_ARCH=\"{}\"'.format(arch),
-        "LLVM_NATIVE_ASMPARSER=LLVMInitialize{}AsmParser".format(arch),
-        "LLVM_NATIVE_ASMPRINTER=LLVMInitialize{}AsmPrinter".format(arch),
-        "LLVM_NATIVE_DISASSEMBLER=LLVMInitialize{}Disassembler".format(arch),
-        "LLVM_NATIVE_TARGET=LLVMInitialize{}Target".format(arch),
-        "LLVM_NATIVE_TARGETINFO=LLVMInitialize{}TargetInfo".format(arch),
-        "LLVM_NATIVE_TARGETMC=LLVMInitialize{}TargetMC".format(arch),
-        "LLVM_NATIVE_TARGETMCA=LLVMInitialize{}TargetMCA".format(arch),
-        r'LLVM_HOST_TRIPLE=\"{}\"'.format(triple),
-        r'LLVM_DEFAULT_TARGET_TRIPLE=\"{}\"'.format(triple),
-    ]
-
-posix_defines = [
-    "LLVM_ON_UNIX=1",
-    "HAVE_BACKTRACE=1",
-    "BACKTRACE_HEADER=<execinfo.h>",
-    r'LTDL_SHLIB_EXT=\".so\"',
-    r'LLVM_PLUGIN_EXT=\".so\"',
-    "LLVM_ENABLE_THREADS=1",
-    "HAVE_DEREGISTER_FRAME=1",
-    "HAVE_LIBPTHREAD=1",
-    "HAVE_PTHREAD_GETNAME_NP=1",
-    "HAVE_PTHREAD_H=1",
-    "HAVE_PTHREAD_SETNAME_NP=1",
-    "HAVE_REGISTER_FRAME=1",
-    "HAVE_SETENV_R=1",
-    "HAVE_STRERROR_R=1",
-    "HAVE_SYSEXITS_H=1",
-    "HAVE_UNISTD_H=1",
-]
-
-linux_defines = posix_defines + [
-    "_GNU_SOURCE",
-    "HAVE_MALLINFO=1",
-    "HAVE_SBRK=1",
-    "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
-]
-
-macos_defines = posix_defines + [
-    "HAVE_MACH_MACH_H=1",
-    "HAVE_MALLOC_MALLOC_H=1",
-    "HAVE_MALLOC_ZONE_STATISTICS=1",
-    "HAVE_PROC_PID_RUSAGE=1",
-    "HAVE_UNW_ADD_DYNAMIC_FDE=1",
-]
-
-win32_defines = [
-    # Windows system library specific defines.
-    "_CRT_SECURE_NO_DEPRECATE",
-    "_CRT_SECURE_NO_WARNINGS",
-    "_CRT_NONSTDC_NO_DEPRECATE",
-    "_CRT_NONSTDC_NO_WARNINGS",
-    "_SCL_SECURE_NO_DEPRECATE",
-    "_SCL_SECURE_NO_WARNINGS",
-    "UNICODE",
-    "_UNICODE",
+CONFIG_H_SUBSTITUTIONS = (
+    {"${BUG_REPORT_URL}": "https://github.com/llvm/llvm-project/issues/"} |
+    cmakedefine01(
+        "ENABLE_BACKTRACES",
+        disable = "//llvm/config:LLVM_ENABLE_BACKTRACES_disabled",
+    ) |
+    cmakedefine01(
+        "ENABLE_CRASH_OVERRIDES",
+        disable = "//llvm/config:LLVM_ENABLE_CRASH_OVERRIDES_disabled",
+    ) |
+    cmakedefine01(
+        "LLVM_ENABLE_CRASH_DUMPS",
+        enable = "//llvm/config:LLVM_ENABLE_CRASH_DUMPS_enabled",
+    ) |
+    cmakedefine01(
+        "ENABLE_DEBUGLOC_COVERAGE_TRACKING",
+        enable = "//llvm/config:LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING_coverage",
+    ) |
+    cmakedefine01(
+        "LLVM_WINDOWS_PREFER_FORWARD_SLASH",
+        enable = (
+            "@bazel_tools//tools/cpp:mingw",
+            "//llvm/config:LLVM_WINDOWS_PREFER_FORWARD_SLASH_enabled",
+        ),
+        disable = (
+            "//llvm/config:LLVM_WINDOWS_PREFER_FORWARD_SLASH_disabled",
+            "//conditions:default",
+        ),
+    ) |
+    cmakedefine("HAVE_BACKTRACE", enable = "//llvm/config:posix") |
+    {"${BACKTRACE_HEADER}": "execinfo.h"} |
+    {
+        "#cmakedefine HAVE_CRASHREPORTERCLIENT_H": "/* #undef HAVE_CRASHREPORTERCLIENT_H */",
+    } |
+    cmakedefine01_off("HAVE_CRASHREPORTER_INFO") |
+    cmakedefine01_off("HAVE_DECL_ARC4RANDOM") |
+    cmakedefine01_on("HAVE_DECL_FE_ALL_EXCEPT") |
+    cmakedefine01_on("HAVE_DECL_FE_INEXACT") |
+    cmakedefine01_off("HAVE_DECL_STRERROR_S") |
+    cmakedefine_set("HAVE_DLOPEN") |
+    cmakedefine("HAVE_REGISTER_FRAME", enable = "//llvm/config:posix") |
+    cmakedefine("HAVE_DEREGISTER_FRAME", enable = "//llvm/config:posix") |
+    cmakedefine("HAVE_UNW_ADD_DYNAMIC_FDE", enable = "@platforms//os:macos") |
+    cmakedefine_unset("HAVE_FFI_CALL") |
+    cmakedefine_unset("HAVE_FFI_FFI_H") |
+    cmakedefine_unset("HAVE_FFI_H") |
+    cmakedefine_set("HAVE_FUTIMENS") |
+    cmakedefine_set("HAVE_FUTIMES") |
+    cmakedefine_set("HAVE_GETPAGESIZE") |
+    cmakedefine_set("HAVE_GETRUSAGE") |
+    {"#cmakedefine HAVE_ISATTY 1": "#define HAVE_ISATTY 1"} |
+    cmakedefine_unset("HAVE_LIBEDIT") |
+    # TODO: Wire this up Exegesis and remove custom logic.
+    cmakedefine_unset("HAVE_LIBPFM") |
----------------
aaronmondal wrote:

Note: Libpfm is already configurable but doesn't match the CMake behavior. By disabling it here we keep the existing behavior for now and can defer changes to the libpfm configuration.

https://github.com/llvm/llvm-project/pull/126729


More information about the llvm-commits mailing list