Debian Codegraph @

utils/bazel/.bazelrc

raw
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 ###############################################################################
9
10 # Flip off to disable MODULE.bazel until we're ready.
11 # https://github.com/llvm/llvm-project/issues/55924
12 common --enable_bzlmod=false --enable_workspace
13
14 # TODO: Remove lit test reliance on this
15 common --legacy_external_runfiles
16
17 # Prevent invalid caching if input files are modified during a build.
18 build --experimental_guard_against_concurrent_changes
19
20 # Automatically enable --config=(linux|macos|windows) based on the host
21 build --enable_platform_specific_config
22
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.
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
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
35 # Rely on compiler flags to compile with debug info/strip rather than stripping
36 # based on compilation_mode.
37 build --strip=never
38
39 # Add layering check to all projects.
40 build --features=layering_check
41
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
47 # Enable so downstream users can flip this flag globally, this should
48 # eventually become the default
49 common --incompatible_disallow_empty_glob
50
51 # TODO: Remove once we move to bazel 7.x
52 build --experimental_cc_shared_library
53
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
61 # Enable header processing to verify that header-only libraries are
62 # self-contained (for sub-projects that enable "parse_headers" feature).
63 # See https://bazel.build/docs/bazel-and-cpp#toolchain-features
64 build --process_headers_in_dependencies
65
66 ###############################################################################
67 # Options to select different strategies for linking potential dependent
68 # libraries. The default leaves it disabled.
69 ###############################################################################
70
71 build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external
72 build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system
73
74 ###############################################################################
75 # Options for "generic_clang" builds: these options should generally apply to
76 # builds using a Clang-based compiler, and default to the `clang` executable on
77 # the `PATH`. While these are provided for convenience and may serve as a
78 # reference, it would be preferable for users to configure an explicit C++
79 # toolchain instead of relying on `.bazelrc` files.
80 ###############################################################################
81
82 # Set the default compiler to the `clang` binary on the `PATH`.
83 build:generic_clang --repo_env=CC=clang
84
85 # C++17 standard version is required.
86 build:generic_clang --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
87
88 # Use `-Wall` for Clang.
89 build:generic_clang --copt=-Wall --host_copt=-Wall
90
91 # The Clang available on MacOS has a warning that isn't clean on MLIR code. The
92 # warning doesn't show up with more recent Clangs, so just disable for now.
93 build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis
94
95 # Build errors are not a helpful way to enforce deprecation in-repo and it is
96 # not the point of the Bazel build to catch usage of deprecated APIs.
97 build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated
98
99 # lld links faster than other linkers. Assume that anybody using clang also has
100 # lld available.
101 build:generic_clang --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld
102
103 ###############################################################################
104 # Options for "generic_gcc" builds: these options should generally apply to
105 # builds using a GCC-based compiler, and default to the `gcc` executable on
106 # the `PATH`. While these are provided for convenience and may serve as a
107 # reference, it would be preferable for users to configure an explicit C++
108 # toolchain instead of relying on `.bazelrc` files.
109 ###############################################################################
110
111 # Set the default compiler to the `gcc` binary on the `PATH`.
112 build:generic_gcc --repo_env=CC=gcc
113
114 # C++17 standard version is required.
115 build:generic_gcc --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
116
117 # Build errors are not a helpful way to enforce deprecation in-repo and it is
118 # not the point of the Bazel build to catch usage of deprecated APIs.
119 build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated
120
121 # Disable GCC warnings that are noisy and/or false positives on LLVM code.
122 # These need to be global as some code triggering these is in header files.
123 build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter
124 build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment
125 build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess
126 build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized
127 build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation
128
129 ###############################################################################
130 # Generic Windows flags common to both MSVC and Clang.
131 ###############################################################################
132
133 # C++17 standard version is required.
134 build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
135
136 # Other generic dialect flags.
137 build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings
138 build:windows --copt=/Oi --host_copt=/Oi
139 build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast
140
141 # Use the more flexible bigobj format for C++ files that have lots of symbols.
142 build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj
143
144 ###############################################################################
145 # Windows specific flags for building with MSVC.
146 ###############################################################################
147
148 build:msvc --config=windows
149
150 build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors...
151 # ...but disable the ones that are violated
152 build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once
153 build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type
154 build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type
155 build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport
156 build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement
157 build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted
158 build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int
159 build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int
160
161 build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors...
162 # ...but disable the ones that are violated.
163 build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files
164
165 ###############################################################################
166 # Options for Windows `clang-cl` builds.
167 ###############################################################################
168
169 # We just start with the baseline Windows config as `clang-cl` doesn't accept
170 # some of the generic Clang flags.
171 build:clang-cl --config=windows
172
173 # Switch from MSVC to the `clang-cl` compiler.
174 build:clang-cl --compiler=clang-cl
175
176 # Use Clang's internal warning flags instead of the ones that sometimes map
177 # through to MSVC's flags.
178 build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall
179 build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror
180
181 # This doesn't appear to be enforced by any upstream bot.
182 build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused
183
184 # There appears to be an unused constant in GoogleTest on Windows.
185 build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable
186
187 # Disable some warnings hit even with `clang-cl` in Clang's own code.
188 build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport
189 build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing
190
191 ###############################################################################
192 # Options for continuous integration.
193 ###############################################################################
194
195 # -O1 tries to provide a reasonable tradeoff between compile times and runtime
196 # performance. However, if we start running more tests (e.g. all of
197 # check-clang) we may want more optimizations.
198 # Note for anybody considering using --compilation_mode=opt in CI, it builds
199 # most files twice, one PIC version for shared libraries in tests, and one
200 # non-PIC version for binaries.
201 build:ci --copt=-O1
202
203 # Use clang.
204 build:ci --config=generic_clang
205
206 # Speedup bazel using a ramdisk.
207 build:ci --sandbox_base=/dev/shm
208
209 # Use system's mpfr and pfm instead of building it from source.
210 # This is non hermetic but helps with compile time.
211 build:ci --@llvm-project//libc:mpfr=system
212 build:ci --@llvm-project//llvm:pfm=system
213
214 # Don't build/test targets tagged with "nobuildkite".
215 build:ci --build_tag_filters=-nobuildkite
216 build:ci --test_tag_filters=-nobuildkite
217
218 # Show as many errors as possible.
219 build:ci --keep_going
220
221 # Show test errors.
222 build:ci --test_output=errors
223
224 # Only show failing tests to reduce output
225 build:ci --test_summary=terse
226
227 # Attempt to work around intermittent issue while trying to fetch remote blob.
228 # See e.g. https://github.com/bazelbuild/bazel/issues/18694.
229 build:ci --remote_default_exec_properties=cache-silo-key=CleverPeafowl
230
231 ###############################################################################
232
233 # The user.bazelrc file is not checked in but available for local mods.
234 # Always keep this at the end of the file so that user flags override.
235 try-import %workspace%/user.bazelrc