forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bazelrc
266 lines (210 loc) · 11.4 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
##
## Workarounds for bugs and temporary things
##
try-import .bazelrc.local
startup --host_jvm_args=-Xmx3072m # we need at least 3G to reliably build, the default is to use 1/4 of memory, which makes flaky on 8G boxes
# enable https://github.com/google/googletest/pull/1653
common:build --define absl=1
common:test --test_env=GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1
##
## Custom toolchain.
##
build --crosstool_top=@llvm_toolchain_12_0_0//:toolchain --copt=-D_LIBCPP_ENABLE_NODISCARD
##
## Common build options across all build configurations
##
# Enable strict_action_env flag to. For more information on this feature see
# https://groups.google.com/forum/#!topic/bazel-discuss/_VmRfMyyHBk.
# This will be the new default behavior at some point (and the flag was flipped
# shortly in 0.21.0 - https://github.com/bazelbuild/bazel/issues/7026). Remove
# this flag here once flipped in Bazel again.
build --incompatible_strict_action_env
# Enforce that we don't rely on `@bazel_tools//platforms` and instead use the
# `@platforms` repository for constraint resolution. See
# https://github.com/bazelbuild/bazel/issues/8622 for more information.
build --incompatible_use_platforms_repo_for_constraints
# C / C++ Options
# Don't depend on system compiler
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build --copt=-fno-omit-frame-pointer
build --copt=-fstack-protector
build --copt=-Werror --copt=-Wimplicit-fallthrough --copt=-Wmissing-field-initializers
build --host_copt=-O1
build --host_copt=-DFORCE_DEBUG
build --host_cxxopt=-Wno-unused-variable --host_cxxopt=-Wno-overloaded-virtual --host_cxxopt=-Wno-unused-const-variable # ragel violates those and we want a silent build
build --host_cxxopt=-Wno-pass-failed # host build doesn't have enough optimizations enabled for clang to vectorize this loop reliably
# The MacOS CROSSTOOL in bazel defines _FORTIFY_SOURCE both on
# <command line>:1:9: and <built-in>:355:9: so sadly we turn them all off
build --copt=-Wno-macro-redefined
# Clang 12.0.0 has warnings when compiling LLVM 12.0.0 on C++20, sadly.
# TODO(jez) When we upgrade to LLVM 13.0.0+ can we delete this?
# TODO(jez) We will need these to build C++20, but emscripten doesn't even know about these options yet.
# Leaving them commented out so we can uncomment them after upgrading emscripten.
# build --host_cxxopt=-Wno-deprecated-anon-enum-enum-conversion
# build --host_cxxopt=-Wno-deprecated-enum-enum-conversion
# build --cxxopt=-Wno-deprecated-anon-enum-enum-conversion
# build --cxxopt=-Wno-deprecated-enum-enum-conversion
# build --cxxopt=-Wno-ambiguous-reversed-operator
##
## debug configuration
##
build:dbg --copt=-O0
build:dbg --compilation_mode=dbg
build:dbg --config=debugsymbols
build:dbg --config=rubydbg
build:rubydbg --copt=-DRUBY_DEBUG --copt=-DVM_CHECK_MODE=1 --copt=-DTRANSIENT_HEAP_CHECK_MODE --copt=-DRGENGC_CHECK_MODE --copt=-DENC_DEBUG
build:coverage --config=forcedebug
build:coverage --cxxopt=-Wno-pass-failed # coverage build fails vectorization
test:coverage --spawn_strategy=local
build --define=versioned=false
build:versioned --workspace_status_command=tools/buildstamp/get_workspace_status --stamp --define=versioned=true
build:dbg-darwin --config=dbg --platforms=@//tools/config:darwin_x86_64
build:dbg-linux --config=dbg --platforms=@//tools/config:linux_x86_64
##
## Configurations used for releases
##
# release version: optimized, with debug symbols and version information
build:release-common --define release=true
build:release-common --define jemalloc=true
build:release-common --compilation_mode=opt
build:release-common --config=backtracesymbols
build:release-common --config=static-libs
build:release-common --config=versioned
build:release-debug-common --config=forcedebug
build:release-debug-common --config=debugsymbols
build:release-debug-common --config=skipslowenforce
# harden: mark relocation sections read-only
build:release-linux --linkopt=-Wl,-z,relro,-z,now
build:release-linux --config=lto-linux --config=release-common --platforms=@//tools/config:linux_x86_64
# This is to turn on vector instructions where available.
# We used to do this unconditionally, but Rosetta 2 doesn't translate all vector instructions well.
#
# If we ever start making universal x86-64 + aarch64 binaries for macOS, we
# could think about re-enabling the vector instructions for x86-64.
#
# At Stripe: developer laptops run skylake, devboxes run skylake-avx512
# however some AWS instances in our fleet still run Sandy Bridge (Skylake predecessor), as of 2018.
build:release-linux --copt=-march=sandybridge
build:release-sanitized-linux --copt=-march=sandybridge
build:release-mac --config=release-common --platforms=@//tools/config:darwin_x86_64
build:release-debug-linux --config=release-linux
build:release-debug-linux --config=release-debug-common
build:release-debug-mac --config=release-mac
build:release-debug-mac --config=release-debug-common
build:release-sanitized-linux --copt=-O2
build:release-sanitized-linux --config=sanitize-linux
build:release-sanitized-linux --define jemalloc=false
build:release-sanitized-linux --config=release-debug-common
build:release-sanitized-mac --copt=-O2
build:release-sanitized-mac --config=sanitize-mac
build:release-sanitized-mac --define jemalloc=false
build:release-sanitized-linux --config=release-debug-common
##
## Configuration used to to as much testing as possible in CI
##
build:test-sanitized-linux --config=release-sanitized-linux --config=dbg --nostamp --define release=false
test:test-sanitized-linux --test_env="UBSAN_OPTIONS=print_stacktrace=1"
test:test-sanitized-linux --test_env="ASAN_OPTIONS=detect_leaks=0"
build:test-sanitized-mac --config=release-sanitized-mac --config=dbg --nostamp --define release=false
test:test-sanitized-mac --test_env="UBSAN_OPTIONS=print_stacktrace=1"
build:reduce-intermediate-file-size-base --copt=-g0 --linkopt=-g0 # used by buildfarm to have less debug information on disk
build:reduce-intermediate-file-size-base --strip=always
build:reduce-intermediate-file-size-base --copt=-fno-standalone-debug --linkopt=-fno-standalone-debug # used by buildfarm to have less debug information on disk
# extend reduce-intermediate-file-size with -Os
build:buildfarm --copt=-Os --linkopt=-Os --config=reduce-intermediate-file-size-base
test:buildfarm --test_output=errors
build:buildfarm-sanitized-linux --config=test-sanitized-linux --config=buildfarm
build:buildfarm-sanitized-mac --config=test-sanitized-mac --config=buildfarm --config=shared-libs
##
## Shared fragments of configuration
##
# DEBUG_MODE is set by default for all builds except --config=release.
# Use this flag to set DEBUG_MODE even for --config=release.
build:forcedebug --copt=-DFORCE_DEBUG
# DEBUG_MODE controls whether ENFORCEs are enabled. Some ENFORCEs are super
# slow and/or don't pass on Stripe's codebase. Long term we should definitely
# make these checks pass and maybe even make them fast, but for now we provide
# a way to skip slow debug checks (for example, when compiling debug release
# builds)
build:skipslowenforce --copt=-DSKIP_SLOW_ENFORCE
# LTO build. Much longer compilation time. Smaller size and better perf.
build:lto --copt=-flto=thin
build:lto --linkopt=-flto=thin
build:lto --config=static-libs
## flags that substantially increase Clang&LLVMs ability to devirtualize calls
build:lto-linux --linkopt=-Wl,--icf=all
build:lto-linux --config=lto
# By default, we make static builds, but we can also use dynamic linking if asked to.
# Note that dynamic linking is not fully supported by some of our toolchains and thus it may not always work.
build --define=linkshared=false
build:shared-libs --define=linkshared=true --copt=-fPIC --linkopt=-fPIC
build:static-libs --define=linkshared=false --copt=-fno-PIC --linkopt=-fno-PIC
build:static-libs --linkopt=-fno-pie --copt=-fno-pie
# It's useful to be able to write `config_setting` rules for "this is
# an unsanitized build", but we can't express "copt does not contain
# -fsanitize". So we set this `--define` and unset it if we're using a
# sanitizer.
build --define unsanitized=true
# sanitize build: run with ASAN and UBSAN. Catches most memory and
# undefined-behavior errors, substantially larger and slower binary.
build:sanitize --config=asan --config=ubsan
build:asan --copt=-fsanitize=address --copt=-fsanitize-address-use-after-scope
build:asan --linkopt=-fsanitize=address --linkopt=-fsanitize-address-use-after-scope
build:asan --copt=-DADDRESS_SANITIZER # used by abseil
build:asan --copt=-DHAS_SANITIZER
build:asan --define unsanitized=false
build:ubsan --copt=-fsanitize=undefined --copt=-fno-sanitize-recover=undefined
build:ubsan --linkopt=-fsanitize=undefined --copt=-fno-sanitize-recover=undefined
build:ubsan --define unsanitized=false
build:ubsan --copt=-DHAS_SANITIZER
# Bazel links C++ files with $CC, not $CXX, this breaks UBSan
build:sanitize-linux --linkopt=external/llvm_toolchain_12_0_0/lib/clang/12.0.0/lib/linux/libclang_rt.asan_cxx-x86_64.a
build:sanitize-linux --linkopt=external/llvm_toolchain_12_0_0/lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone_cxx-x86_64.a
build:sanitize-linux --linkopt=external/llvm_toolchain_12_0_0/lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone-x86_64.a
build:sanitize-linux --config=sanitize
build:sanitize-mac --config=sanitize
build:tsan --copt=-fsanitize=thread
build:tsan --linkopt=-fsanitize=thread
# Build optimized for executable size. Can be faster if size of executable code is a bottleneck.
build:size --linkopt=-Os --config=lto
build:size --copt=-Os --config=lto
### Debug symbols on OS X. ###
# From https://github.com/RobotLocomotion/drake/blob/master/tools/cc_toolchain/bazel.rc
# See https://github.com/bazelbuild/bazel/issues/2537
build:debugsymbols --copt=-g3 --copt=-fstandalone-debug --copt=-DDEBUG_SYMBOLS --copt=-glldb
build:debugsymbols --linkopt=-g3 --linkopt=-fstandalone-debug --linkopt=-DDEBUG_SYMBOLS --linkopt=-glldb
build:debugsymbols --spawn_strategy=local
build:debugsymbols --genrule_strategy=local
# simpler & smaller debug symbols. Good enough for backtraces, but not for debugging.
build:backtracesymbols --copt=-DDEBUG_SYMBOLS --copt=-gline-tables-only
build:backtracesymbols --linkopt=-DDEBUG_SYMBOLS --linkopt=-gline-tables-only
build:backtracesymbols --spawn_strategy=local
build:backtracesymbols --genrule_strategy=local
build --strip=never
##
## Fuzzing
##
build:fuzz --copt=-fsanitize=fuzzer --linkopt=-fsanitize=fuzzer --config=asan
build:fuzz --config=forcedebug --config=debugsymbols
build:fuzz --copt=-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
##
## Webasm config. Please use either of those depending on your platform
##
build:webasm-linux --crosstool_top=//tools/toolchain/webasm-linux --config=webasm
build:webasm-darwin --crosstool_top=//tools/toolchain/webasm-darwin --config=webasm
# common webasm config
# Use --cpu as a differentiator.
build:webasm --cpu=webasm --spawn_strategy=local --genrule_strategy=local --copt=-Oz --linkopt=-Oz --copt=-DMDB_USE_ROBUST=0
build:webasm --define release=true
build:webasm --compilation_mode=opt
build:webasm --copt=-DNDEBUG --linkopt=-DNDEBUG # for some reason emscripten doesn't pass those when -O2\-Oz are specified
build:webasm --copt=--llvm-lto --copt=3 --linkopt=--llvm-lto --linkopt=3
# Specify a "sane" C++ toolchain for the host platform.
build:webasm --host_crosstool_top=@llvm_toolchain_12_0_0//:toolchain
##
## Stripe's ci passes --config=ci, we need it to exist
##
common:stripeci --config=ci
common:ci --color yes
# enables a lot of features in mac instruments profiler
build:instruments --linkopt=-framework --linkopt=CoreFoundation