-
Notifications
You must be signed in to change notification settings - Fork 620
Expand file tree
/
Copy path.bazelrc
More file actions
496 lines (428 loc) · 28 KB
/
.bazelrc
File metadata and controls
496 lines (428 loc) · 28 KB
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
common --enable_platform_specific_config
build --verbose_failures
build --build_tag_filters=-off-by-default,-requires-container-engine
# block network access by default
build --nosandbox_default_allow_network
test --test_tag_filters=-off-by-default,-requires-fuzzilli,-requires-container-engine
test:asan --test_tag_filters=-off-by-default,-no-asan,-requires-fuzzilli,-requires-container-engine
# 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=3,15,60,240
# As part of starlarkification, Bazel 8 and 9 remove a number of rules which now need to be imported
# from other repositories. In the long term, load() statements will be needed to import these rules.
# For now, we can still autoload the affected repositories when needed. Do this only for a remaining
# protobuf component and rules_cc (needed with Bazel 9).
# cc_test is only included because of highway; remove once they include cc_test properly.
common --incompatible_autoload_externally="+ProtoInfo,+cc_binary,+cc_library,+cc_test"
# TODO(cleanup): Bazel 9 sets this by default, which breaks the macOS-cross build. Fix and re-enable.
common --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False
# Enable proto toolchain resolution to use prebuilt protoc (starting with protobuf v34.0). Will be
# the default starting with Bazel 10.
common --incompatible_enable_proto_toolchain_resolution
# 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.
# 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.
# 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/rust_lint.bazelrc
import %workspace%/build/tools/clang_tidy/clang_tidy.bazelrc
# Continue building locally when remote cache entries fail to materialize
build --incompatible_remote_local_fallback_for_remote_cache
# Use -isystem for cc_library includes attribute – this prevents warnings for misbehaving external
# code.
build:linux --features=external_include_paths --host_features=external_include_paths
# Forward compatibility with future Bazel versions:
# Disable deprecated cfg = "host" Bazel rule setting. Blocked on perfetto.
# common --incompatible_disable_starlark_host_transitions
# Our dependencies (ICU, zlib, etc.) produce a lot of these warnings, so we disable them.
build --per_file_copt='external@-Wno-error'
build --per_file_copt='external@-Wno-suggest-override'
build --per_file_copt='external/.*v8@-Wno-unused-function'
build --per_file_copt='external/zlib@-Wno-deprecated-non-prototype'
build --host_per_file_copt='external/zlib@-Wno-deprecated-non-prototype'
build --per_file_copt=external/protobuf@-Wno-deprecated-declarations
build --host_per_file_copt=external/protobuf@-Wno-deprecated-declarations
# opt in to capnp deprecation warnings about trying to attach to a refcounted object
build --cxxopt=-DKJ_WARN_REFCOUNTED_ATTACH=1
# TODO(cleanup): Causes warnings with LLVM20, fix and enable again
build --copt=-Wno-nontrivial-memaccess
# Unconditionally optimize V8 heap.cc on macOS – when optimization or inlining are disabled, this
# file appears to cause segfaults at workerd startup on macOS.
# TODO(cleanup): Investigate why this happens, our patches do not modify heap.cc itself so the bug
# might be introduced through a header included in heap.cc, through the Bazel build configuration or
# a bug in Apple LLVM.
build:macos --per_file_copt=v8/src/heap/heap.cc@-O3
# The macOS apple_support toolchain sets -DDEBUG for fastbuild, unlike the Linux toolchain. This is
# unhelpful for compile speeds and test performance, and may cause compile errors based on V8 DCHECK
# macros that reference symbols only available with V8_VERIFY_WRITE_BARRIERS (a debug-only define),
# causing compile errors. Undefine DEBUG to match Linux behavior.
build:macos --copt=-UDEBUG
# Increasing the optimization level of V8 significantly speeds up tests using V8 a lot, especially
# python tests. This is useful for both CI and local development and enabled by default, but still
# kept in a separate configuration to make it easy to disable.
build:v8-codegen-opt --per_file_copt=v8/src@-O3
# V8 is heavily using absl for hashing now, optimize it too.
build:v8-codegen-opt --per_file_copt=external/abseil-cpp@-O3
# zlib and tcmalloc (for Linux) are also CPU-intensive, optimize them too.
build:v8-codegen-opt --per_file_copt=external/tcmalloc@-O3
build:v8-codegen-opt --per_file_copt=external/zlib@-O3
# BoringSSL is CPU-intensive for crypto tests, optimize it too.
build:v8-codegen-opt --per_file_copt=external/boringssl@-O3
# simdutf is used for fast string encoding/decoding
build:v8-codegen-opt --per_file_copt=external/+http+simdutf@-O3
# ICU and perfetto are generally updated with V8 and rarely need to be updated, optimize them too.
build:v8-codegen-opt --per_file_copt=external/.*com_googlesource_chromium_icu@-O3
build:v8-codegen-opt --per_file_copt=external/perfetto@-O3
build:v8-codegen-opt-windows --per_file_copt=v8/src@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/abseil-cpp@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/zlib@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/boringssl@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/+http+simdutf@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/.*com_googlesource_chromium_icu@/O2,/clang:-O3
build:v8-codegen-opt-windows --per_file_copt=external/perfetto@/O2,/clang:-O3
build:unix --config=v8-codegen-opt
build:windows --config=v8-codegen-opt-windows
# In Google projects, exceptions are not used as a rule. Disabling them is more consistent with the
# canonical V8 build and improves code size. Paths are adjusted for bzlmod mangling – V8 and ICU use
# a wildcard for this as the prefix is some variation of +_repo_rules3+ where the number can change
# when refactoring MODULE.bazel – setting this directly would be too brittle
build:unix --per_file_copt=external/abseil-cpp@-fno-exceptions
build:unix --per_file_copt=external/protobuf@-fno-exceptions
build:unix --per_file_copt=external/tcmalloc@-fno-exceptions
build:unix --per_file_copt=external/.*com_googlesource_chromium_icu@-fno-exceptions
build:unix --per_file_copt=external/perfetto@-fno-exceptions
build:unix --per_file_copt=external/boringssl@-fno-exceptions
build:unix --per_file_copt=external/.*v8@-fno-exceptions
build:unix --per_file_copt=external/ada-url@-fno-exceptions
build:unix --per_file_copt=external/+http+simdutf@-fno-exceptions
build:windows --per_file_copt=external/abseil-cpp@/clang:-fno-exceptions
build:windows --per_file_copt=external/protobuf@/clang:-fno-exceptions
build:windows --per_file_copt=external/tcmalloc@/clang:-fno-exceptions
build:windows --per_file_copt=external/.*com_googlesource_chromium_icu@/clang:-fno-exceptions
build:windows --per_file_copt=external/perfetto@/clang:-fno-exceptions
build:windows --per_file_copt=external/boringssl@/clang:-fno-exceptions
build:windows --per_file_copt=external/.*v8@/clang:-fno-exceptions
build:windows --per_file_copt=external/ada-url@/clang:-fno-exceptions
build:windows --per_file_copt=external/+http+simdutf@/clang:-fno-exceptions
# V8 torque is an exception from this policy, see v8 BUILD.gn.
build:unix --per_file_copt=external/.*v8/src/torque@-fexceptions
build:windows --per_file_copt=external/.*v8/src/torque@/clang:-fexceptions
# 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'
# 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.
build:thin-lto --config=opt
build:thin-lto --copt='-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
# always have KJ_IREQUIRE checks enabled, this matches workers production.
build --@capnp-cpp//src/kj:kj_enable_irequire=True
# overriden in config=opt
build --@capnp-cpp//src/kj:debug_memory=True
build --cxxopt="-fbracket-depth=512" --host_cxxopt="-fbracket-depth=512"
# 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.
# Using extra_rustc_flag for non-exec flags so they can be overwritten selectively.
build --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=n
build --@rules_rust//:extra_exec_rustc_flags=-Cdebug-assertions=n
build --@rules_rust//:rustfmt.toml=//src/rust:rustfmt.toml
# 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
# Enable ASan, LSan support in V8
build:asan --copt="-DV8_USE_ADDRESS_SANITIZER"
build:asan --per_file_copt='external/.*v8@-DADDRESS_SANITIZER,-DLEAK_SANITIZER'
# fuzzilli (https://github.com/googleprojectzero/fuzzilli/)
build:fuzzilli --config=asan
build:fuzzilli --copt="-DWORKERD_FUZZILLI"
build:fuzzilli --linkopt="-DWORKERD_FUZZILLI"
build:fuzzilli --copt="-fsanitize-coverage=trace-pc-guard"
build:fuzzilli --linkopt="-fsanitize-coverage=trace-pc-guard"
build:fuzzilli --linkopt="-static-libasan"
# Set ASan/UBSan options globally to abort on error (raise SIGABRT) for proper Fuzzilli crash detection
build:fuzzilli --action_env=ASAN_OPTIONS=abort_on_error=1:symbolize=false
build:fuzzilli --action_env=UBSAN_OPTIONS=abort_on_error=1:symbolize=false
# Override test filters to include requires-fuzzilli tests (inherits asan's -no-asan filter)
test:fuzzilli --test_tag_filters=-off-by-default
#
# Linux and macOS
#
build:unix --workspace_status_command=./tools/unix/workspace-status.sh
build:unix --cxxopt='-std=c++23' --host_cxxopt='-std=c++23'
build:unix --@capnp-cpp//src/kj:libdl=True
# Bazel uses CC to compile C and C++ actions, no need to define CXX.
build:unix --repo_env=BAZEL_COMPILER=clang
build:unix --repo_env=CC=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-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='-Wsuggest-override'
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'
# 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-<version>-dev and libc++abi-<version>-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, 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='/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-'
# Configuration for header parsing. Requires bazel toolchain support (available for macOS, Linux).
build:parse_headers --features=parse_headers --process_headers_in_dependencies
# Silence some capnproto warnings/errors that are not relevant for header parsing
build:parse_headers --per_file_copt='.*\.h@-Wno-unused-function,-Wno-pragma-system-header-outside-header'
build:parse_headers --per_file_copt=external/+http+capnp-cpp/src/kj/common.h@-Wno-unreachable-code
build:parse_headers --per_file_copt=external/+http+capnp-cpp/src/capnp/arena.h@-DCAPNP_PRIVATE
# optimized configuration
build:opt -c opt
build:opt --@capnp-cpp//src/kj:debug_memory=False
# Release configuration.
build:release --config=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"
# TODO(soon): Investigate these issues on an actual Windows system.
# Compiling these files causes clang-cl 20 to crash on Windows release builds, work around this by
# disabling inlining (using /Od would work too but we still want to have whatever optimizations we
# can have)
build:release_windows --per_file_copt="src/workerd/server/server"@/clang:-fno-inline
build:release_windows --per_file_copt="src/workerd/server/container-client"@/clang:-fno-inline
# Work around Windows test failures in rpc-related tests
build:release_windows --per_file_copt=src/workerd/io/worker-interface@/clang:-fno-inline
build:windows --cxxopt='/std:c++23preview' --host_cxxopt='/std:c++23preview'
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'
build:windows --copt='/EHs' --host_copt='/EHs'
# The `/std:c++23preview` argument is unused during BoringSSL compilation and we don't
# want a warning when compiling each file.
build:windows --per_file_copt=external/boringssl@-Wno-unused-command-line-argument --host_per_file_copt=external/boringssl@-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'
# Coverage configuration using LLVM tools. These environment variables are used by rules_cc
# to locate LLVM coverage tools. Users should ensure llvm-profdata and llvm-cov are available
# in PATH (create symlinks to version-specific binaries if needed, e.g., ln -s llvm-cov-19 llvm-cov).
build:coverage --repo_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1
# GCOV is used by rules_cc to merge raw profile data (.profraw) into indexed profile data (.profdata)
build:coverage --repo_env=GCOV=llvm-profdata
# COVERAGE_GCOV_PATH is used by collect_cc_coverage.sh for merging .profraw files.
build:coverage --repo_env=COVERAGE_GCOV_PATH=/usr/bin/llvm-profdata
# BAZEL_LLVM_COV is used by collect_cc_coverage.sh to generate LCOV reports from profile data
build:coverage --repo_env=BAZEL_LLVM_COV=llvm-cov
build:coverage --experimental_use_llvm_covmap
# experimental_generate_llvm_lcov tells collect_cc_coverage to use llvm-cov export to generate LCOV
# format instead of just outputting raw profdata. LLVM_COV specifies the llvm-cov binary to use.
build:coverage --experimental_generate_llvm_lcov
# Ensure that we fetch coverage data from remote cache
build:coverage --experimental_fetch_all_coverage_outputs
build:coverage --experimental_split_coverage_postprocessing
# Allow coverage outputs to be writable for post-processing
build:coverage --experimental_writable_outputs
build:coverage --collect_code_coverage
# Only instrument source code, not tests or tools - significantly speeds up coverage builds
build:coverage --instrumentation_filter="^//src/workerd[/:],^//src/rust[/:]"
build:coverage --instrument_test_targets
# Disable coverage instrumentation for external dependencies to speed up compilation.
# Coverage for V8/external code is not useful for our purposes.
# These flags negate -fprofile-instr-generate and -fcoverage-mapping set by rules_cc.
build:coverage --per_file_copt=external/.*@-fno-profile-instr-generate,-fno-coverage-mapping
# KJ uses _exit() by default which bypasses atexit handlers and prevents LLVM profile runtime
# from writing coverage data. KJ_CLEAN_SHUTDOWN forces use of normal exit() instead.
build:coverage --test_env=KJ_CLEAN_SHUTDOWN=1
# Use -O1 for faster compilation - coverage builds don't need heavy optimization
build:coverage --copt=-O1
# Reduce debug info for faster compilation and smaller binaries
build:coverage --copt=-g1
# Use limited coverage mode for smaller binaries and faster execution (used by Chromium)
build:coverage --copt=-mllvm --copt=-limited-coverage-experimental=true
coverage --test_tag_filters=-off-by-default,-requires-fuzzilli,-requires-container-engine,-lint,-benchmark,-workerd-benchmark,-no-coverage
# Coverage instrumentation slows down test execution, so extend timeouts
# We disable enormous tests due to the slowdown (CI jobs have a 6h max duration)
coverage --test_size_filters=-enormous
coverage --test_timeout=240,240,240,240
coverage --build_tests_only
# This config is defined internally and enabled on many machines.
# Defining it as empty just so these machines can run build commands from the workerd repo
build:rosetta-arm64 --define=rosetta_arm64_no_op=1