[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


================
@@ -0,0 +1,158 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Configurable build attributes for LLVM."""
+
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
+
+# To view the configurable build attributes in this file:
+#
+#   bazel query 'kind(".*_flag", @llvm-project//llvm/config:all)'
+
+selects.config_setting_group(
+    name = "aarch64-unknown-linux-gnu",
+    match_all = [
+        "@platforms//cpu:aarch64",
+        "@platforms//os:linux",
+    ],
+)
+
+selects.config_setting_group(
+    name = "arm64-apple-darwin",
+    match_all = [
+        "@platforms//cpu:arm64",
+        "@platforms//os:macos",
+    ],
+)
+
+selects.config_setting_group(
+    name = "powerpc64le-unknown-linux-gnu",
+    match_all = [
+        "@platforms//cpu:ppc64le",
+        "@platforms//os:linux",
+    ],
+)
+
+selects.config_setting_group(
+    name = "systemz-unknown-linux_gnu",
+    match_all = [
+        "@platforms//cpu:s390x",
+        "@platforms//os:linux",
+    ],
+)
+
+selects.config_setting_group(
+    name = "x86_64-pc-win32",
+    match_all = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:windows",
+    ],
+)
+
+selects.config_setting_group(
+    name = "x86_64-unknown-darwin",
+    match_all = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:macos",
+    ],
+)
+
+selects.config_setting_group(
+    name = "x86_64-unknown-linux-gnu",
+    match_all = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:linux",
+    ],
+)
+
+selects.config_setting_group(
+    name = "posix",
+    match_any = [
+        "@platforms//os:linux",
+        "@platforms//os:macos",
+        "@platforms//os:freebsd",
+    ],
+)
+
+# Directly configurable boolean build attributes.
----------------
aaronmondal wrote:

I'm leaning towards moving these flags to a global `//config` directory. This way the command lines get shorter (`@llvm-project//config:LLVM_SOMEOPTION` instead of the current `@llvm-project//llvm/config:LLVM_SOMEOPTION`).

If we do this for the other subprojects this would let us query all options that the Bazel build supports via

```
bazel query 'kind(".*_flag", @llvm-project//config:all)
```

The tradeoff here is that it somewhat blurs the lines between different projects if we add more options. Since the configurable attributes are generally prefixed like `LLVM_*`, `CLANG_*`, etc. I think this would be fine regardless.

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


More information about the llvm-commits mailing list