# Enables picking up host-OS specific config, i.e. adds support for the following: # `build:[ linux | macos | windows | freebsd | openbsd ]` common --enable_platform_specific_config # TODO(parkmycar): Migrate to Bzlmod. # # Note: We are not yet using Bzlmod because there are parts of the ecosystem # that haven't yet migrated to it. common --noenable_bzlmod # Required for remote caching to be effective. # # Otherwise Bazel will passthrough the current system's PATH in the execution # environment, which differs between systems and thus breaks remote caching. build --incompatible_strict_action_env # Prevent actions in the sandbox from accessing the network. # # TODO(parkmycar): `prof-http`s build script downloads resources from npm. #build --sandbox_default_allow_network=false # Bazel provides the macOS 14.5 SDK as the sysroot, we also set the minimum # version to prevent breaking the remote cache across developer machines. common --copt=-mmacosx-version-min=14.0 common --linkopt=-mmacosx-version-min=14.0 common --macos_sdk_version=14.0 # Note(parkmycar): Ideally we would error on unused command line arguments, but # trying to constrain the above arguments to just macos doesn't seem to work. common --copt=-Wno-unused-command-line-argument common --linkopt=-Wno-unused-command-line-argument # Always build position independent C code. common --copt=-fPIC # Config for building protobuf. build --copt=-Wno-error=deprecated-declarations # Required to stamp our development builds with the current git hash. # # This script gets run before every build, see the script for more info. build:release-stamp --stamp --workspace_status_command "python3 misc/bazel/build-info/workspace_status.py" # Output all test output by default, this makes it most like cargo. # # Note: We used to have 'stream' here, but that forces Bazel to serialize test execution. build --test_output=all # Environment variables to pass through to the test runner. These can impact # remote cache hits, so add them sparingly. # # TODO(parkmycar): Switch over to using `env_inherit` on `rust_test` once that's stable. # build --test_env=COCKROACH_URL # Allows spaces to in filenames, without this Rust Doc tests fail to build. build:macos --experimental_inprocess_symlink_creation # Tracks stashed sandboxes in-memory so it uses less I/O on reuse. # # Bazel's sandbox performance on macOS doesn't scale very well, see: build --experimental_inmemory_sandbox_stashes # Don't build runfile symlink forests, unless required. build --nobuild_runfile_links # Always have Bazel output why it rebuilt something, should make debugging builds easier. # # TODO(parkmycar): Enable this under a "debug" or "verbose" # common --explain=bazel-explain.log # common --verbose_explanations # Compress any artifacts larger than 2MiB with zstd. # # Note(parkmycar): These thresholds were chosen arbitrarily. You should feel # free to change them if you encounter issues. common --remote_cache_compression common --experimental_remote_cache_compression_threshold=2097152 # Memoizes merkle tree calculations to improve the remote cache hit checking speed. common --experimental_remote_merkle_tree_cache # Number of merkle trees to memoize (default 1000). common --experimental_remote_merkle_tree_cache_size=5000 # Don't make the user wait for uploading artifacts to complete, finish it in the background. common --bes_upload_mode=fully_async # Make sure any local disk cache stays within a reasonable size. common --experimental_disk_cache_gc_max_size=80G common --experimental_disk_cache_gc_max_age=14d # Tells `xz` to use all available cores. action_env=XZ_OPT=-T0 # # Config when running Bazel from a script. # # Silence most UI output since it's noisy. run:script --ui_event_filters=-info,-stdout,-stderr --noshow_progress # LLVM's libc++ has different assertion modes which can be configured to catch # undefined behavior. See: build:debug --cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" build:debug --host_cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" build:debug --@rules_rust//:extra_rustc_flag="-Csplit-debuginfo=unpacked" # # Debug Info Configuration # # TODO(parkmycar): Enable this for macOS. `toolchains_llvm` defaults to ld64 which # doesn't support zlib compression. build:linux --linkopt="-Wl,--compress-debug-sections=zlib" build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,--compress-debug-sections=zlib" # Specifying "-O2" uses level 6 zlib compression. build:linux --linkopt="-Wl,-O2" build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,-O2" build:linux --copt="-gz=zlib" # Match the DWARF version used by Rust. # # Note(parkmycar): This might not be necessary but seemed nice to do. # # See: build:linux --copt="-gdwarf-4" build:linux --linkopt="-gdwarf-4" build:macos --copt="-gdwarf-2" build:macos --linkopt="-gdwarf-2" # Emit full debug info, allowing us to easily analyze core dumps from staging # (and, in an emergency, also prod). build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cdebuginfo=2 build:debuginfo-full --copt=-g2 build:debuginfo-full --strip=never build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cstrip=none build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cdebuginfo=1 build:debuginfo-limited --copt=-g1 build:debuginfo-limited --strip=never build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cstrip=none build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cdebuginfo=0 build:debuginfo-none --copt=-g0 build:debuginfo-none --strip=always build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cstrip=symbols # # Common Build Configuration # build --linkopt="-fuse-ld=lld" build --@rules_rust//:extra_rustc_flag="-Clink-arg=-fuse-ld=lld" build --@rules_rust//:extra_rustc_flag="-Csymbol-mangling-version=v0" # We use 64 because it's enough to totally saturate a CI builder so our builds # are as fast as possible, and it's less than the default of 256 used with # Cargo when incremental compilation is enabled. build --@rules_rust//:extra_rustc_flag="-Ccodegen-units=64" # Enabling pipelined builds allows dependent libraries to begin compiling with # just `.rmeta` instead of the full `.rlib`. This is what Cargo does and offers # a significant speedup in end-to-end build times! build --@rules_rust//rust/settings:pipelined_compilation=True # `cargo check` like config, still experimental! # # Ignores all outputs other than `.rmeta`, requires pipelied_compilation to be enabled! build:check --output_groups=build_metadata # CI Build Configuration # # Note: This shouldn't change any config of the built binary, just the way it # gets built. # # Always enable verbose failures in CI, makes it easier to debug failures. build:ci --verbose_failures # `/dev/shm` is a RAM backed temporary filesystem, it should speedup sandbox creation. build:in-mem-sandbox --sandbox_base=/dev/shm # Release Build Configuration # build:release --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST build:release --copt=-O3 build:release --copt=-DNDEBUG build:release --compilation_mode=opt # We only enable Link Time Optimization for CI builds and not local release builds. build:release-lto --copt=-flto=thin build:release-lto --linkopt=-flto=thin build:release-lto --@rules_rust//rust/settings:lto=thin build:release-lto --@//misc/bazel/platforms:xlang_lto=True # Builds from `main` or tagged builds. # # Note: We don't use a ramdisk for tagged builds because the full debuginfo is # too large and we OOD/OOM. build:release-tagged --config=release --config=release-lto --config=release-stamp --config=debuginfo-full # PRs in CI. # # Not doing a full stamp nor omitting full debug info, greatly speeds up compile times. build:release-dev --config=release --config=optimized --config=debuginfo-limited # "Optimized" Build. # # Provides both reasonably fast compile times and runtimes. build:optimized --compilation_mode=opt build:optimized --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST build:optimized --copt=-O2 build:optimized --copt=-DNDEBUG build:optimized --config=debuginfo-none build:optimized --copt=-fno-lto build:optimized --linkopt=-fno-lto build:optimized --@rules_rust//rust/settings:lto=off # Build with the Rust Nightly Toolchain build:rust-nightly --@rules_rust//rust/toolchain/channel=nightly # AddressSanitizer # # Only works on Linux and does not support cross compiling. # # TODO: To support cross compiling sanitized builds we most likely need to move # our compiler runtime libraries (e.g. libc++, libunwind, asan) from our # toolchain into our system root, and then also specify `-resource-dir` to tell # `clang` to search for these libraries in the system root. # # See: # build:asan --config=rust-nightly build:asan --@rules_rust//:extra_rustc_flag=-Zsanitizer=address --@rules_rust//:extra_rustc_flag=-Zexternal-clangrt build:asan --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=on build:asan --@rules_rust//:extra_rustc_flag=-Cllvm-args=-asan-use-after-scope build:asan --@rules_rust//:extra_rustc_flag=-Cllvm-args=-asan-use-after-return=always build:asan --copt=-fsanitize=address build:asan --copt=-fno-omit-frame-pointer build:asan --copt=-g build:asan --copt=-O1 build:asan --linkopt=-fsanitize=address build:asan --strip=never build:asan --@//misc/bazel/platforms:sanitizer="address" build:asan --action_env=ASAN_OPTIONS=verbosity=1 # HACK(parkmycar): We want to tell Rust to use the Bazel provided `clang++` but there isn't # a great way to do that. We know this is where `clang++` lives though, so it works. build:asan --@rules_rust//:extra_rustc_flag=-Clinker=external/llvm_toolchain_llvm/bin/clang++ # Hardware Assisted AddressSanitizer # # Only works on `aarch64-linux-unknown-gnu` and does not support cross compiling. # # See: # build:hwasan --config=rust-nightly build:hwasan --@rules_rust//:extra_rustc_flag=-Zsanitizer=hwaddress --@rules_rust//:extra_rustc_flag=-Zexternal-clangrt build:hwasan --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=on build:hwasan --@rules_rust//:extra_rustc_flag=-Ctarget-feature=+tagged-globals build:hwasan --copt=-fsanitize=hwaddress build:hwasan --copt=-fno-omit-frame-pointer build:hwasan --copt=-g build:hwasan --copt=-O1 build:hwasan --linkopt=-fsanitize=hwaddress build:hwasan --strip=never build:hwasan --@//misc/bazel/platforms:sanitizer="hwaddress" build:hwasan --action_env=ASAN_OPTIONS=verbosity=1 # HACK(parkmycar): We want to tell Rust to use the Bazel provided `clang++` but there isn't # a great way to do that. We know this is where `clang++` lives though, so it works. build:hwasan --@rules_rust//:extra_rustc_flag=-Clinker=external/llvm_toolchain_llvm/bin/clang++