-
Notifications
You must be signed in to change notification settings - Fork 323
/
.bazelrc
385 lines (325 loc) · 21.3 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
common --enable_platform_specific_config
build --verbose_failures
build --build_tag_filters=-off-by-default
test --test_tag_filters=-off-by-default
test:asan --test_tag_filters=-off-by-default,-no-asan
# exclude enormous tests by default
build --test_size_filters=-enormous
# use lower test timeouts: https://bazel.build/reference/test-encyclopedia#role-test-runner
# corresponds to small,medium,large,enormous tests (medium is default)
build --test_timeout=1,15,60,240
# Not using bzlmod for dependencies yet
common --noenable_bzlmod
# bazel7 enables Build without the Bytes (BwoB) by default. This significantly speeds up builds
# using the remote cache since less data needs to be fetched. Set remote_cache_eviction_retries
# which is required to fully support a "dumb" cache. Bazel 8 already sets this value by default.
build --experimental_remote_cache_eviction_retries=5
# Note that we use remote_download_minimal for test builds, which avoids fetching build outputs
# where possible. While several previous BwoB bugs have been fixed, this is slower than it could be
# due to https://github.com/bazelbuild/bazel/issues/20576.
# Windows build is failing on some runs due to FileAccessException errors, Bazel has had several
# similar bugs in the past. Disable BwoB for now.
build:windows --remote_download_all
# Import CI-specific configuration. As the amount of custom configuration settings we use grows,
# consider moving more flags out to separate files.
import %workspace%/build/ci.bazelrc
import %workspace%/build/lint.bazelrc
# Enable webgpu
build --//src/workerd/io:enable_experimental_webgpu=True
# Avoid generating duplicate runfile trees. This will become the default in a future bazel version.
build --nolegacy_external_runfiles
# Flip this early to avoid breaking compatibility once it becomes the default.
build --incompatible_disallow_empty_glob
# Prevents bazel cache invalidation when switching terminals
build --incompatible_strict_action_env
# Dawn tint build flags
build --@dawn//src/tint:tint_build_glsl_writer=False
build --@dawn//src/tint:tint_build_glsl_validator=False
build --@dawn//src/tint:tint_build_hlsl_writer=True
build --@dawn//src/tint:tint_build_ir=False
build --@dawn//src/tint:tint_build_msl_writer=True
build --@dawn//src/tint:tint_build_spv_reader=False
build --@dawn//src/tint:tint_build_spv_writer=True
build --@dawn//src/tint:tint_build_wgsl_reader=True
build --@dawn//src/tint:tint_build_wgsl_writer=True
# Our dependencies (ICU, zlib, etc.) produce a lot of these warnings, so we disable them. Depending
# on the clang version, zlib either produces warnings for -Wdeprecated-non-prototype or does not
# have that option, so disable -Wunknown-warning-option there too.
build --per_file_copt='external@-Wno-error'
build --per_file_copt='external/v8@-Wno-deprecated-declarations'
build --per_file_copt='external/com_googlesource_chromium_icu@-Wno-ambiguous-reversed-operator,-Wno-deprecated-declarations'
build --host_per_file_copt='external/com_googlesource_chromium_icu@-Wno-ambiguous-reversed-operator,-Wno-deprecated-declarations'
build --per_file_copt='external/dawn@-Wno-shorten-64-to-32,-Wno-unneeded-internal-declaration,-Wno-deprecated-this-capture'
build --host_per_file_copt='external/dawn@-Wno-shorten-64-to-32,-Wno-unneeded-internal-declaration,-Wno-deprecated-this-capture'
build --per_file_copt='external/zlib@-Wno-unknown-warning-option,-Wno-deprecated-non-prototype'
build --host_per_file_copt='external/zlib@-Wno-unknown-warning-option,-Wnodeprecated-non-prototype'
# for some reason tcmalloc uses internal msan-enabled annotation in the code, rather than public one
build --per_file_copt=external/com_google_tcmalloc@-DANNOTATE_MEMORY_IS_INITIALIZED=ABSL_ANNOTATE_MEMORY_IS_INITIALIZED
build --per_file_copt=external/com_google_protobuf@-Wno-deprecated-declarations,-Wno-deprecated-pragma,-Wno-deprecated-this-capture
build --host_per_file_copt=external/com_google_protobuf@-Wno-deprecated-declarations,-Wno-deprecated-pragma,-Wno-deprecated-this-capture
# Increasing the optimization level of some portions of V8 significantly speeds up Python tests
# in GitHub Actions. This is an optional performance hack and shouly only be used in CI.
build:v8-codegen-opt --per_file_copt=v8/src/compiler@-O2
build:v8-codegen-opt --per_file_copt=v8/src/common@-O2
build:v8-codegen-opt --per_file_copt=v8/src/builtins@-O2
build:v8-codegen-opt --per_file_copt=v8/src/heap@-O2
build:v8-codegen-opt --per_file_copt=v8/src/snapshot@-O2
build:v8-codegen-opt --per_file_copt=v8/src/objects@-O2
build:v8-codegen-opt --per_file_copt=v8/src/wasm@-O2
build:v8-codegen-opt --per_file_copt=v8/src/base@-O2
# Disable relaxing all jumps during LLVM codegen under -O0, which previously led to build
# performance improvements but makes code size worse. This will be the default in LLVM19.
# https://maskray.me/blog/2024-04-27-clang-o0-output-branch-displacement-and-size-increase
build:unix --copt="-mno-relax-all" --host_copt="-mno-relax-all"
# Limit transitive header includes within libc++. This improves compliance with IWYU, helps avoid
# errors with downstream projects that implicitly define this already and reduces total include size.
https://libcxx.llvm.org/DesignDocs/HeaderRemovalPolicy.html
build:unix --cxxopt=-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES --host_cxxopt=-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES
# Do not enable libc++ ABI tags. This makes mangled symbol names and thus include overhead and code
# size slightly smaller and is safe as long as we don't link with several copies of libc++.
build:unix --cxxopt=-D_LIBCPP_NO_ABI_TAG --host_cxxopt=-D_LIBCPP_NO_ABI_TAG
# Disable the experimental (and currently incomplete) parallel STL implementation as with
# downstream, this reduces the include overhead for <algorithm>.
build:unix --cxxopt=-D_LIBCPP_HAS_NO_INCOMPLETE_PSTL --host_cxxopt=-D_LIBCPP_HAS_NO_INCOMPLETE_PSTL
# V8 redefines the _WIN32_WINNT set by bazel, disable warnings for redefined macros. Since V8 uses
# a global define for this, we need to apply it for everything.
# TODO(cleanup): Patch upstream V8 to use local_defines for this instead.
build:windows --copt='-Wno-macro-redefined'
build:windows --host_copt='-Wno-macro-redefined'
# Dawn/Tint adds compiler flags that are ignored on Windows
build:windows --per_file_copt='external/dawn@-Wno-unknown-argument'
build:windows --host_per_file_copt='external/dawn@-Wno-unknown-argument'
# V8 now requires Windows 10, Bazel fails to set this properly.
build:windows --per_file_copt=external/v8/src/base/platform/platform-win32.cc@-D_WIN32_WINNT=0x0A00
build:windows --host_per_file_copt=external/v8/src/base/platform/platform-win32.cc@-D_WIN32_WINNT=0x0A00
# typescript configuration
# do more correct type checking
common --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
# Use "tsc" as the transpiler when ts_project has no `transpiler` set.
common --@aspect_rules_ts//ts:default_to_tsc_transpiler
# optimized LTO build. you'll need a fairly recent clang for this to work
build:thin-lto -c opt
build:thin-lto --cxxopt='-flto=thin'
build:thin-lto --linkopt='-flto=thin'
# configuration used for performance profiling
build:profile --config=thin-lto
build:profile --copt="-fno-omit-frame-pointer" --copt="-mno-omit-leaf-frame-pointer"
build:profile --config=limited-dbg-info
build:profile --strip=never
# configuration used for performance benchmarking is the same as profiling for consistency
build:benchmark --config=profile
# Define a debug config which is primarily intended for local development.
build:debug -c dbg
# Using simple template names saves around 5% of binary size of workerd.
build:unix --cxxopt='-gsimple-template-names' --host_cxxopt='-gsimple-template-names'
# Enable hidden visibility for inline functions. This can cause problems when comparing pointers to
# inline functions across shared library boundaries, but this is unlikely to be done anywhere
# within workerd, V8 explicitly supports hidden visibility.
build:unix --cxxopt='-fvisibility-inlines-hidden' --host_cxxopt='-fvisibility-inlines-hidden'
# Define a config mode which is fastbuild but with basic debug info.
build:fastdbg -c fastbuild
build:fastdbg --config=limited-dbg-info
build:fastdbg --config=rust-debug
build:fastdbg --strip=never
build:fastdbg --//:dead_strip=False
# provide a limited amount of debug info, sufficient for qualified stack traces.
build:limited-dbg-info --copt='-g1' --copt="-fdebug-info-for-profiling"
# Miscellaneous platform-independent options
build --@capnp-cpp//src/kj:openssl=True --@capnp-cpp//src/kj:zlib=True --@capnp-cpp//src/kj:brotli=True
build --@capnp-cpp//src/capnp:gen_rust=True
build --cxxopt="-fbracket-depth=512" --host_cxxopt="-fbracket-depth=512"
build --@capnp-cpp//src/capnp:gen_rust=True
# Additional Rust flags (see https://doc.rust-lang.org/rustc/codegen-options/index.html)
# Need to disable debug-assertions for fastbuild, should be off automatically for opt. As long as
# rust-level LTO is not enabled, LLVM bitcode is not needed so -C embed-bitcode=n provides a free
# improvement to build speed and Rust code size.
# Using extra_rustc_flag for non-exec flags so they can be overwritten selectively.
build --@rules_rust//:extra_rustc_flag=-Cembed-bitcode=n
build --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=n
build --@rules_rust//:extra_exec_rustc_flags=-C,debug-assertions=n,-C,embed-bitcode=n
# We default to not enabling debug assertions and unwinding for Rust. For debug builds this is not
# the right setting, but unfortunately we can't set that directly.
build:rust-debug --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=y
# Use the equivalent of -g/-g2 for Rust here, this is necessary to get qualified stack traces while
# -Zdebug-info-for-profiling is unavailable. Unlike gcc/clang, Rust defaults to -g3 otherwise.
build:rust-debug --@rules_rust//:extra_rustc_flag=-Cdebuginfo=1
build:rust-debug --@rules_rust//:extra_rustc_flag=-Cstrip=none
# Adding -C lto=thin here would improve binary size significantly – disable it for now due to
# compile errors and wrong code generation when bazel and rust use different LLVM versions.
build:thin-lto --@rules_rust//:extra_rustc_flag=-Ccodegen-units=1
# common sanitizers options
build:sanitizer-common --@workerd//src/workerd/server:use_tcmalloc=False
build:sanitizer-common --copt="-fsanitize-link-c++-runtime" --linkopt="-fsanitize-link-c++-runtime"
build:sanitizer-common --copt="-Og"
build:sanitizer-common --copt="-g" --strip=never
build:sanitizer-common --copt="-fno-optimize-sibling-calls"
build:sanitizer-common --copt="-fno-omit-frame-pointer" --copt="-mno-omit-leaf-frame-pointer"
# address sanitizer (https://github.com/google/sanitizers/wiki/AddressSanitizer)
build:asan --config=sanitizer-common
build:asan --copt="-fsanitize=address" --linkopt="-fsanitize=address"
build:asan --test_env=ASAN_OPTIONS=abort_on_error=true
build:asan --test_env=KJ_CLEAN_SHUTDOWN=1
#
# Linux and macOS
#
build:unix --workspace_status_command=./tools/unix/workspace-status.sh
build:unix --cxxopt='-std=c++20' --host_cxxopt='-std=c++20'
build:unix --@capnp-cpp//src/kj:libdl=True
build:unix --action_env=BAZEL_COMPILER=clang
build:unix --action_env=CC=clang
build:unix --action_env=CXX=clang++
build:unix --test_env=LLVM_SYMBOLIZER=llvm-symbolizer
# Warning options.
build:unix --cxxopt='-Wall' --host_cxxopt='-Wall'
build:unix --cxxopt='-Wextra' --host_cxxopt='-Wextra'
build:unix --cxxopt='-Wunused-function' --host_cxxopt='-Wunused-function'
build:unix --cxxopt='-Wunused-lambda-capture' --host_cxxopt='-Wunused-lambda-capture'
build:unix --cxxopt='-Wunused-variable' --host_cxxopt='-Wunused-variable'
build:unix --cxxopt='-Wno-strict-aliasing' --host_cxxopt='-Wno-strict-aliasing'
build:unix --cxxopt='-Wno-sign-compare' --host_cxxopt='-Wno-sign-compare'
build:unix --cxxopt='-Wno-unused-parameter' --host_cxxopt='-Wno-unused-parameter'
build:unix --cxxopt='-Wno-missing-field-initializers' --host_cxxopt='-Wno-missing-field-initializers'
build:unix --cxxopt='-Wno-ignored-qualifiers' --host_cxxopt='-Wno-ignored-qualifiers'
build:linux --config=unix
build:macos --config=unix
# Support macOS 13 as the minimum version. There should be at least a warning when backward
# compatibility is broken as -Wunguarded-availability-new is enabled by default. Only enable for
# target configuration as host configuration tools are only used during the build process.
build:macos --macos_minimum_os=13.5
# Avoid emitting duplicate unwind info where compact unwind info can be used. This reduces the
# object size by ~5% on average, improving disk space usage and link times. The final binary size
# is not affected. Note that this is on-by-default on arm64, but turning it on for all mac builds
# is easier than adding the flag only on x86. See https://reviews.llvm.org/D122258 for detailed
# information on the flag.
build:macos --copt='-femit-dwarf-unwind=no-compact-unwind'
# Bazel doesn't allow setting flags only for a specific build mode like fastbuild, but somehow has
# a flag that does this for ObjC to set "-O0 -DDEBUG=1". Worse yet, options set by this flag cannot
# be overwritten on the command line, which confusingly makes enabling optimization there not have
# an effect. On macOS we build some ObjC as part of Dawn, set this flag to an empty string so we
# can set the right configuration flags.
# TODO(soon): File a bazel issue for the flag so we can drop this.
build:macos --experimental_objc_fastbuild_options=""
# Cross-Compilation
# Only cross-compiling on macOS from Apple Silicon to x86_64 is supported – using apple_support
# makes this much easier than on other platforms. We could define a configuration for cross-
# compiling from Intel Mac too, but it lacks a means to run Apple Silicon binaries. We would have to
# change V8 mksnapshot to build in the host configuration again (effectively compiling much of V8
# twice) and couldn't run tests, so it would provide little value.
#
# Define the target platform
build:macos-cross-x86_64 --cpu=darwin_x86_64 --host_cpu=darwin_arm64 --platforms //:macOS_x86
# Some cross-compiled tests are slower when run over Rosetta, increase the medium test size timeout.
# Test performance is still very much satisfactory considering that emulation is being used here.
build:macos-cross-x86_64 --test_timeout=1,30,60,240
# On Linux, always link libc++ statically to avoid compatibility issues with different OS versions.
# macOS links with dynamic libc++ by default, which has good backwards compatibility.
# Drop default link flags, which include libstdc++ for Linux
build:linux --features=-default_link_libs --host_features=-default_link_libs
build:linux --cxxopt='-stdlib=libc++' --host_cxxopt='-stdlib=libc++'
build:linux --linkopt='-stdlib=libc++' --host_linkopt='-stdlib=libc++'
build:linux --linkopt='-l:libc++.a' --linkopt='-lm' --linkopt='-static-libgcc'
# We don't expect to distribute host tools, no need to statically link libgcc.
# TODO(cleanup): Ideally we'd also use shared libc++ here, we'd just need to install the
# libunwind-15-dev and libc++abi-15-dev packages on CI to have all of shared libc++ available.
build:linux --host_linkopt='-l:libc++.a' --host_linkopt='-lm'
# On Linux, enable PIC. In macos pic is the default, and the objc_library rule does not work
# correctly if we use this flag since it will not find the object files to include
# https://github.com/bazelbuild/bazel/issues/12439#issuecomment-914449079
build:linux --force_pic
# On Linux, garbage collection sections and optimize binary size. These do not apply to the macOS
# toolchain.
build:linux --linkopt="-Wl,--gc-sections"
build:linux --copt="-ffunction-sections" --host_copt="-ffunction-sections"
build:linux --copt="-fdata-sections" --host_copt="-fdata-sections"
# On Linux, use clang lld.
build:linux --linkopt="-fuse-ld=lld"
#
# Windows
#
# See https://bazel.build/configure/windows#symlink
startup --windows_enable_symlinks
build:windows --workspace_status_command=./tools/windows/workspace-status.cmd
build:windows --enable_runfiles
# We use LLVM's MSVC-compatible compiler driver to compile our code on Windows,
# as opposed to using MSVC directly. This enables us to use the "same" compiler
# frontend on Linux, macOS, and Windows, massively reducing the effort required
# to compile workerd on Windows. Notably, this provides proper support for
# `#pragma once` when using symlinked virtual includes, `__atomic_*` functions,
# a standards-compliant preprocessor, support for GNU statement expressions
# used by some KJ macros, and understands the `.c++` extension by default.
# As of bazel 7, incompatible_enable_cc_toolchain_resolution is enabled by default, so we need to
# define a platform for the clang-cl build.
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl
build:windows --extra_execution_platforms=//:x64_windows-clang-cl
# The Windows fastbuild bazel configuration is broken in that it necessarily generates PDB debug
# information while the Linux and macOS toolchains only compile with debug information in the dbg
# configuration or when requested with the -g flag. This causes huge increases in compile time and
# disk/cache space usage – a single test may come with a 490MB PDB file.
# In an optional configuration, use the opt configuration and manually disable optimizations as a
# workaround.
build:windows_no_dbg -c opt
build:windows_no_dbg --copt='-O0'
build:windows_no_dbg --copt='/Od'
build:windows_no_dbg --linkopt='/INCREMENTAL:NO'
build:windows_no_dbg --features=-smaller_binary
# Mitigate the large size impact of Windows debug binaries somewhat by applying string merging and
# linker garbage collection.
build:windows_dbg --config=debug
build:windows_dbg --copt='/Gy' --copt='/Gw'
build:windows_dbg --linkopt='/OPT:REF'
build:windows_dbg --linkopt='/OPT:LLDTAILMERGE' --linkopt='/OPT:SAFEICF'
# This hides inline symbols in classes that are marked to be exported, similar to
# -fvisibility-inlines-hidden on Unix systems (https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html)
# Currently this only reduces object sizes slightly, larger gains are possible if we compile V8 as
# a shared library.
build:windows --copt='/Zc:dllexportInlines-'
# Release configuration.
build:release -c opt
build:release --@rules_rust//:extra_rustc_flag=-Ccodegen-units=1
# enable -O3 for the release configuration. Based on benchmarking there is little difference in
# performance, but -O3 should generally be expected to be faster for at least parts of the workerd API.
build:release_unix --copt='-O3'
build:release_unix --config=release
build:release_linux --config=release_unix
build:release_linux --linkopt="-Wl,-O2"
build:release_macos --config=release_unix
# Disable generating LC_DATA_IN_CODE and LC_FUNCTION_STARTS binary sections, two rarely used types
# of macOS debug info. These sections are largely undocumented, but are used by LLDB to improve
# debugging on binaries that are otherwise stripped. There should be no need to include this
# data in releases.
build:release_macos --linkopt="-Wl,-no_data_in_code_info"
build:release_macos --linkopt="-Wl,-no_function_starts"
# Cross-compiled release build for x86_64.
build:release_macos_cross_x86_64 --config=release_macos
build:release_macos_cross_x86_64 --config=macos-cross-x86_64
# On macOS, optionally compile using LLD (19 or higher is compatible with the default flags added by
# apple_support). Requires Homebrew's lld package to be installed and symlinked into /usr/local/bin.
# This is less CPU intensive than the system linker, but also slightly slower in terms of wall time
# since it is less parallel. More importantly, it allows us to enable LLD's ICF pass, which
# significantly decreases binary sizes. We could use Xcode 16's -Wl,-deduplicate option instead, but
# LLD's ICF appears to be superior. We also want to enable ICF for Linux, but there it causes
# warnings when dynamically linking with libc++.
build:macos_lld --linkopt=-fuse-ld=lld --linkopt=--ld-path=/usr/local/bin/ld64.lld
build:macos_lld_icf --config=macos_lld
build:macos_lld_icf --linkopt="-Wl,--icf=safe"
build:release_windows --config=release
# Windows uses /O2 as its preferred optimization setting and enabled by bazel in the opt
# configuration, but for clang-cl this is equivalent to only -O2 and a few other things. -O3 is
# not exposed directly in the clang-cl driver, but we can access regular clang
# flags using the /clang prefix anyway. https://clang.llvm.org/docs/UsersManual.html#the-clang-option
build:release_windows --copt="/clang:-O3"
# clang-cl does not enable strict aliasing by default to match MSVC's approach, unlike clang on
# Unix which turns it on for opt builds.
build:release_windows --copt="-fstrict-aliasing"
build:windows --cxxopt='/std:c++20' --host_cxxopt='/std:c++20'
build:windows --copt='/D_CRT_USE_BUILTIN_OFFSETOF' --host_copt='/D_CRT_USE_BUILTIN_OFFSETOF'
build:windows --copt='/DWIN32_LEAN_AND_MEAN' --host_copt='/DWIN32_LEAN_AND_MEAN'
# The `/std:c++20` argument is unused during boringssl compilation and we don't
# want a warning when compiling each file.
build:windows --copt='-Wno-unused-command-line-argument' --host_copt='-Wno-unused-command-line-argument'
# MSVC disappointingly sets __cplusplus to 199711L by default. Defining /Zc:__cplusplus makes it
# set the correct value. We currently don't check __cplusplus, but some dependencies do.
build:windows --cxxopt='/Zc:__cplusplus' --host_cxxopt='/Zc:__cplusplus'
# enable clang coverage: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
build:clang-coverage --copt="-fprofile-instr-generate" --linkopt="-fprofile-instr-generate"
build:clang-coverage --copt="-fcoverage-mapping" --linkopt="-fcoverage-mapping"