[llvm] [Bazel] Make LLVM and Clang config headers configurable (PR #126729)
Aaron Siddhartha Mondal via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 15 13:57:30 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.
+#
+# These map to CMake `option` fields on a best-effort basis. The default maps to
+# CMake's `ON` or `OFF` value.
+[
+ (
+ bool_flag(
+ name = option,
+ build_setting_default = default,
+ ),
+ # Only define the opposite of the default value to reduce target count
+ # and prevent accidental default redeclarations.
+ (
+ config_setting(
+ name = "{}_enabled".format(option),
+ flag_values = {":{}".format(option): "true"},
+ ) if not default else config_setting(
+ name = "{}_disabled".format(option),
+ flag_values = {":{}".format(option): "false"},
+ )
+ ),
+ )
+ for option, default in [
+ ("LLVM_ENABLE_BACKTRACES", True),
+ ("LLVM_ENABLE_CRASH_OVERRIDES", True),
+ ("LLVM_ENABLE_CRASH_DUMPS", False),
+
+ # These deviate slightly from CMake in that we use a boolean rather than
+ # ON/OFF/FORCE_ON since in Bazel ON collapses into FORCE_ON anyways.
+ ("LLVM_ENABLE_ZLIB", True),
+ ("LLVM_ENABLE_ZSTD", True),
+ ("LLVM_HAS_LOGF128", False),
+ ]
+]
+
+bool_flag(
+ name = "LLVM_WINDOWS_PREFER_FORWARD_SLASH",
+ build_setting_default = False,
+)
+
+config_setting(
+ name = "LLVM_WINDOWS_PREFER_FORWARD_SLASH_enabled",
+ flag_values = {":LLVM_WINDOWS_PREFER_FORWARD_SLASH": "true"},
+)
----------------
aaronmondal wrote:
The intent is that this is an ambiguous default. Clarified the comment.
https://github.com/llvm/llvm-project/pull/126729
More information about the llvm-commits
mailing list