Skip to content

Commit 638ac2f

Browse files
authored
Add bazelrc preset (#169)
* Add bazelrc preset * use ci config
1 parent 0cb7712 commit 638ac2f

File tree

6 files changed

+263
-11
lines changed

6 files changed

+263
-11
lines changed

.bazelrc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
########################
2+
# Import bazelrc presets
3+
import %workspace%/tools/preset.bazelrc
4+
5+
# Don’t want to push a rules author to update their deps if not needed.
6+
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
7+
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
8+
common --config=ruleset
9+
110
# Bazel settings that apply to this repository.
211
# Take care to document any settings that you expect users to apply.
312
# Settings that apply only to CI are in .github/workflows/ci.bazelrc
413

514
# Required until this is the default; expected in Bazel 7
615
common --enable_bzlmod
716

8-
# Don’t want to push a rules author to update their deps if not needed.
9-
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
10-
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
11-
common --check_direct_dependencies=off
12-
1317
# Ensure that the MODULE.bazel.lock file is complete and committed.
1418
# This is an important security measure: it ensures that developers on the
1519
# same rule set download dependencies at the same versions with the same bits.

.github/workflows/ci.bazelrc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# This file contains Bazel settings to apply on CI only.
22
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml
33

4-
# Debug where options came from
5-
build --announce_rc
4+
common --config=ci
65
# This directory is configured in GitHub actions to be persisted between runs.
76
# We do not enable the repository cache to cache downloaded external artifacts
87
# as these are generally faster to download again than to fetch them from the
98
# GitHub actions cache.
10-
build --disk_cache=~/.cache/bazel
11-
# Don't rely on test logs being easily accessible from the test runner,
12-
# though it makes the log noisier.
13-
test --test_output=errors
9+
common --disk_cache=~/.cache/bazel
1410
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
1511
test --test_env=XDG_CACHE_HOME

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.2", dev_dependenc
3939
bazel_dep(name = "bazel_lib", version = "3.0.0", dev_dependency = True)
4040
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1", dev_dependency = True)
4141

42+
bazel_dep(name = "bazelrc-preset.bzl", version = "1.6.0")
43+
4244
mylang = use_extension("//mylang:extensions.bzl", "mylang")
4345
mylang.toolchain(mylang_version = "1.14.2")
4446
use_repo(mylang, "mylang_toolchains")

MODULE.bazel.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/BUILD.bazel

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+
doc_link_template = "https://registry.build/flag/bazel?filter={flag}",
6+
)

