xref: /llvm-project-15.0.7/utils/bazel/.bazelrc (revision ef72739e)
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# Prevent invalid caching if input files are modified during a build.
10build --experimental_guard_against_concurrent_changes
11
12###############################################################################
13# Options to select different strategies for linking potential dependent
14# libraries. The default leaves it disabled.
15###############################################################################
16
17build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external
18build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system
19
20build:terminfo_external --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=external
21build:terminfo_system --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=system
22
23###############################################################################
24# Options for "generic_clang" builds: these options should generally apply to
25# builds using a Clang-based compiler, and default to the `clang` executable on
26# the `PATH`. While these are provided for convenience and may serve as a
27# reference, it would be preferable for users to configure an explicit C++
28# toolchain instead of relying on `.bazelrc` files.
29###############################################################################
30
31# Set the default compiler to the `clang` binary on the `PATH`.
32build:generic_clang --repo_env=CC=clang
33
34# C++14 standard version is required.
35build:generic_clang --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
36
37# Use `-Wall` and `-Werror` for Clang.
38build:generic_clang --copt=-Wall --copt=-Werror --host_copt=-Wall --host_copt=-Werror
39
40# The Clang available on MacOS has a warning that isn't clean on MLIR code. The
41# warning doesn't show up with more recent Clangs, so just disable for now.
42build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis
43
44# Build errors are not a helpful way to enforce deprecation in-repo and it is
45# not the point of the Bazel build to catch usage of deprecated APIs.
46build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated
47
48###############################################################################
49# Options for "generic_gcc" builds: these options should generally apply to
50# builds using a GCC-based compiler, and default to the `gcc` executable on
51# the `PATH`. While these are provided for convenience and may serve as a
52# reference, it would be preferable for users to configure an explicit C++
53# toolchain instead of relying on `.bazelrc` files.
54###############################################################################
55
56# Set the default compiler to the `gcc` binary on the `PATH`.
57build:generic_gcc --repo_env=CC=gcc
58
59# C++14 standard version is required.
60build:generic_gcc --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
61
62# Build errors are not a helpful way to enforce deprecation in-repo and it is
63# not the point of the Bazel build to catch usage of deprecated APIs.
64build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated
65
66# Disable GCC warnings that are noisy and/or false positives on LLVM code.
67# These need to be global as some code triggering these is in header files.
68build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter
69build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment
70build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess
71build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized
72build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation
73
74# Use `-Werror` for GCC to make sure warnings don't slip past.
75build:generic_gcc --copt=-Werror --host_copt=-Werror
76
77###############################################################################
78# Generic Windows flags common to both MSVC and Clang.
79###############################################################################
80
81# C++14 standard version is required.
82build:windows --cxxopt=/std:c++14 --host_cxxopt=/std:c++14
83
84# Other generic dialect flags.
85build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings
86build:windows --copt=/Oi --host_copt=/Oi
87build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast
88
89# Use the more flexible bigobj format for C++ files that have lots of symbols.
90build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj
91
92###############################################################################
93# Windows specific flags for building with MSVC.
94###############################################################################
95
96build:msvc --config=windows
97
98build:msvc --copt=/WX --host_copt=/WX    # Treat warnings as errors...
99# ...but disable the ones that are violated
100build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once
101build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type
102build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type
103build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport
104build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement
105build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted
106build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int
107build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int
108
109build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors...
110# ...but disable the ones that are violated.
111build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files
112
113###############################################################################
114# Options for Windows `clang-cl` builds.
115###############################################################################
116
117# We just start with the baseline Windows config as `clang-cl` doesn't accept
118# some of the generic Clang flags.
119build:clang-cl --config=windows
120
121# Switch from MSVC to the `clang-cl` compiler.
122build:clang-cl --compiler=clang-cl
123
124# Use Clang's internal warning flags instead of the ones that sometimes map
125# through to MSVC's flags.
126build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall
127build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror
128
129# This doesn't appear to be enforced by any upstream bot.
130build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused
131
132# There appears to be an unused constant in GoogleTest on Windows.
133build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable
134
135# Disable some warnings hit even with `clang-cl` in Clang's own code.
136build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport
137build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing
138
139###############################################################################
140
141###############################################################################
142# Configuration for building remotely using Remote Build Execution (RBE)
143# Based on https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/bazel-1.0.0.bazelrc
144###############################################################################
145
146build:rbe --remote_instance_name=projects/llvm-bazel/instances/default_instance
147
148# Depending on how many machines are in the remote execution instance, setting
149# this higher can make builds faster by allowing more jobs to run in parallel.
150# Setting it too high can result in jobs that timeout, however, while waiting
151# for a remote machine to execute them.
152build:rbe --jobs=150
153
154# Set several flags related to specifying the platform, toolchain and java
155# properties.
156# These flags should only be used as is for the rbe-ubuntu16-04 container
157# and need to be adapted to work with other toolchain containers.
158build:rbe --host_javabase=@rbe_default//java:jdk
159build:rbe --javabase=@rbe_default//java:jdk
160build:rbe --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
161build:rbe --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
162build:rbe --crosstool_top=@rbe_default//cc:toolchain
163build:rbe --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
164# Platform flags:
165# The toolchain container used for execution is defined in the target indicated
166# by "extra_execution_platforms", "host_platform" and "platforms".
167# More about platforms: https://docs.bazel.build/versions/main/platforms.html
168build:rbe --extra_toolchains=@rbe_default//config:cc-toolchain
169build:rbe --extra_execution_platforms=@rbe_default//config:platform
170build:rbe --host_platform=@rbe_default//config:platform
171build:rbe --platforms=@rbe_default//config:platform
172
173build:rbe --define=EXECUTOR=remote
174
175# Enable remote execution so actions are performed on the remote systems.
176build:rbe --remote_executor=grpcs://remotebuildexecution.googleapis.com
177
178# Enforce stricter environment rules, which eliminates some non-hermetic
179# behavior and therefore improves both the remote cache hit rate and the
180# correctness and repeatability of the build.
181build:rbe --incompatible_strict_action_env=true
182
183# Set a higher timeout value, just in case.
184build:rbe --remote_timeout=3600
185
186# Local disk cache is incompatible with remote execution (for obvious reasons).
187build:rbe --disk_cache=""
188
189# Enable authentication. This will pick up application default credentials by
190# default. You can use --google_credentials=some_file.json to use a service
191# account credential instead.
192build:rbe --google_default_credentials=true
193
194# The user.bazelrc file is not checked in but available for local mods.
195# Always keep this at the end of the file so that user flags override.
196try-import %workspace%/user.bazelrc
197