forked from cloudflare/workerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bazelrc
196 lines (159 loc) · 10.6 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
common --enable_platform_specific_config
build --verbose_failures
build --build_tag_filters=-off-by-default
# Enable webgpu
build --//src/workerd/io:enable_experimental_webgpu=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'
# 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'
# Speed up sandboxed compilation, particularly on I/O-constrained and non-Linux systems
# https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories
build --reuse_sandbox_directories
# 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='-gline-tables-only' --linkopt='-gline-tables-only' --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='-gline-tables-only' --host_cxxopt='-gline-tables-only'
build:fastdbg --linkopt='-gline-tables-only' --host_linkopt='-gline-tables-only'
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"
# Disable the new Maybe deprecations until we have converted more of the codebase.
build --@capnp-cpp//src/kj:deprecate_kj_if_maybe=False
build --@capnp-cpp//src/kj:deprecate_empty_maybe_from_nullptr=False
# 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 --cxxopt='-stdlib=libc++' --host_cxxopt='-stdlib=libc++'
build:unix --linkopt='-stdlib=libc++' --host_linkopt='-stdlib=libc++'
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.
build:macos --macos_minimum_os=11.0 --host_macos_minimum_os=11.0
# On Linux, always link libc++ statically to avoid compatibility issues with different OS versions.
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.
build:windows --compiler=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 --noincompatible_use_host_features
build:windows_no_dbg --features=-smaller_binary --features=-disable_assertions_feature
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"