tools/preset.bazelrc

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?filter=color
39+
40+
# On CI, use cursor controls in screen output.
41+
common:ci --curses="yes"
42+
# Docs: https://registry.build/flag/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?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/bazel?filter=incompatible_disallow_empty_glob
124+
125+
# Accept multiple --modify_execution_info flags, rather than the last flag overwriting earlier ones.
126+
common --incompatible_modify_execution_info_additive
127+
# Docs: https://registry.build/flag/bazel?filter=incompatible_modify_execution_info_additive
128+
129+
# Make builds more reproducible by using a static value for PATH and not inheriting LD_LIBRARY_PATH.
130+
# Use `--action_env=ENV_VARIABLE` if you want to inherit specific variables from the environment where Bazel runs.
131+
# Note that doing so can prevent cross-user caching if a shared cache is used.
132+
# See https://github.com/bazelbuild/bazel/issues/2574 for more details.
133+
common --incompatible_strict_action_env
134+
# Docs: https://registry.build/flag/bazel?filter=incompatible_strict_action_env
135+
136+
# Performance improvement: avoid laying out a second copy of the runfiles tree.
137+
# See https://github.com/bazelbuild/bazel/issues/23574.
138+
# This flag was flipped for Bazel 8.
139+
common --nolegacy_external_runfiles
140+
# Docs: https://registry.build/flag/bazel?filter=legacy_external_runfiles
141+
142+
# On CI, don't download remote outputs to the local machine.
143+
# Most CI pipelines don't need to access the files and they can remain at rest on the remote cache.
144+
# Significant time can be spent on needless downloads, which is especially noticeable on fully-cached builds.
145+
#
146+
# If you do need to download files, the fastest options are:
147+
# - (preferred) Use `remote_download_regex` to specify the files to download.
148+
# - Use the Remote Output Service (https://blog.bazel.build/2024/07/23/remote-output-service.html)
149+
# to lazy-materialize specific files after the build completes.
150+
# - Perform a second bazel command with specific targets and override this flag with the `toplevel` value.
151+
# - To copy executable targets, you can use `bazel run --run_under=cp //some:binary_target <destination path>`.
152+
common:ci --remote_download_outputs="minimal"
153+
# Docs: https://registry.build/flag/bazel?filter=remote_download_outputs
154+
155+
# On CI, fall back to standalone local execution strategy if remote execution fails.
156+
# Otherwise, when a grpc remote cache connection fails, it would fail the build.
157+
common:ci --remote_local_fallback
158+
# Docs: https://registry.build/flag/bazel?filter=remote_local_fallback
159+
160+
# On CI, extend the maximum amount of time to wait for remote execution and cache calls.
161+
common:ci --remote_timeout=3600
162+
# Docs: https://registry.build/flag/bazel?filter=remote_timeout
163+
164+
# Do not upload locally executed action results to the remote cache.
165+
# This should be the default for local builds so local builds cannot poison the remote cache.
166+
#
167+
# Note that this flag is flipped to True under --config=ci, see below.
168+
common --noremote_upload_local_results
169+
# Docs: https://registry.build/flag/bazel?filter=remote_upload_local_results
170+
171+
# On CI, upload locally executed action results to the remote cache.
172+
common:ci --remote_upload_local_results
173+
# Docs: https://registry.build/flag/bazel?filter=remote_upload_local_results
174+
175+
# Repository rules, such as rules_jvm_external: put Bazel's JDK on the path.
176+
# Avoids non-hermeticity from dependency on a JAVA_HOME pointing at a system JDK
177+
# see https://github.com/bazelbuild/rules_jvm_external/issues/445
178+
common --repo_env="JAVA_HOME=../bazel_tools/jdk"
179+
# Docs: https://registry.build/flag/bazel?filter=repo_env
180+
181+
# Reuse sandbox directories between invocations.
182+
# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs.
183+
# Saves time on sandbox creation and deletion when many of the same kind of action is spawned during the build.
184+
common --reuse_sandbox_directories
185+
# Docs: https://registry.build/flag/bazel?filter=reuse_sandbox_directories
186+
187+
# Don't allow network access for build actions in the sandbox by default.
188+
# Avoids accidental non-hermeticity in actions/tests which depend on remote services.
189+
# Developers should tag targets with `tags=["requires-network"]` to be explicit that they need network access.
190+
# Note that the sandbox cannot print a message to the console if it denies network access,
191+
# so failures under this flag appear as application errors in the networking layer.
192+
common --nosandbox_default_allow_network
193+
# Docs: https://registry.build/flag/bazel?filter=sandbox_default_allow_network
194+
195+
# Only show progress every 60 seconds on CI.
196+
# We want to find a compromise between printing often enough to show that the build isn't stuck,
197+
# but not so often that we produce a long log file that requires a lot of scrolling.
198+
common:ci --show_progress_rate_limit=60
199+
# Docs: https://registry.build/flag/bazel?filter=show_progress_rate_limit
200+
201+
# The printed files are convenient strings for copy+pasting to the shell, to execute them.
202+
# This option requires an integer argument, which is the threshold number of targets above which result information is not printed.
203+
# Show the output files created by builds that requested more than one target.
204+
# This helps users locate the build outputs in more cases.
205+
common --show_result=20
206+
# Docs: https://registry.build/flag/bazel?filter=show_result
207+
208+
# On CI, add a timestamp to each message generated by Bazel specifying the time at which the message was displayed.
209+
# This makes it easier to reason about what were the slowest steps on CI.
210+
common:ci --show_timestamps
211+
# Docs: https://registry.build/flag/bazel?filter=show_timestamps
212+
213+
# The terminal width in columns. Configure this to override the default value based on what your CI system renders.
214+
common:ci --terminal_columns=143
215+
# Docs: https://registry.build/flag/bazel?filter=terminal_columns
216+
217+
# Output test errors to stderr so users don't have to `cat` or open test failure log files when test fail.
218+
# This makes the log noisier in exchange for reducing the time-to-feedback on test failures for users.
219+
common --test_output="errors"
220+
# Docs: https://registry.build/flag/bazel?filter=test_output
221+
222+
# Stream stdout/stderr output from each test in real-time.
223+
# This provides immediate feedback during test execution, useful for debugging test failures.
224+
common:debug --test_output="streamed"
225+
# Docs: https://registry.build/flag/bazel?filter=test_output
226+
227+
# Run one test at a time in exclusive mode.
228+
# This prevents test interference and provides clearer output when debugging test issues.
229+
common:debug --test_strategy="exclusive"
230+
# Docs: https://registry.build/flag/bazel?filter=test_strategy
231+
232+
# The default test_summary ("short") prints a result for every test target that was executed.
233+
# In a large repo this amounts to hundreds of lines of additional log output when testing a broad wildcard pattern like //...
234+
# This value means to print information only about unsuccessful tests that were run.
235+
test:ci --test_summary="terse"
236+
# Docs: https://registry.build/flag/bazel?filter=test_summary
237+
238+
# Prevent long running tests from timing out.
239+
# Set to a high value to allow tests to complete even if they take longer than expected.
240+
common:debug --test_timeout=9999
241+
# Docs: https://registry.build/flag/bazel?filter=test_timeout

0 commit comments

Comments
 (0)