forked from cloudflare/workerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bazelrc
235 lines (195 loc) · 12.7 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
common --enable_platform_specific_config
build --verbose_failures
build --build_tag_filters=-off-by-default
test --test_tag_filters=-off-by-default
# Not using bzlmod for dependencies yet
common --noenable_bzlmod
# TODO(soon): bazel7 enables Build without the Bytes (BwoB) by default. This could significantly
# speed up builds using the remote cache since less data needs to be fetched. Unfortunately, it
# appears to cause build failures due to https://github.com/bazelbuild/bazel/issues/20559 at this
# time. Use --remote_download_all to disable BwoB for now.
# When that issue and https://github.com/bazelbuild/bazel/issues/20576 have been addressed, we can
# also explore --remote_download_minimal.
build --remote_download_all
# Enable webgpu
build --//src/workerd/io:enable_experimental_webgpu=True
# 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/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'
build --host_per_file_copt='external/dawn@-Wno-shorten-64-to-32,-Wno-unneeded-internal-declaration'
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
# Enable C++20 to support std::unordered_map::contains(). Not sure why this is needed here, V8
# is supposed to work with C++14.
build:unix --per_file_copt='external/v8/src/compiler/graph-visualizer.cc@-std=c++20'
build:windows --per_file_copt='external/v8/src/compiler/graph-visualizer.cc@/std:c++20'
# Need to redefine _WIN32_WINNT to build dawn on Windows
build:windows --per_file_copt='external/dawn@-Wno-macro-redefined'
build:windows --host_per_file_copt='external/dawn@-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. 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 --copt='-g1' --linkopt='-g1' --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'
# Define a config mode which is fastbuild but with basic debug info.
build:fastdbg -c fastbuild
build:fastdbg --cxxopt='-g1' --host_cxxopt='-g1'
build:fastdbg --linkopt='-g1' --host_linkopt='-g1'
build:fastdbg --strip=never
build:fastdbg --//:dead_strip=False
# Miscellaneous platform-independent options
build --@capnp-cpp//src/kj:openssl=True --@capnp-cpp//src/kj:zlib=True --@capnp-cpp//src/kj:brotli=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. 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-deps code size.
build --@rules_rust//:extra_rustc_flags=-C,panic=abort,-C,debug-assertions=n,-C,embed-bitcode=n
build --@rules_rust//:extra_exec_rustc_flags=-C,panic=abort,-C,debug-assertions=n,-C,embed-bitcode=n
build:fastdbg --@rules_rust//:extra_rustc_flags=-C,panic=unwind,-C,debug-assertions=y,-C,debuginfo=1,-C,embed-bitcode=n
build:fastdbg --@rules_rust//:extra_exec_rustc_flags=-C,panic=unwind,-C,debug-assertions=y,-C,debuginfo=1,-C,embed-bitcode=n
# TODO(later): -C codegen-units=1 improves code size and quality, should be enabled in a future
# release configuration even if lto is off. Similarly, adding -C lto=thin 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_flags=-C,panic=abort,-C,codegen-units=1,-C,embed-bitcode=n
# 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
#
# 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 11 as the minimum version. There should be at least a warning when backward
# compatibility is broken as -Wunguarded-availability-new is enabled by default.
# TODO (cleanup): macOS 11.X is now EOL, bump this to macOS 12.5 soon.
build:macos --macos_minimum_os=11.5 --host_macos_minimum_os=11.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'
# 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.
build:linux --cxxopt='-stdlib=libc++' --host_cxxopt='-stdlib=libc++'
build:linux --linkopt='-stdlib=libc++' --host_linkopt='-stdlib=libc++'
build:linux --action_env=BAZEL_LINKLIBS='-l%:libc++.a -lm -static-libgcc'
# 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" --linkopt="-Wl,-O2"
build:linux --cxxopt="-ffunction-sections" --host_cxxopt="-ffunction-sections"
build:linux --cxxopt="-fdata-sections" --host_cxxopt="-fdata-sections"
# TODO(later): rustc's -C,codegen-units=1 and ld/lld's -Wl,-O2 on Linux/possibly Windows should
# bring an additional binary size improvement. These should only be enabled in opt mode which won't
# be possible in bazelrc without establishing a release configuration, but it can be done using the
# extra_rustc_flags parameter in rust_register_toolchains() and by modifying linkopts in kj_test()
# and wd_cc_binary() similar to how the use_dead_strip flag is used. The binary size improvement is
# modest (~ 300kb), but if we encounter size concerns again this would be a good place to start.
#
# 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' --host_copt='-O0'
build:windows_no_dbg --copt='/Od' --host_copt='/Od'
build:windows_no_dbg --copt='/INCREMENTAL:NO' --host_copt='/INCREMENTAL:NO'
build:windows_no_dbg --features=-smaller_binary --features=-disable_assertions_feature
# 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' --copt='/GF'
build:windows_dbg --linkopt='/OPT:REF'
build:windows --cxxopt='/std:c++20' --host_cxxopt='/std:c++20'
build:windows --cxxopt='/await' --host_cxxopt='/await'
build:windows --copt='/D_CRT_USE_BUILTIN_OFFSETOF' --host_copt='/D_CRT_USE_BUILTIN_OFFSETOF'
build:windows --copt='/DWINDOWS_LEAN_AND_MEAN' --host_copt='/DWINDOWS_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"