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
5 ###############################################################################
6 # Common flags that apply to all configurations.
7 # Use sparingly for things common to all compilers and platforms.
8 ###############################################################################
9 # Prevent invalid caching if input files are modified during a build.
10 build --experimental_guard_against_concurrent_changes
12 # In opt mode, bazel by default builds both PIC and non-PIC object files for
13 # tests vs binaries. We don't need this feature and it slows down opt builds
17 # Shared objects take up more space. With fast linkers and binaries that aren't
18 # super large, the benefits of shared objects are minimal.
19 build --dynamic_mode=off
21 # Rely on compiler flags to compile with debug info/strip rather than stripping
22 # based on compilation_mode.
25 # Add layering check to all projects.
26 build --features=layering_check
28 # Opt out of legacy lax behavior implicitly exporting files that are rule inputs
29 # with default visibility.
30 # See: https://bazel.build/reference/be/functions#exports_files
31 build --incompatible_no_implicit_file_export
33 ###############################################################################
34 # Options to select different strategies for linking potential dependent
35 # libraries. The default leaves it disabled.
36 ###############################################################################
38 build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external
39 build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system
41 build:terminfo_external --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=external
42 build:terminfo_system --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=system
44 ###############################################################################
45 # Options for "generic_clang" builds: these options should generally apply to
46 # builds using a Clang-based compiler, and default to the `clang` executable on
47 # the `PATH`. While these are provided for convenience and may serve as a
48 # reference, it would be preferable for users to configure an explicit C++
49 # toolchain instead of relying on `.bazelrc` files.
50 ###############################################################################
52 # Set the default compiler to the `clang` binary on the `PATH`.
53 build:generic_clang --repo_env=CC=clang
55 # C++17 standard version is required.
56 build:generic_clang --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
58 # Use `-Wall` for Clang.
59 build:generic_clang --copt=-Wall --host_copt=-Wall
61 # The Clang available on MacOS has a warning that isn't clean on MLIR code. The
62 # warning doesn't show up with more recent Clangs, so just disable for now.
63 build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis
65 # Build errors are not a helpful way to enforce deprecation in-repo and it is
66 # not the point of the Bazel build to catch usage of deprecated APIs.
67 build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated
69 # lld links faster than other linkers. Assume that anybody using clang also has
71 build:generic_clang --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld
73 ###############################################################################
74 # Options for "generic_gcc" builds: these options should generally apply to
75 # builds using a GCC-based compiler, and default to the `gcc` executable on
76 # the `PATH`. While these are provided for convenience and may serve as a
77 # reference, it would be preferable for users to configure an explicit C++
78 # toolchain instead of relying on `.bazelrc` files.
79 ###############################################################################
81 # Set the default compiler to the `gcc` binary on the `PATH`.
82 build:generic_gcc --repo_env=CC=gcc
84 # C++17 standard version is required.
85 build:generic_gcc --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
87 # Build errors are not a helpful way to enforce deprecation in-repo and it is
88 # not the point of the Bazel build to catch usage of deprecated APIs.
89 build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated
91 # Disable GCC warnings that are noisy and/or false positives on LLVM code.
92 # These need to be global as some code triggering these is in header files.
93 build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter
94 build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment
95 build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess
96 build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized
97 build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation
99 ###############################################################################
100 # Generic Windows flags common to both MSVC and Clang.
101 ###############################################################################
103 # C++17 standard version is required.
104 build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
106 # Other generic dialect flags.
107 build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings
108 build:windows --copt=/Oi --host_copt=/Oi
109 build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast
111 # Use the more flexible bigobj format for C++ files that have lots of symbols.
112 build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj
114 ###############################################################################
115 # Windows specific flags for building with MSVC.
116 ###############################################################################
118 build:msvc --config=windows
120 build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors...
121 # ...but disable the ones that are violated
122 build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once
123 build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type
124 build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type
125 build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport
126 build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement
127 build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted
128 build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int
129 build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int
131 build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors...
132 # ...but disable the ones that are violated.
133 build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files
135 ###############################################################################
136 # Options for Windows `clang-cl` builds.
137 ###############################################################################
139 # We just start with the baseline Windows config as `clang-cl` doesn't accept
140 # some of the generic Clang flags.
141 build:clang-cl --config=windows
143 # Switch from MSVC to the `clang-cl` compiler.
144 build:clang-cl --compiler=clang-cl
146 # Use Clang's internal warning flags instead of the ones that sometimes map
147 # through to MSVC's flags.
148 build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall
149 build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror
151 # This doesn't appear to be enforced by any upstream bot.
152 build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused
154 # There appears to be an unused constant in GoogleTest on Windows.
155 build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable
157 # Disable some warnings hit even with `clang-cl` in Clang's own code.
158 build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport
159 build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing
161 ###############################################################################
162 # Options for continuous integration.
163 ###############################################################################
165 # -O1 tries to provide a reasonable tradeoff between compile times and runtime
166 # performance. However, if we start running more tests (e.g. all of
167 # check-clang) we may want more optimizations.
168 # Note for anybody considering using --compilation_mode=opt in CI, it builds
169 # most files twice, one PIC version for shared libraries in tests, and one
170 # non-PIC version for binaries.
174 build:ci --config=generic_clang
176 # Speedup bazel using a ramdisk.
177 build:ci --sandbox_base=/dev/shm
179 # Use system's mpfr and pfm instead of building it from source.
180 # This is non hermetic but helps with compile time.
181 build:ci --@llvm-project//libc:mpfr=system
182 build:ci --@llvm-project//llvm:pfm=system
184 # Don't build/test targets tagged with "nobuildkite".
185 build:ci --build_tag_filters=-nobuildkite
186 build:ci --test_tag_filters=-nobuildkite
188 # Show as many errors as possible.
189 build:ci --keep_going
192 build:ci --test_output=errors
194 ###############################################################################
196 # The user.bazelrc file is not checked in but available for local mods.
197 # Always keep this at the end of the file so that user flags override.
198 try-import %workspace%/user.bazelrc