Skip to content

Commit 4b4e2ec

Browse files
authored
chore: bazelrc presets (#3865)
1 parent 82738bd commit 4b4e2ec

File tree

6 files changed

+254
-40
lines changed

6 files changed

+254
-40
lines changed

.aspect/workflows/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# See https://docs.aspect.build/workflows/configuration
22
tasks:
33
- test:
4+
flags:
5+
- --config=ci
46
notifications:
57
github: {}

.bazelci/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
bazel: 7.1.1
2+
bazel: 7.3.1
33
# Note, this will tell the user to do the wrong thing (manually run buildifer)
44
# See https://github.com/bazelbuild/continuous-integration/issues/1161
55
buildifier:

.bazelrc

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,8 @@
1-
# TODO: migrate all root WORKSPACE dependencies to MODULE.bazel
2-
# https://github.com/bazel-contrib/rules_nodejs/issues/3695
3-
common --noenable_bzlmod
4-
common --enable_workspace
1+
import %workspace%/tools/preset.bazelrc
52

6-
# Specifies desired output mode for running tests.
7-
# Valid values are
8-
# 'summary' to output only test status summary
9-
# 'errors' to also print test logs for failed tests
10-
# 'all' to print logs for all tests
11-
# 'streamed' to output logs for all tests in real time
12-
# (this will force tests to be executed locally one at a time regardless of --test_strategy value).
13-
common --test_output=errors
14-
15-
# Turn on --incompatible_strict_action_env which was on by default
16-
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
17-
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
18-
# This flag is needed to so that the bazel cache is not invalidated
19-
# when running bazel via `yarn bazel`.
20-
# See https://github.com/angular/angular/issues/27514.
21-
common --incompatible_strict_action_env
22-
23-
# Turn off legacy external runfiles
24-
# This prevents accidentally depending on this feature, which Bazel will remove.
25-
common --nolegacy_external_runfiles
26-
27-
# Don’t want to push a rules author to update their deps if not needed.
28-
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
29-
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
30-
common --check_direct_dependencies=off
3+
common --config=ruleset
314

325
# In the root MODULE.bazel file we don't set include_headers on the nodejs toolchain
336
# so the `//nodejs/headers:current_node_cc_headers`` target will not build. This target
347
# is instead tested in `e2e/headers``
358
common --deleted_packages=nodejs/headers
36-
37-
# Load any settings specific to the current user.
38-
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
39-
# This needs to be last statement in this
40-
# config, as the user configuration should be able to overwrite flags from this file.
41-
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
42-
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
43-
# rather than user.bazelrc as suggested in the Bazel docs)
44-
try-import %workspace%/.bazelrc.user

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module(
88
# Lower-bounds (minimum) versions for direct runtime dependencies
99
bazel_dep(name = "bazel_lib", version = "3.0.0-beta.1")
1010
bazel_dep(name = "bazel_skylib", version = "1.4.1")
11+
12+
bazel_dep(name = "bazelrc-preset.bzl", version = "1.2.0", dev_dependency = True)
13+
1114
bazel_dep(name = "platforms", version = "0.0.5")
1215

1316
# workaround for https://github.com/bazelbuild/bazel/issues/25124
@@ -17,7 +20,9 @@ node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
1720

1821
# Note, this gets the default version of Node.js from
1922
# https://github.com/bazel-contrib/rules_nodejs/blob/main/nodejs/repositories.bzl#L11
20-
node.toolchain()
23+
node.toolchain(
24+
node_version = "16.5.0",
25+
)
2126
use_repo(node, "nodejs_toolchains")
2227

2328
# Toolchain registration under bzlmod should match the order of WORKSPACE registration

tools/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@bazelrc-preset.bzl", "bazelrc_preset")
2+
3+
bazelrc_preset(
4+
name = "preset",
5+
strict = True, # Enable this to opt-in to flags that are flipped in the upcoming major release
6+
)

tools/preset.bazelrc

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Generated by bazelrc-preset.bzl
2+
# To update this file, run:
3+
# bazel run @@//tools:preset.update
4+
5+
# On CI, announce all announces command options read from the bazelrc file(s) when starting up at the
6+
# beginning of each Bazel invocation. This is very useful on CI to be able to inspect which flags
7+
# are being applied on each run based on the order of overrides.
8+
common:ci --announce_rc
9+
# Docs: https://registry.build/flag/[email protected]?filter=announce_rc
10+
11+
# Avoid creating a runfiles tree for binaries or tests until it is needed.
12+
# See https://github.com/bazelbuild/bazel/issues/6627
13+
# This may break local workflows that `build` a binary target, then run the resulting program outside of `bazel run`.
14+
# In those cases, the script will need to call `bazel build --build_runfile_links //my/binary:target` and then execute the resulting program.
15+
common --nobuild_runfile_links
16+
# Docs: https://registry.build/flag/[email protected]?filter=build_runfile_links
17+
18+
# See https://github.com/bazelbuild/bazel/issues/20577
19+
coverage --build_runfile_links
20+
# Docs: https://registry.build/flag/[email protected]?filter=build_runfile_links
21+
22+
# Always run tests even if they have cached results.
23+
# This ensures tests are executed fresh each time, useful for debugging and ensuring test reliability.
24+
common:debug --nocache_test_results
25+
# Docs: https://registry.build/flag/[email protected]?filter=cache_test_results
26+
27+
# Don’t encourage a rules author to update their deps if not needed.
28+
# These bazel_dep calls should indicate the minimum version constraint of the ruleset.
29+
# If the author instead updates to the newest of any of their transitives, as this flag would suggest,
30+
# then they'll also force their dependents to a newer version.
31+
# Context:
32+
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
33+
common:ruleset --check_direct_dependencies="off"
34+
# Docs: https://registry.build/flag/[email protected]?filter=check_direct_dependencies
35+
36+
# On CI, use colors to highlight output on the screen. Set to `no` if your CI does not display colors.
37+
common:ci --color="yes"
38+
# Docs: https://registry.build/flag/[email protected]?filter=color
39+
40+
# On CI, use cursor controls in screen output.
41+
common:ci --curses="yes"
42+
# Docs: https://registry.build/flag/[email protected]?filter=curses
43+
44+
# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is
45+
# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS
46+
# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is
47+
# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc.
48+
common --enable_platform_specific_config
49+
# Docs: https://registry.build/flag/[email protected]?filter=enable_platform_specific_config
50+
51+
# Speed up all builds by not checking if external repository files have been modified.
52+
# For reference: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244
53+
common --noexperimental_check_external_repository_files
54+
# Docs: https://registry.build/flag/[email protected]?filter=experimental_check_external_repository_files
55+
56+
# Always download coverage files for tests from the remote cache. By default, coverage files are not
57+
# downloaded on test result cache hits when --remote_download_minimal is enabled, making it impossible
58+
# to generate a full coverage report.
59+
common --experimental_fetch_all_coverage_outputs
60+
# Docs: https://registry.build/flag/[email protected]?filter=experimental_fetch_all_coverage_outputs
61+
62+
# This flag was added in Bazel 6.2.0 with a default of zero:
63+
# https://github.com/bazelbuild/bazel/commit/24b45890c431de98d586fdfe5777031612049135
64+
# For Bazel 8.0.0rc1 the default was changed to 5:
65+
# https://github.com/bazelbuild/bazel/commit/739e37de66f4913bec1a55b2f2a162e7db6f2d0f
66+
# Back-port the updated flag default value to older Bazel versions.
67+
common --experimental_remote_cache_eviction_retries=5
68+
# Docs: https://registry.build/flag/[email protected]?filter=experimental_remote_cache_eviction_retries
69+
70+
# This flag was added in Bazel 5.0.0 with a default of zero:
71+
# https://github.com/bazelbuild/bazel/commit/a1137ec1338d9549fd34a9a74502ffa58c286a8e
72+
# For Bazel 8.0.0 the default was changed to 5:
73+
# https://github.com/bazelbuild/bazel/commit/9335cf989ee6a678ca10bc4da72214634cef0a57
74+
# Back-port the updated flag default value to older Bazel versions.
75+
common --experimental_repository_downloader_retries=5
76+
# Docs: https://registry.build/flag/[email protected]?filter=experimental_repository_downloader_retries
77+
78+
# Set this flag to enable re-tries of failed tests on CI.
79+
# When any test target fails, try one or more times. This applies regardless of whether the "flaky"
80+
# tag appears on the target definition.
81+
# This is a tradeoff: legitimately failing tests will take longer to report,
82+
# but we can "paper over" flaky tests that pass most of the time.
83+
#
84+
# An alternative is to mark every flaky test with the `flaky = True` attribute, but this requires
85+
# the buildcop to make frequent code edits.
86+
# This flag is not recommended for local builds: flakiness is more likely to get fixed if it is
87+
# observed during development.
88+
#
89+
# Note that when passing after the first attempt, Bazel will give a special "FLAKY" status rather than "PASSED".
90+
test:ci --flaky_test_attempts=2
91+
# Docs: https://registry.build/flag/[email protected]?filter=flaky_test_attempts
92+
93+
# Fixes builds hanging on CI that get the TCP connection closed without sending RST packets.
94+
common:ci --grpc_keepalive_time="30s"
95+
# Docs: https://registry.build/flag/[email protected]?filter=grpc_keepalive_time
96+
97+
# Output a heap dump if an OOM is thrown during a Bazel invocation
98+
# (including OOMs due to `--experimental_oom_more_eagerly_threshold`).
99+
# The dump will be written to `<output_base>/<invocation_id>.heapdump.hprof`.
100+
# You should configure CI to upload this artifact for later inspection.
101+
common --heap_dump_on_oom
102+
# Docs: https://registry.build/flag/[email protected]?filter=heap_dump_on_oom
103+
104+
# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server
105+
# notices when a directory changes, if you have a directory listed in the srcs of some target.
106+
# Recommended when using [copy_directory](https://github.com/bazel-contrib/bazel-lib/blob/main/docs/copy_directory.md)
107+
# and [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories inputs to copy_directory actions.
108+
startup --host_jvm_args="-DBAZEL_TRACK_SOURCE_DIRECTORIES=1"
109+
# Docs: https://registry.build/flag/[email protected]?filter=host_jvm_args
110+
111+
# By default, Bazel automatically creates __init__.py files for py_binary and py_test targets.
112+
# From https://github.com/bazelbuild/bazel/issues/10076:
113+
# > It is magic at a distance.
114+
# > Python programmers are already used to creating __init__.py files in their source trees,
115+
# > so doing it behind their backs introduces confusion and changes the semantics of imports
116+
common --incompatible_default_to_explicit_init_py
117+
# Docs: https://registry.build/flag/[email protected]?filter=incompatible_default_to_explicit_init_py
118+
119+
# Disallow empty glob patterns.
120+
# The glob() function tends to be error-prone, because any typo in a path will silently return an empty list.
121+
# This flag was added in Bazel 0.27 and flipped in Bazel 8: https://github.com/bazelbuild/bazel/issues/8195
122+
common --incompatible_disallow_empty_glob
123+
# Docs: https://registry.build/flag/[email protected]?filter=incompatible_disallow_empty_glob
124+
125+
# Make builds more reproducible by using a static value for PATH and not inheriting LD_LIBRARY_PATH.
126+
# Use `--action_env=ENV_VARIABLE` if you want to inherit specific variables from the environment where Bazel runs.
127+
# Note that doing so can prevent cross-user caching if a shared cache is used.
128+
# See https://github.com/bazelbuild/bazel/issues/2574 for more details.
129+
common --incompatible_strict_action_env
130+
# Docs: https://registry.build/flag/[email protected]?filter=incompatible_strict_action_env
131+
132+
# Performance improvement: avoid laying out a second copy of the runfiles tree.
133+
# See https://github.com/bazelbuild/bazel/issues/23574.
134+
# This flag was flipped for Bazel 8.
135+
common --nolegacy_external_runfiles
136+
# Docs: https://registry.build/flag/[email protected]?filter=legacy_external_runfiles
137+
138+
# On CI, don't download remote outputs to the local machine.
139+
# Most CI pipelines don't need to access the files and they can remain at rest on the remote cache.
140+
# Significant time can be spent on needless downloads, which is especially noticeable on fully-cached builds.
141+
#
142+
# If you do need to download files, the fastest options are:
143+
# - (preferred) Use `remote_download_regex` to specify the files to download.
144+
# - Use the Remote Output Service (https://blog.bazel.build/2024/07/23/remote-output-service.html)
145+
# to lazy-materialize specific files after the build completes.
146+
# - Perform a second bazel command with specific targets and override this flag with the `toplevel` value.
147+
# - To copy executable targets, you can use `bazel run --run_under=cp //some:binary_target <destination path>`.
148+
common:ci --remote_download_outputs="minimal"
149+
# Docs: https://registry.build/flag/[email protected]?filter=remote_download_outputs
150+
151+
# On CI, fall back to standalone local execution strategy if remote execution fails.
152+
# Otherwise, when a grpc remote cache connection fails, it would fail the build.
153+
common:ci --remote_local_fallback
154+
# Docs: https://registry.build/flag/[email protected]?filter=remote_local_fallback
155+
156+
# On CI, extend the maximum amount of time to wait for remote execution and cache calls.
157+
common:ci --remote_timeout=3600
158+
# Docs: https://registry.build/flag/[email protected]?filter=remote_timeout
159+
160+
# Do not upload locally executed action results to the remote cache.
161+
# This should be the default for local builds so local builds cannot poison the remote cache.
162+
#
163+
# Note that this flag is flipped to True under --config=ci, see below.
164+
common --noremote_upload_local_results
165+
# Docs: https://registry.build/flag/[email protected]?filter=remote_upload_local_results
166+
167+
# On CI, upload locally executed action results to the remote cache.
168+
common:ci --remote_upload_local_results
169+
# Docs: https://registry.build/flag/[email protected]?filter=remote_upload_local_results
170+
171+
# Repository rules, such as rules_jvm_external: put Bazel's JDK on the path.
172+
# Avoids non-hermeticity from dependency on a JAVA_HOME pointing at a system JDK
173+
# see https://github.com/bazelbuild/rules_jvm_external/issues/445
174+
common --repo_env="JAVA_HOME=../bazel_tools/jdk"
175+
# Docs: https://registry.build/flag/[email protected]?filter=repo_env
176+
177+
# Reuse sandbox directories between invocations.
178+
# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs.
179+
# Saves time on sandbox creation and deletion when many of the same kind of action is spawned during the build.
180+
common --reuse_sandbox_directories
181+
# Docs: https://registry.build/flag/[email protected]?filter=reuse_sandbox_directories
182+
183+
# Don't allow network access for build actions in the sandbox by default.
184+
# Avoids accidental non-hermeticity in actions/tests which depend on remote services.
185+
# Developers should tag targets with `tags=["requires-network"]` to be explicit that they need network access.
186+
# Note that the sandbox cannot print a message to the console if it denies network access,
187+
# so failures under this flag appear as application errors in the networking layer.
188+
common --nosandbox_default_allow_network
189+
# Docs: https://registry.build/flag/[email protected]?filter=sandbox_default_allow_network
190+
191+
# Only show progress every 60 seconds on CI.
192+
# We want to find a compromise between printing often enough to show that the build isn't stuck,
193+
# but not so often that we produce a long log file that requires a lot of scrolling.
194+
common:ci --show_progress_rate_limit=60
195+
# Docs: https://registry.build/flag/[email protected]?filter=show_progress_rate_limit
196+
197+
# The printed files are convenient strings for copy+pasting to the shell, to execute them.
198+
# This option requires an integer argument, which is the threshold number of targets above which result information is not printed.
199+
# Show the output files created by builds that requested more than one target.
200+
# This helps users locate the build outputs in more cases.
201+
common --show_result=20
202+
# Docs: https://registry.build/flag/[email protected]?filter=show_result
203+
204+
# On CI, add a timestamp to each message generated by Bazel specifying the time at which the message was displayed.
205+
# This makes it easier to reason about what were the slowest steps on CI.
206+
common:ci --show_timestamps
207+
# Docs: https://registry.build/flag/[email protected]?filter=show_timestamps
208+
209+
# The terminal width in columns. Configure this to override the default value based on what your CI system renders.
210+
common:ci --terminal_columns=143
211+
# Docs: https://registry.build/flag/[email protected]?filter=terminal_columns
212+
213+
# Output test errors to stderr so users don't have to `cat` or open test failure log files when test fail.
214+
# This makes the log noisier in exchange for reducing the time-to-feedback on test failures for users.
215+
common --test_output="errors"
216+
# Docs: https://registry.build/flag/[email protected]?filter=test_output
217+
218+
# Stream stdout/stderr output from each test in real-time.
219+
# This provides immediate feedback during test execution, useful for debugging test failures.
220+
common:debug --test_output="streamed"
221+
# Docs: https://registry.build/flag/[email protected]?filter=test_output
222+
223+
# Run one test at a time in exclusive mode.
224+
# This prevents test interference and provides clearer output when debugging test issues.
225+
common:debug --test_strategy="exclusive"
226+
# Docs: https://registry.build/flag/[email protected]?filter=test_strategy
227+
228+
# The default test_summary ("short") prints a result for every test target that was executed.
229+
# In a large repo this amounts to hundreds of lines of additional log output when testing a broad wildcard pattern like //...
230+
# This value means to print information only about unsuccessful tests that were run.
231+
test:ci --test_summary="terse"
232+
# Docs: https://registry.build/flag/[email protected]?filter=test_summary
233+
234+
# Prevent long running tests from timing out.
235+
# Set to a high value to allow tests to complete even if they take longer than expected.
236+
common:debug --test_timeout=9999
237+
# Docs: https://registry.build/flag/[email protected]?filter=test_timeout

0 commit comments

Comments
 (0)