.bazelrc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. # Enables picking up host-OS specific config, i.e. adds support for the following:
  2. # `build:[ linux | macos | windows | freebsd | openbsd ]`
  3. common --enable_platform_specific_config
  4. # TODO(parkmycar): Migrate to Bzlmod.
  5. #
  6. # Note: We are not yet using Bzlmod because there are parts of the ecosystem
  7. # that haven't yet migrated to it.
  8. common --noenable_bzlmod
  9. # Required for remote caching to be effective.
  10. #
  11. # Otherwise Bazel will passthrough the current system's PATH in the execution
  12. # environment, which differs between systems and thus breaks remote caching.
  13. build --incompatible_strict_action_env
  14. # Prevent actions in the sandbox from accessing the network.
  15. #
  16. # TODO(parkmycar): `prof-http`s build script downloads resources from npm.
  17. #build --sandbox_default_allow_network=false
  18. # Bazel provides the macOS 14.5 SDK as the sysroot, we also set the minimum
  19. # version to prevent breaking the remote cache across developer machines.
  20. common --copt=-mmacosx-version-min=14.0
  21. common --linkopt=-mmacosx-version-min=14.0
  22. common --macos_sdk_version=14.0
  23. # Note(parkmycar): Ideally we would error on unused command line arguments, but
  24. # trying to constrain the above arguments to just macos doesn't seem to work.
  25. common --copt=-Wno-unused-command-line-argument
  26. common --linkopt=-Wno-unused-command-line-argument
  27. # Always build position independent C code.
  28. common --copt=-fPIC
  29. # Config for building protobuf.
  30. build --copt=-Wno-error=deprecated-declarations
  31. # Required to stamp our development builds with the current git hash.
  32. #
  33. # This script gets run before every build, see the script for more info.
  34. build:release-stamp --stamp --workspace_status_command "python3 misc/bazel/build-info/workspace_status.py"
  35. # Output all test output by default, this makes it most like cargo.
  36. #
  37. # Note: We used to have 'stream' here, but that forces Bazel to serialize test execution.
  38. build --test_output=all
  39. # Environment variables to pass through to the test runner. These can impact
  40. # remote cache hits, so add them sparingly.
  41. #
  42. # TODO(parkmycar): Switch over to using `env_inherit` on `rust_test` once that's stable.
  43. # <https://github.com/bazelbuild/rules_rust/pull/2809>
  44. build --test_env=COCKROACH_URL
  45. # Allows spaces to in filenames, without this Rust Doc tests fail to build.
  46. build:macos --experimental_inprocess_symlink_creation
  47. # Tracks stashed sandboxes in-memory so it uses less I/O on reuse.
  48. #
  49. # Bazel's sandbox performance on macOS doesn't scale very well, see: <https://github.com/bazelbuild/bazel/issues/8230>
  50. build --experimental_inmemory_sandbox_stashes
  51. # Don't build runfile symlink forests, unless required.
  52. build --nobuild_runfile_links
  53. # Always have Bazel output why it rebuilt something, should make debugging builds easier.
  54. #
  55. # TODO(parkmycar): Enable this under a "debug" or "verbose"
  56. # common --explain=bazel-explain.log
  57. # common --verbose_explanations
  58. # Compress any artifacts larger than 2MiB with zstd.
  59. #
  60. # Note(parkmycar): These thresholds were chosen arbitrarily. You should feel
  61. # free to change them if you encounter issues.
  62. common --remote_cache_compression
  63. common --experimental_remote_cache_compression_threshold=2097152
  64. # Memoizes merkle tree calculations to improve the remote cache hit checking speed.
  65. common --experimental_remote_merkle_tree_cache
  66. # Number of merkle trees to memoize (default 1000).
  67. common --experimental_remote_merkle_tree_cache_size=5000
  68. # Don't make the user wait for uploading artifacts to complete, finish it in the background.
  69. common --bes_upload_mode=fully_async
  70. # Make sure any local disk cache stays within a reasonable size.
  71. common --experimental_disk_cache_gc_max_size=80G
  72. common --experimental_disk_cache_gc_max_age=14d
  73. # Tells `xz` to use all available cores.
  74. action_env=XZ_OPT=-T0
  75. #
  76. # Config when running Bazel from a script.
  77. #
  78. # Silence most UI output since it's noisy.
  79. run:script --ui_event_filters=-info,-stdout,-stderr --noshow_progress
  80. # LLVM's libc++ has different assertion modes which can be configured to catch
  81. # undefined behavior. See: <https://libcxx.llvm.org/Hardening.html>
  82. build:debug --cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"
  83. build:debug --host_cxxopt="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"
  84. build:debug --@rules_rust//:extra_rustc_flag="-Csplit-debuginfo=unpacked"
  85. #
  86. # Debug Info Configuration
  87. #
  88. # TODO(parkmycar): Enable this for macOS. `toolchains_llvm` defaults to ld64 which
  89. # doesn't support zlib compression.
  90. build:linux --linkopt="-Wl,--compress-debug-sections=zlib"
  91. build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,--compress-debug-sections=zlib"
  92. # Specifying "-O2" uses level 6 zlib compression.
  93. build:linux --linkopt="-Wl,-O2"
  94. build:linux --@rules_rust//:extra_rustc_flag="-Clink-arg=-Wl,-O2"
  95. build:linux --copt="-gz=zlib"
  96. # Match the DWARF version used by Rust.
  97. #
  98. # Note(parkmycar): This might not be necessary but seemed nice to do.
  99. #
  100. # See: <https://doc.rust-lang.org/stable/unstable-book/compiler-flags/dwarf-version.html>
  101. build:linux --copt="-gdwarf-4"
  102. build:linux --linkopt="-gdwarf-4"
  103. build:macos --copt="-gdwarf-2"
  104. build:macos --linkopt="-gdwarf-2"
  105. # Emit full debug info, allowing us to easily analyze core dumps from staging
  106. # (and, in an emergency, also prod).
  107. build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cdebuginfo=2
  108. build:debuginfo-full --copt=-g2
  109. build:debuginfo-full --strip=never
  110. build:debuginfo-full --@rules_rust//:extra_rustc_flag=-Cstrip=none
  111. build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cdebuginfo=1
  112. build:debuginfo-limited --copt=-g1
  113. build:debuginfo-limited --strip=never
  114. build:debuginfo-limited --@rules_rust//:extra_rustc_flag=-Cstrip=none
  115. build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cdebuginfo=0
  116. build:debuginfo-none --copt=-g0
  117. build:debuginfo-none --strip=always
  118. build:debuginfo-none --@rules_rust//:extra_rustc_flag=-Cstrip=symbols
  119. #
  120. # Common Build Configuration
  121. #
  122. build --linkopt="-fuse-ld=lld"
  123. build --@rules_rust//:extra_rustc_flag="-Clink-arg=-fuse-ld=lld"
  124. build --@rules_rust//:extra_rustc_flag="-Csymbol-mangling-version=v0"
  125. # We use 64 because it's enough to totally saturate a CI builder so our builds
  126. # are as fast as possible, and it's less than the default of 256 used with
  127. # Cargo when incremental compilation is enabled.
  128. build --@rules_rust//:extra_rustc_flag="-Ccodegen-units=64"
  129. # Enabling pipelined builds allows dependent libraries to begin compiling with
  130. # just `.rmeta` instead of the full `.rlib`. This is what Cargo does and offers
  131. # a significant speedup in end-to-end build times!
  132. build --@rules_rust//rust/settings:pipelined_compilation=True
  133. # `cargo check` like config, still experimental!
  134. #
  135. # Ignores all outputs other than `.rmeta`, requires pipelied_compilation to be enabled!
  136. build:check --output_groups=build_metadata
  137. # CI Build Configuration
  138. #
  139. # Note: This shouldn't change any config of the built binary, just the way it
  140. # gets built.
  141. #
  142. # Always enable verbose failures in CI, makes it easier to debug failures.
  143. build:ci --verbose_failures
  144. # `/dev/shm` is a RAM backed temporary filesystem, it should speedup sandbox creation.
  145. build:in-mem-sandbox --sandbox_base=/dev/shm
  146. # Release Build Configuration
  147. #
  148. build:release --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
  149. build:release --copt=-O3
  150. build:release --copt=-DNDEBUG
  151. build:release --compilation_mode=opt
  152. # We only enable Link Time Optimization for CI builds and not local release builds.
  153. build:release-lto --copt=-flto=thin
  154. build:release-lto --linkopt=-flto=thin
  155. build:release-lto --@rules_rust//rust/settings:lto=thin
  156. build:release-lto --@//misc/bazel/platforms:xlang_lto=True
  157. # Builds from `main` or tagged builds.
  158. #
  159. # Note: We don't use a ramdisk for tagged builds because the full debuginfo is
  160. # too large and we OOD/OOM.
  161. build:release-tagged --config=release --config=release-lto --config=release-stamp --config=debuginfo-full
  162. # PRs in CI.
  163. #
  164. # Not doing a full stamp nor omitting full debug info, greatly speeds up compile times.
  165. build:release-dev --config=release --config=optimized --config=debuginfo-limited
  166. # "Optimized" Build.
  167. #
  168. # Provides both reasonably fast compile times and runtimes.
  169. build:optimized --compilation_mode=opt
  170. build:optimized --cxxopt=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
  171. build:optimized --copt=-O2
  172. build:optimized --copt=-DNDEBUG
  173. build:optimized --config=debuginfo-none
  174. build:optimized --copt=-fno-lto
  175. build:optimized --linkopt=-fno-lto
  176. build:optimized --@rules_rust//rust/settings:lto=off
  177. # Build with the Rust Nightly Toolchain
  178. build:rust-nightly --@rules_rust//rust/toolchain/channel=nightly
  179. # AddressSanitizer
  180. #
  181. # Only works on Linux and does not support cross compiling.
  182. #
  183. # TODO: To support cross compiling sanitized builds we most likely need to move
  184. # our compiler runtime libraries (e.g. libc++, libunwind, asan) from our
  185. # toolchain into our system root, and then also specify `-resource-dir` to tell
  186. # `clang` to search for these libraries in the system root.
  187. #
  188. # See: <https://clang.llvm.org/docs/AddressSanitizer.html>
  189. # <https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html#addresssanitizer>
  190. build:asan --config=rust-nightly
  191. build:asan --@rules_rust//:extra_rustc_flag=-Zsanitizer=address --@rules_rust//:extra_rustc_flag=-Zexternal-clangrt
  192. build:asan --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=on
  193. build:asan --@rules_rust//:extra_rustc_flag=-Cllvm-args=-asan-use-after-scope
  194. build:asan --@rules_rust//:extra_rustc_flag=-Cllvm-args=-asan-use-after-return=always
  195. build:asan --copt=-fsanitize=address
  196. build:asan --copt=-fno-omit-frame-pointer
  197. build:asan --copt=-g
  198. build:asan --copt=-O1
  199. build:asan --linkopt=-fsanitize=address
  200. build:asan --strip=never
  201. build:asan --@//misc/bazel/platforms:sanitizer="address"
  202. build:asan --action_env=ASAN_OPTIONS=verbosity=1
  203. # HACK(parkmycar): We want to tell Rust to use the Bazel provided `clang++` but there isn't
  204. # a great way to do that. We know this is where `clang++` lives though, so it works.
  205. build:asan --@rules_rust//:extra_rustc_flag=-Clinker=external/llvm_toolchain_llvm/bin/clang++
  206. # Hardware Assisted AddressSanitizer
  207. #
  208. # Only works on `aarch64-linux-unknown-gnu` and does not support cross compiling.
  209. #
  210. # See: <https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html>
  211. # <https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html#hwaddresssanitizer>
  212. build:hwasan --config=rust-nightly
  213. build:hwasan --@rules_rust//:extra_rustc_flag=-Zsanitizer=hwaddress --@rules_rust//:extra_rustc_flag=-Zexternal-clangrt
  214. build:hwasan --@rules_rust//:extra_rustc_flag=-Cdebug-assertions=on
  215. build:hwasan --@rules_rust//:extra_rustc_flag=-Ctarget-feature=+tagged-globals
  216. build:hwasan --copt=-fsanitize=hwaddress
  217. build:hwasan --copt=-fno-omit-frame-pointer
  218. build:hwasan --copt=-g
  219. build:hwasan --copt=-O1
  220. build:hwasan --linkopt=-fsanitize=hwaddress
  221. build:hwasan --strip=never
  222. build:hwasan --@//misc/bazel/platforms:sanitizer="hwaddress"
  223. build:hwasan --action_env=ASAN_OPTIONS=verbosity=1
  224. # HACK(parkmycar): We want to tell Rust to use the Bazel provided `clang++` but there isn't
  225. # a great way to do that. We know this is where `clang++` lives though, so it works.
  226. build:hwasan --@rules_rust//:extra_rustc_flag=-Clinker=external/llvm_toolchain_llvm/bin/clang++