-
Notifications
You must be signed in to change notification settings - Fork 467
/
.bazelrc
212 lines (182 loc) · 8.65 KB
/
.bazelrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Enables picking up host-OS specific config, i.e. adds support for the following:
# `build:[ linux | macos | windows | freebsd | openbsd ]`
common --enable_platform_specific_config
# TODO(parkmycar): Migrate to Bzlmod.
#
# Note: We are not yet using Bzlmod because there are parts of the ecosystem
# that haven't yet migrated to it.
common --noenable_bzlmod
# Required for remote caching to be effective.
#
# Otherwise Bazel will passthrough the current system's PATH in the execution
# environment, which differs between systems and thus breaks remote caching.
build --incompatible_strict_action_env
# Prevent actions in the sandbox from accessing the network.
#
# TODO(parkmycar): `prof-http`s build script downloads resources from npm.
#build --sandbox_default_allow_network=false
# Bazel provides the macOS 14.5 SDK as the sysroot, we also set the minimum
# version to prevent breaking the remote cache across developer machines.
common --copt=-mmacosx-version-min=14.0
common --linkopt=-mmacosx-version-min=14.0
common --macos_sdk_version=14.0
# Note(parkmycar): Ideally we would error on unused command line arguments, but
# trying to constrain the above arguments to just macos doesn't seem to work.
common --copt=-Wno-unused-command-line-argument
common --linkopt=-Wno-unused-command-line-argument
# Config for building protobuf.
build --copt=-Wno-error=deprecated-declarations
# Required to stamp our development builds with the current git hash.
#
# This script gets run before every build, see the script for more info.
build:release-stamp --stamp --workspace_status_command "python3 misc/bazel/build-info/workspace_status.py"
# Output all test output by default, this makes it most like cargo.
#
# Note: We used to have 'stream' here, but that forces Bazel to serialize test execution.
build --test_output=all
# Environment variables to pass through to the test runner. These can impact
# remote cache hits, so add them sparingly.
#
# TODO(parkmycar): Switch over to using `env_inherit` on `rust_test` once that's stable.
# <https://github.com/bazelbuild/rules_rust/pull/2809>
build --test_env=COCKROACH_URL
# Allows spaces to in filenames, without this Rust Doc tests fail to build.
build:macos --experimental_inprocess_symlink_creation
# Tracks stashed sandboxes in-memory so it uses less I/O on reuse.
#
# Bazel's sandbox performance on macOS doesn't scale very well, see: <https://github.com/bazelbuild/bazel/issues/8230>
build --experimental_inmemory_sandbox_stashes
# Always have Bazel output why it rebuilt something, should make debugging builds easier.
#
# TODO(parkmycar): Enable this under a "debug" or "verbose"
# common --explain=bazel-explain.log
# common --verbose_explanations
# Compress any artifacts larger than 2MiB with zstd.
common --remote_cache_compression
common --experimental_remote_cache_compression_threshold=2097152
# Memoizes merkle tree calculations to improve the remote cache hit checking speed.
common --experimental_remote_merkle_tree_cache
# Number of merkle trees to memoize (default 1000).
common --experimental_remote_merkle_tree_cache_size=5000
# Don't make the user wait for uploading artifacts to complete, finish it in the background.
common --bes_upload_mode=fully_async
# Make sure any local disk cache stays within a reasonable size.
common --experimental_disk_cache_gc_max_size=80G
common --experimental_disk_cache_gc_max_age=14d
# Tells `xz` to use all available cores.
action_env=XZ_OPT=-T0
#
# Config when running Bazel from a script.
#
# Silence most UI output since it's noisy.
run:script --ui_event_filters=-info,-stdout,-stderr --noshow_progress
# LLVM's libc++ has different assertion modes which can be configured to catch
# undefined behavior. See: <https://libcxx.llvm.org/Hardening.html>
build:debug --cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"
build:debug --host_cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"
build:debug --@rules_rust//:extra_rustc_flag="-Csplit-debuginfo=unpacked"
#
# Debug Info Configuration
#
# TODO(parkmycar): Enable this for macOS. `toolchains_llvm` defaults to ld64 which
# doesn't support zlib compression.
build:linux --linkopt="-Wl,--compress-debug-sections=zlib"
build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,--compress-debug-sections=zlib"
# Specifying "-O2" uses level 6 zlib compression.
build:linux --linkopt="-Wl,-O2"
build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,-O2"
build:linux --copt="-gz=zlib"
# Match the DWARF version used by Rust
#
# See: <https://doc.rust-lang.org/stable/unstable-book/compiler-flags/dwarf-version.html>
build:linux --copt="-gdwarf-4"
build:linux --linkopt="-gdwarf-4"
build:macos --copt="-gdwarf-2"
build:macos --linkopt="-gdwarf-2"
# Emit full debug info, allowing us to easily analyze core dumps from staging
# (and, in an emergency, also prod).
build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cdebuginfo=2
build:debuginfo-full --copt=-g2
build:debuginfo-full --strip=never
build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cstrip=none
build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cdebuginfo=line-tables-only
build:debuginfo-limited --copt=-gline-tables-only
build:debuginfo-limited --strip=never
build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cstrip=none
build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cdebuginfo=0
build:debuginfo-none --copt=-g0
build:debuginfo-none --strip=always
build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cstrip=symbols
#
# Common Build Configuration
#
build --linkopt="-fuse-ld=lld"
build --@rules_rust//:extra_rustc_flag="-Clink-arg=-fuse-ld=lld"
build --@rules_rust//:extra_rustc_flag="-Csymbol-mangling-version=v0"
# We use 64 because it's enough to totally saturate a CI builder so our builds
# are as fast as possible, and it's less than the default of 256 used with
# Cargo when incremental compilation is enabled.
build --@rules_rust//:extra_rustc_flag="-Ccodegen-units=64"
# Enabling pipelined builds allows dependent libraries to begin compiling with
# just `.rmeta` instead of the full `.rlib`.
build --@rules_rust//rust/settings:pipelined_compilation=True
# `cargo check` like config, still experimental!
#
# Ignores all outputs other than `.rmeta`, requires pipelied_compilation to be enabled!
build:check --output_groups=build_metadata
# CI Build Configuration
#
# Note: This shouldn't change any config of the built binary, just the way it
# gets built.
#
# `/dev/shm` is a RAM backed temporary filesystem, it should speedup sandbox creation.
build:ci --sandbox_base=/dev/shm
# Always enable verbose failures in CI, makes it easier to debug failures.
build:ci --verbose_failures
# Release Build Configuration
#
build:release --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
build:release --copt=-O3
build:release --copt=-DNDEBUG
build:release --compilation_mode=opt
# We only enable Link Time Optimization for CI builds and not local release builds.
build:release-lto --copt=-flto=thin
build:release-lto --linkopt=-flto=thin
build:release-lto --@rules_rust//:extra_rustc_flag=-Clto=thin
# Builds from `main` or tagged builds.
#
# Note: We don't use a ramdisk for tagged builds because the full debuginfo is
# too large and we OOD/OOM.
build:release-tagged --config=release --config=release-lto --config=release-stamp --config=debuginfo-full
# PRs in CI.
#
# Not doing a full stamp nor omitting full debug info, greatly speeds up compile times.
build:release-dev --config=release --config=release-lto --config=debuginfo-limited
# "Optimized" Build.
#
# Provides both reasonably fast compile times and runtimes.
build:optimized --compilation_mode=opt
build:optimized --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
build:optimized --copt=-O2
build:optimized --copt=-DNDEBUG
build:optimized --config=debuginfo-none
build:optimized --copt=-fno-lto
build:optimized --linkopt=-fno-lto
build:optimized --@rules_rust//:extra_rustc_flag=-Clto=off
build:optimized --@rules_rust//:extra_rustc_flag=-Cembed-bitcode=no
# Build with the Rust Nightly Toolchain
build:rust-nightly --@rules_rust//rust/toolchain/channel=nightly
# Cross Language LTO
#
# <https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html>
#
# TODO(parkmycar): Re-enable these. They eiter cause a compilation failure because of
# missing object files, or (seemingly) makes the number of codegen units 1 which compiles
# way too slow.
#build:release --@rules_rust//:extra_rustc_flag="-Clinker-plugin-lto"
#build:linux --@rules_rust//rust/settings:experimental_use_cc_common_link=True
# This 'features' option comes from the `unix_cc_toolchain_config` in Bazel core and sets all the
# right flags.
#
# See: <https://github.com/bazelbuild/bazel/blob/master/tools/cpp/unix_cc_toolchain_config.bzl>
#build:release --features=thin_lto