|
| 1 | +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 2 | +# See https://llvm.org/LICENSE.txt for license information. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + |
| 5 | +"""Configurable build attributes for the overlay. |
| 6 | +
|
| 7 | +To view the configurable build attributes in this file: |
| 8 | +
|
| 9 | + bazel query 'kind(".*_flag", @llvm-project//config:all)' |
| 10 | +""" |
| 11 | + |
| 12 | +load("@bazel_skylib//lib:selects.bzl", "selects") |
| 13 | +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") |
| 14 | + |
| 15 | +# Common config settings mapping to platform triples. |
| 16 | +# |
| 17 | +# See also: //platform:BUILD.bazel. |
| 18 | +# |
| 19 | +# TODO(aaronmondal): Add triples for more useful configurations as per |
| 20 | +# `llvm/include/llvm/TargetParser/Triple.h`. |
| 21 | + |
| 22 | +selects.config_setting_group( |
| 23 | + name = "aarch64-unknown-linux-gnu", |
| 24 | + match_all = [ |
| 25 | + "@platforms//cpu:aarch64", |
| 26 | + "@platforms//os:linux", |
| 27 | + ], |
| 28 | +) |
| 29 | + |
| 30 | +selects.config_setting_group( |
| 31 | + name = "arm64-apple-darwin", |
| 32 | + match_all = [ |
| 33 | + "@platforms//cpu:arm64", |
| 34 | + "@platforms//os:macos", |
| 35 | + ], |
| 36 | +) |
| 37 | + |
| 38 | +selects.config_setting_group( |
| 39 | + name = "powerpc64le-unknown-linux-gnu", |
| 40 | + match_all = [ |
| 41 | + "@platforms//cpu:ppc64le", |
| 42 | + "@platforms//os:linux", |
| 43 | + ], |
| 44 | +) |
| 45 | + |
| 46 | +selects.config_setting_group( |
| 47 | + name = "systemz-unknown-linux_gnu", |
| 48 | + match_all = [ |
| 49 | + "@platforms//cpu:s390x", |
| 50 | + "@platforms//os:linux", |
| 51 | + ], |
| 52 | +) |
| 53 | + |
| 54 | +selects.config_setting_group( |
| 55 | + name = "x86_64-pc-win32", |
| 56 | + match_all = [ |
| 57 | + "@platforms//cpu:x86_64", |
| 58 | + "@platforms//os:windows", |
| 59 | + ], |
| 60 | +) |
| 61 | + |
| 62 | +selects.config_setting_group( |
| 63 | + name = "x86_64-unknown-darwin", |
| 64 | + match_all = [ |
| 65 | + "@platforms//cpu:x86_64", |
| 66 | + "@platforms//os:macos", |
| 67 | + ], |
| 68 | +) |
| 69 | + |
| 70 | +selects.config_setting_group( |
| 71 | + name = "x86_64-unknown-linux-gnu", |
| 72 | + match_all = [ |
| 73 | + "@platforms//cpu:x86_64", |
| 74 | + "@platforms//os:linux", |
| 75 | + ], |
| 76 | +) |
| 77 | + |
| 78 | +# Useful helpers. |
| 79 | + |
| 80 | +selects.config_setting_group( |
| 81 | + name = "posix", |
| 82 | + match_any = [ |
| 83 | + "@platforms//os:linux", |
| 84 | + "@platforms//os:macos", |
| 85 | + "@platforms//os:freebsd", |
| 86 | + ], |
| 87 | +) |
| 88 | + |
| 89 | +# Configurable build attributes for llvm. |
| 90 | + |
| 91 | +# These map to CMake `option` fields on a best-effort basis. The default maps to |
| 92 | +# CMake's `ON` or `OFF` value. |
| 93 | +[ |
| 94 | + ( |
| 95 | + bool_flag( |
| 96 | + name = option, |
| 97 | + build_setting_default = default, |
| 98 | + ), |
| 99 | + # Only define the opposite of the default value to reduce target count |
| 100 | + # and prevent accidental default redeclarations. |
| 101 | + # |
| 102 | + # This also acts as a failsafe to prevent drift if a default is flipped |
| 103 | + # as a changed default triggers straightfoward errors in all places |
| 104 | + # where no longer existing config_settings need to be adjusted. |
| 105 | + ( |
| 106 | + config_setting( |
| 107 | + name = "{}_enabled".format(option), |
| 108 | + flag_values = {":{}".format(option): "true"}, |
| 109 | + ) if not default else config_setting( |
| 110 | + name = "{}_disabled".format(option), |
| 111 | + flag_values = {":{}".format(option): "false"}, |
| 112 | + ) |
| 113 | + ), |
| 114 | + ) |
| 115 | + for option, default in [ |
| 116 | + ("LLVM_ENABLE_BACKTRACES", True), |
| 117 | + ("LLVM_ENABLE_CRASH_OVERRIDES", True), |
| 118 | + ("LLVM_ENABLE_CRASH_DUMPS", False), |
| 119 | + |
| 120 | + # These deviate slightly from CMake in that we use a boolean rather than |
| 121 | + # ON/OFF/FORCE_ON since in Bazel ON collapses into FORCE_ON anyways. |
| 122 | + ("LLVM_ENABLE_ZLIB", True), |
| 123 | + ("LLVM_ENABLE_ZSTD", True), |
| 124 | + ("LLVM_HAS_LOGF128", False), |
| 125 | + ] |
| 126 | +] |
| 127 | + |
| 128 | +# This doesn't have a common default as most builds expect this to be disabled |
| 129 | +# by default but MinGW builds expect it enabled by default. |
| 130 | +bool_flag( |
| 131 | + name = "LLVM_WINDOWS_PREFER_FORWARD_SLASH", |
| 132 | + build_setting_default = False, |
| 133 | +) |
| 134 | + |
| 135 | +config_setting( |
| 136 | + name = "LLVM_WINDOWS_PREFER_FORWARD_SLASH_enabled", |
| 137 | + flag_values = {":LLVM_WINDOWS_PREFER_FORWARD_SLASH": "true"}, |
| 138 | +) |
| 139 | + |
| 140 | +config_setting( |
| 141 | + name = "LLVM_WINDOWS_PREFER_FORWARD_SLASH_disabled", |
| 142 | + flag_values = {":LLVM_WINDOWS_PREFER_FORWARD_SLASH": "false"}, |
| 143 | +) |
| 144 | + |
| 145 | +string_flag( |
| 146 | + name = "LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING", |
| 147 | + build_setting_default = "DISABLED", |
| 148 | + values = [ |
| 149 | + "COVERAGE", |
| 150 | + "DISABLED", |
| 151 | + ], |
| 152 | +) |
| 153 | + |
| 154 | +config_setting( |
| 155 | + name = "LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING_coverage", |
| 156 | + flag_values = {":LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING": "COVERAGE"}, |
| 157 | +) |
| 158 | + |
| 159 | +bool_flag( |
| 160 | + name = "LLVM_ENABLE_PLUGINS", |
| 161 | + # TODO(aaronmondal): This should be enabled by default, but that currently |
| 162 | + # breaks @llvm-project//llvm/unittests:analysis_tests. |
| 163 | + build_setting_default = False, |
| 164 | +) |
| 165 | + |
| 166 | +config_setting( |
| 167 | + name = "LLVM_ENABLE_PLUGINS_enabled", |
| 168 | + flag_values = {":LLVM_ENABLE_PLUGINS": "true"}, |
| 169 | +) |
| 170 | + |
| 171 | +config_setting( |
| 172 | + name = "LLVM_ENABLE_PLUGINS_disabled", |
| 173 | + flag_values = {":LLVM_ENABLE_PLUGINS": "false"}, |
| 174 | +) |
0 commit comments