Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 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 | ############################################################################### |
| 6 | # Common flags that apply to all configurations. |
| 7 | # Use sparingly for things common to all compilers and platforms. |
| 8 | ############################################################################### |
Keith Smiley | f1fe451 | 2024-08-13 01:06:05 | [diff] [blame] | 9 | |
| 10 | # Flip off to disable MODULE.bazel until we're ready. |
| 11 | # https://github.com/llvm/llvm-project/issues/55924 |
Nick Desaulniers | 5877e5b | 2024-12-10 21:07:52 | [diff] [blame] | 12 | common --enable_bzlmod=false --enable_workspace |
Keith Smiley | f1fe451 | 2024-08-13 01:06:05 | [diff] [blame] | 13 | |
Keith Smiley | bedbaff | 2024-12-10 22:09:08 | [diff] [blame] | 14 | # TODO: Remove lit test reliance on this |
| 15 | common --legacy_external_runfiles |
| 16 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 17 | # Prevent invalid caching if input files are modified during a build. |
| 18 | build --experimental_guard_against_concurrent_changes |
| 19 | |
Keith Smiley | 4b077ed | 2024-04-04 22:10:52 | [diff] [blame] | 20 | # Automatically enable --config=(linux|macos|windows) based on the host |
| 21 | build --enable_platform_specific_config |
| 22 | |
Arthur Eubanks | 2698be0 | 2022-09-26 01:21:35 | [diff] [blame] | 23 | # In opt mode, bazel by default builds both PIC and non-PIC object files for |
| 24 | # tests vs binaries. We don't need this feature and it slows down opt builds |
| 25 | # considerably. |
Keith Smiley | 4b077ed | 2024-04-04 22:10:52 | [diff] [blame] | 26 | # TODO: Remove platform specifics we're on bazel 7.x https://github.com/bazelbuild/bazel/issues/12439 |
| 27 | # Apple platforms always enable pic so this flag is unnecessary anyways |
| 28 | build:linux --force_pic |
| 29 | build:windows --force_pic |
Arthur Eubanks | 2698be0 | 2022-09-26 01:21:35 | [diff] [blame] | 30 | |
| 31 | # Shared objects take up more space. With fast linkers and binaries that aren't |
| 32 | # super large, the benefits of shared objects are minimal. |
| 33 | build --dynamic_mode=off |
| 34 | |
Arthur Eubanks | 7a8b930 | 2022-09-26 01:49:49 | [diff] [blame] | 35 | # Rely on compiler flags to compile with debug info/strip rather than stripping |
| 36 | # based on compilation_mode. |
| 37 | build --strip=never |
| 38 | |
Guillaume Chatelet | 8de802e | 2023-02-09 21:36:59 | [diff] [blame] | 39 | # Add layering check to all projects. |
| 40 | build --features=layering_check |
| 41 | |
Benoit Jacob | 1c532b5 | 2023-06-09 02:33:51 | [diff] [blame] | 42 | # Opt out of legacy lax behavior implicitly exporting files that are rule inputs |
| 43 | # with default visibility. |
| 44 | # See: https://bazel.build/reference/be/functions#exports_files |
| 45 | build --incompatible_no_implicit_file_export |
| 46 | |
Keith Smiley | 72c729f | 2024-03-22 16:51:20 | [diff] [blame] | 47 | # Enable so downstream users can flip this flag globally, this should |
| 48 | # eventually become the default |
| 49 | common --incompatible_disallow_empty_glob |
| 50 | |
Keith Smiley | 4b077ed | 2024-04-04 22:10:52 | [diff] [blame] | 51 | # TODO: Remove once we move to bazel 7.x |
| 52 | build --experimental_cc_shared_library |
| 53 | |
Keith Smiley | 28a2f57 | 2024-10-21 21:01:29 | [diff] [blame] | 54 | # Disabling runfiles links drastically increases performance in slow disk IO |
| 55 | # situations Do not build runfile trees by default. If an execution strategy |
| 56 | # relies on runfile symlink tree, the tree is created on-demand. See: |
| 57 | # https://github.com/bazelbuild/bazel/issues/6627 and |
| 58 | # https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df |
| 59 | build --build_runfile_links=false |
| 60 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 61 | ############################################################################### |
| 62 | # Options to select different strategies for linking potential dependent |
| 63 | # libraries. The default leaves it disabled. |
| 64 | ############################################################################### |
| 65 | |
| 66 | build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external |
| 67 | build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system |
| 68 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 69 | ############################################################################### |
| 70 | # Options for "generic_clang" builds: these options should generally apply to |
| 71 | # builds using a Clang-based compiler, and default to the `clang` executable on |
| 72 | # the `PATH`. While these are provided for convenience and may serve as a |
| 73 | # reference, it would be preferable for users to configure an explicit C++ |
| 74 | # toolchain instead of relying on `.bazelrc` files. |
| 75 | ############################################################################### |
| 76 | |
| 77 | # Set the default compiler to the `clang` binary on the `PATH`. |
| 78 | build:generic_clang --repo_env=CC=clang |
| 79 | |
Benjamin Kramer | 2d2ad02 | 2022-08-06 19:47:44 | [diff] [blame] | 80 | # C++17 standard version is required. |
| 81 | build:generic_clang --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 82 | |
Mehdi Amini | 6174568 | 2022-11-09 00:42:41 | [diff] [blame] | 83 | # Use `-Wall` for Clang. |
| 84 | build:generic_clang --copt=-Wall --host_copt=-Wall |
Geoffrey Martin-Noble | ef72739 | 2022-02-01 01:50:59 | [diff] [blame] | 85 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 86 | # The Clang available on MacOS has a warning that isn't clean on MLIR code. The |
| 87 | # warning doesn't show up with more recent Clangs, so just disable for now. |
| 88 | build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis |
| 89 | |
Geoffrey Martin-Noble | ef72739 | 2022-02-01 01:50:59 | [diff] [blame] | 90 | # Build errors are not a helpful way to enforce deprecation in-repo and it is |
| 91 | # not the point of the Bazel build to catch usage of deprecated APIs. |
| 92 | build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 93 | |
Arthur Eubanks | 76b1e83 | 2022-08-11 21:15:47 | [diff] [blame] | 94 | # lld links faster than other linkers. Assume that anybody using clang also has |
| 95 | # lld available. |
| 96 | build:generic_clang --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld |
| 97 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 98 | ############################################################################### |
| 99 | # Options for "generic_gcc" builds: these options should generally apply to |
| 100 | # builds using a GCC-based compiler, and default to the `gcc` executable on |
| 101 | # the `PATH`. While these are provided for convenience and may serve as a |
| 102 | # reference, it would be preferable for users to configure an explicit C++ |
| 103 | # toolchain instead of relying on `.bazelrc` files. |
| 104 | ############################################################################### |
| 105 | |
| 106 | # Set the default compiler to the `gcc` binary on the `PATH`. |
| 107 | build:generic_gcc --repo_env=CC=gcc |
| 108 | |
Benjamin Kramer | 2d2ad02 | 2022-08-06 19:47:44 | [diff] [blame] | 109 | # C++17 standard version is required. |
| 110 | build:generic_gcc --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 111 | |
Geoffrey Martin-Noble | ef72739 | 2022-02-01 01:50:59 | [diff] [blame] | 112 | # Build errors are not a helpful way to enforce deprecation in-repo and it is |
| 113 | # not the point of the Bazel build to catch usage of deprecated APIs. |
| 114 | build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated |
| 115 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 116 | # Disable GCC warnings that are noisy and/or false positives on LLVM code. |
| 117 | # These need to be global as some code triggering these is in header files. |
| 118 | build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter |
| 119 | build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment |
| 120 | build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess |
| 121 | build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized |
| 122 | build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation |
| 123 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 124 | ############################################################################### |
Chandler Carruth | 112dc16 | 2021-10-16 07:46:19 | [diff] [blame] | 125 | # Generic Windows flags common to both MSVC and Clang. |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 126 | ############################################################################### |
| 127 | |
Benjamin Kramer | 2d2ad02 | 2022-08-06 19:47:44 | [diff] [blame] | 128 | # C++17 standard version is required. |
| 129 | build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 |
Chandler Carruth | 0198d76 | 2021-11-02 02:52:38 | [diff] [blame] | 130 | |
| 131 | # Other generic dialect flags. |
| 132 | build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings |
| 133 | build:windows --copt=/Oi --host_copt=/Oi |
| 134 | build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast |
| 135 | |
| 136 | # Use the more flexible bigobj format for C++ files that have lots of symbols. |
| 137 | build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj |
Chandler Carruth | 112dc16 | 2021-10-16 07:46:19 | [diff] [blame] | 138 | |
| 139 | ############################################################################### |
| 140 | # Windows specific flags for building with MSVC. |
| 141 | ############################################################################### |
| 142 | |
| 143 | build:msvc --config=windows |
| 144 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 145 | build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors... |
| 146 | # ...but disable the ones that are violated |
| 147 | build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once |
| 148 | build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type |
| 149 | build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type |
| 150 | build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport |
| 151 | build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement |
| 152 | build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted |
| 153 | build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int |
| 154 | build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int |
| 155 | |
| 156 | build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors... |
| 157 | # ...but disable the ones that are violated. |
| 158 | build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files |
| 159 | |
Chandler Carruth | 112dc16 | 2021-10-16 07:46:19 | [diff] [blame] | 160 | ############################################################################### |
| 161 | # Options for Windows `clang-cl` builds. |
| 162 | ############################################################################### |
| 163 | |
| 164 | # We just start with the baseline Windows config as `clang-cl` doesn't accept |
| 165 | # some of the generic Clang flags. |
| 166 | build:clang-cl --config=windows |
| 167 | |
| 168 | # Switch from MSVC to the `clang-cl` compiler. |
| 169 | build:clang-cl --compiler=clang-cl |
| 170 | |
Chandler Carruth | 112dc16 | 2021-10-16 07:46:19 | [diff] [blame] | 171 | # Use Clang's internal warning flags instead of the ones that sometimes map |
| 172 | # through to MSVC's flags. |
| 173 | build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall |
| 174 | build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror |
| 175 | |
| 176 | # This doesn't appear to be enforced by any upstream bot. |
| 177 | build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused |
| 178 | |
| 179 | # There appears to be an unused constant in GoogleTest on Windows. |
| 180 | build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 181 | |
Chandler Carruth | 0198d76 | 2021-11-02 02:52:38 | [diff] [blame] | 182 | # Disable some warnings hit even with `clang-cl` in Clang's own code. |
| 183 | build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport |
| 184 | build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing |
| 185 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 186 | ############################################################################### |
Arthur Eubanks | 77ce95a | 2022-08-17 16:10:47 | [diff] [blame] | 187 | # Options for continuous integration. |
| 188 | ############################################################################### |
| 189 | |
| 190 | # -O1 tries to provide a reasonable tradeoff between compile times and runtime |
| 191 | # performance. However, if we start running more tests (e.g. all of |
| 192 | # check-clang) we may want more optimizations. |
Arthur Eubanks | 9a83f38 | 2022-08-22 16:36:23 | [diff] [blame] | 193 | # Note for anybody considering using --compilation_mode=opt in CI, it builds |
| 194 | # most files twice, one PIC version for shared libraries in tests, and one |
| 195 | # non-PIC version for binaries. |
Arthur Eubanks | 77ce95a | 2022-08-17 16:10:47 | [diff] [blame] | 196 | build:ci --copt=-O1 |
| 197 | |
Arthur Eubanks | d5a57ab | 2022-08-22 17:12:10 | [diff] [blame] | 198 | # Use clang. |
| 199 | build:ci --config=generic_clang |
| 200 | |
| 201 | # Speedup bazel using a ramdisk. |
| 202 | build:ci --sandbox_base=/dev/shm |
| 203 | |
Jordan Rupprecht | 4aa7769 | 2022-12-28 16:13:20 | [diff] [blame] | 204 | # Use system's mpfr and pfm instead of building it from source. |
Guillaume Chatelet | d856e5f | 2022-11-18 10:14:37 | [diff] [blame] | 205 | # This is non hermetic but helps with compile time. |
| 206 | build:ci --@llvm-project//libc:mpfr=system |
Jordan Rupprecht | 4aa7769 | 2022-12-28 16:13:20 | [diff] [blame] | 207 | build:ci --@llvm-project//llvm:pfm=system |
Guillaume Chatelet | d856e5f | 2022-11-18 10:14:37 | [diff] [blame] | 208 | |
Arthur Eubanks | d5a57ab | 2022-08-22 17:12:10 | [diff] [blame] | 209 | # Don't build/test targets tagged with "nobuildkite". |
| 210 | build:ci --build_tag_filters=-nobuildkite |
| 211 | build:ci --test_tag_filters=-nobuildkite |
| 212 | |
| 213 | # Show as many errors as possible. |
| 214 | build:ci --keep_going |
| 215 | |
| 216 | # Show test errors. |
| 217 | build:ci --test_output=errors |
| 218 | |
Keith Smiley | fbaec0f | 2024-06-04 19:23:06 | [diff] [blame] | 219 | # Only show failing tests to reduce output |
| 220 | build:ci --test_summary=terse |
| 221 | |
Christian Sigg | a70d999 | 2024-09-03 09:08:33 | [diff] [blame] | 222 | # Attempt to work around intermittent issue while trying to fetch remote blob. |
| 223 | # See e.g. https://github.com/bazelbuild/bazel/issues/18694. |
Christian Sigg | df4746d | 2024-09-03 16:15:27 | [diff] [blame] | 224 | build:ci --remote_default_exec_properties=cache-silo-key=CleverPeafowl |
Christian Sigg | a70d999 | 2024-09-03 09:08:33 | [diff] [blame] | 225 | |
Arthur Eubanks | 77ce95a | 2022-08-17 16:10:47 | [diff] [blame] | 226 | ############################################################################### |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 227 | |
Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 22:42:25 | [diff] [blame] | 228 | # The user.bazelrc file is not checked in but available for local mods. |
| 229 | # Always keep this at the end of the file so that user flags override. |
| 230 | try-import %workspace%/user.bazelrc |