Skip to content

Commit 446aa24

Browse files
authored
refactor: build with bazel (#203)
1 parent bf33078 commit 446aa24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1885
-467
lines changed

.aspect/bazelrc/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"Aspect bazelrc presets; see https://docs.aspect.build/guides/bazelrc"
2+
3+
load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")
4+
5+
write_aspect_bazelrc_presets(
6+
name = "update_aspect_bazelrc_presets",
7+
presets = [
8+
"bazel8",
9+
"convenience",
10+
"correctness",
11+
"debug",
12+
"javascript",
13+
"performance",
14+
],
15+
)

.aspect/bazelrc/bazel8.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No Bazel 8 specific flag presets yet.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Attempt to build & test every target whose prerequisites were successfully built.
2+
# Docs: https://bazel.build/docs/user-manual#keep-going
3+
build --keep_going
4+
5+
# Output test errors to stderr so users don't have to `cat` or open test failure log files when test
6+
# fail. This makes the log noisier in exchange for reducing the time-to-feedback on test failures for
7+
# users.
8+
# Docs: https://bazel.build/docs/user-manual#test-output
9+
test --test_output=errors
10+
11+
# Show the output files created by builds that requested more than one target. This helps users
12+
# locate the build outputs in more cases
13+
# Docs: https://bazel.build/docs/user-manual#show-result
14+
build --show_result=20
15+
16+
# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is
17+
# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS
18+
# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is
19+
# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc.
20+
# Docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
21+
common --enable_platform_specific_config
22+
23+
# Output a heap dump if an OOM is thrown during a Bazel invocation
24+
# (including OOMs due to `--experimental_oom_more_eagerly_threshold`).
25+
# The dump will be written to `<output_base>/<invocation_id>.heapdump.hprof`.
26+
# You may need to configure CI to capture this artifact and upload for later use.
27+
# Docs: https://bazel.build/reference/command-line-reference#flag--heap_dump_on_oom
28+
common --heap_dump_on_oom
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Do not upload locally executed action results to the remote cache.
2+
# This should be the default for local builds so local builds cannot poison the remote cache.
3+
# It should be flipped to `--remote_upload_local_results` on CI
4+
# by using `--bazelrc=.aspect/bazelrc/ci.bazelrc`.
5+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results
6+
build --noremote_upload_local_results
7+
8+
# Don't allow network access for build actions in the sandbox.
9+
# Ensures that you don't accidentally make non-hermetic actions/tests which depend on remote
10+
# services.
11+
# Developers should tag targets with `tags=["requires-network"]` to opt-out of the enforcement.
12+
# Docs: https://bazel.build/reference/command-line-reference#flag--sandbox_default_allow_network
13+
build --sandbox_default_allow_network=false
14+
15+
# Warn if a test's timeout is significantly longer than the test's actual execution time.
16+
# Bazel's default for test_timeout is medium (5 min), but most tests should instead be short (1 min).
17+
# While a test's timeout should be set such that it is not flaky, a test that has a highly
18+
# over-generous timeout can hide real problems that crop up unexpectedly.
19+
# For instance, a test that normally executes in a minute or two should not have a timeout of
20+
# ETERNAL or LONG as these are much, much too generous.
21+
# Docs: https://bazel.build/docs/user-manual#test-verbose-timeout-warnings
22+
test --test_verbose_timeout_warnings
23+
24+
# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server
25+
# notices when a directory changes, if you have a directory listed in the srcs of some target.
26+
# Recommended when using
27+
# [copy_directory](https://github.com/bazel-contrib/bazel-lib/blob/main/docs/copy_directory.md) and
28+
# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories
29+
# inputs to copy_directory actions.
30+
# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args
31+
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
32+
33+
# Allow exclusive tests to run in the sandbox. Fixes a bug where Bazel doesn't enable sandboxing for
34+
# tests with `tags=["exclusive"]`.
35+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed
36+
test --incompatible_exclusive_test_sandboxed
37+
38+
# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment
39+
# variables like `PATH` sneak into the build, which can cause massive cache misses when they change.
40+
# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the
41+
# client, but note that doing so can prevent cross-user caching if a shared cache is used.
42+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env
43+
build --incompatible_strict_action_env
44+
45+
# Do not automatically create `__init__.py` files in the runfiles of Python targets. Fixes the wrong
46+
# default that comes from Google's internal monorepo by using `__init__.py` to delimit a Python
47+
# package. Precisely, when a `py_binary` or `py_test` target has `legacy_create_init` set to `auto (the
48+
# default), it is treated as false if and only if this flag is set. See
49+
# https://github.com/bazelbuild/bazel/issues/10076.
50+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py
51+
build --incompatible_default_to_explicit_init_py
52+
53+
# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when
54+
# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package
55+
# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195.
56+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob
57+
common --incompatible_disallow_empty_glob
58+
59+
# Always download coverage files for tests from the remote cache. By default, coverage files are not
60+
# downloaded on test result cache hits when --remote_download_minimal is enabled, making it impossible
61+
# to generate a full coverage report.
62+
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
63+
# detching remote cache results
64+
test --experimental_fetch_all_coverage_outputs

.aspect/bazelrc/debug.bazelrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
############################################################
2+
# Use `bazel test --config=debug` to enable these settings #
3+
############################################################
4+
5+
# Stream stdout/stderr output from each test in real-time.
6+
# Docs: https://bazel.build/docs/user-manual#test-output
7+
test:debug --test_output=streamed
8+
9+
# Run one test at a time.
10+
# Docs: https://bazel.build/reference/command-line-reference#flag--test_strategy
11+
test:debug --test_strategy=exclusive
12+
13+
# Prevent long running tests from timing out.
14+
# Docs: https://bazel.build/docs/user-manual#test-timeout
15+
test:debug --test_timeout=9999
16+
17+
# Always run tests even if they have cached results.
18+
# Docs: https://bazel.build/docs/user-manual#cache-test-results
19+
test:debug --nocache_test_results

.aspect/bazelrc/javascript.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Aspect recommended Bazel flags when using Aspect's JavaScript rules: https://github.com/aspect-build/rules_js
2+
# Docs for Node.js flags: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options
3+
4+
# Support for debugging Node.js tests. Use bazel run with `--config=debug` to turn on the NodeJS
5+
# inspector agent. The node process will break before user code starts and wait for the debugger to
6+
# connect. Pass the --inspect-brk option to all tests which enables the node inspector agent. See
7+
# https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more
8+
# details.
9+
# Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options
10+
run:debug -- --node_options=--inspect-brk
11+
test:debug --test_env=NODE_OPTIONS=--inspect-brk
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs.
2+
# Save time on Sandbox creation and deletion when many of the same kind of action run during the
3+
# build.
4+
# No longer experimental in Bazel 6: https://github.com/bazelbuild/bazel/commit/c1a95501a5611878e5cc43a3cc531f2b9e47835b
5+
# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories
6+
build --experimental_reuse_sandbox_directories
7+
8+
# Avoid creating a runfiles tree for binaries or tests until it is needed.
9+
# Docs: https://bazel.build/reference/command-line-reference#flag--build_runfile_links
10+
# See https://github.com/bazelbuild/bazel/issues/6627
11+
#
12+
# This may break local workflows that `build` a binary target, then run the resulting program
13+
# outside of `bazel run`. In those cases, the script will need to call
14+
# `bazel build --build_runfile_links //my/binary:target` and then execute the resulting program.
15+
build --nobuild_runfile_links
16+
17+
# Needed prior to Bazel 8; see
18+
# https://github.com/bazelbuild/bazel/issues/20577
19+
coverage --build_runfile_links

.aspect/cli/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
configure:
2+
languages:
3+
javascript: true

.aspect/workflows/bazelrc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Set this flag to enable re-tries of failed tests on CI.
2+
# When any test target fails, try one or more times. This applies regardless of whether the "flaky"
3+
# tag appears on the target definition.
4+
# This is a tradeoff: legitimately failing tests will take longer to report,
5+
# but we can paper over flaky tests that pass most of the time.
6+
# The alternative is to mark every flaky test with the `flaky = True` attribute, but this requires
7+
# the buildcop to make frequent code edits.
8+
# Not recommended for local builds so that the flakiness is observed during development and thus
9+
# is more likely to get fixed.
10+
# Note that when passing after the first attempt, Bazel will give a special "FLAKY" status.
11+
# Docs: https://bazel.build/docs/user-manual#flaky-test-attempts
12+
test --flaky_test_attempts=2
13+
14+
# Announce all announces command options read from the bazelrc file(s) when starting up at the
15+
# beginning of each Bazel invocation. This is very useful on CI to be able to inspect what Bazel rc
16+
# settings are being applied on each run.
17+
# Docs: https://bazel.build/docs/user-manual#announce-rc
18+
build --announce_rc
19+
20+
# Add a timestamp to each message generated by Bazel specifying the time at which the message was
21+
# displayed.
22+
# Docs: https://bazel.build/docs/user-manual#show-timestamps
23+
build --show_timestamps
24+
25+
# Only show progress every 30 seconds on CI.
26+
# We want to find a compromise between printing often enough to show that the build isn't stuck,
27+
# but not so often that we produce a long log file that requires a lot of scrolling.
28+
# https://bazel.build/reference/command-line-reference#flag--show_progress_rate_limit
29+
build --show_progress_rate_limit=30
30+
31+
# Use cursor controls in screen output.
32+
# Docs: https://bazel.build/docs/user-manual#curses
33+
build --curses=yes
34+
35+
# Use colors to highlight output on the screen. Set to `no` if your CI does not display colors.
36+
# Docs: https://bazel.build/docs/user-manual#color
37+
build --color=yes
38+
39+
# The terminal width in columns. Configure this to override the default value based on what your CI system renders.
40+
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/runtime/UiOptions.java#L151
41+
build --terminal_columns=143
42+
43+
######################################
44+
# Generic remote cache configuration #
45+
######################################
46+
47+
# Only download remote outputs of top level targets to the local machine.
48+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_download_toplevel
49+
build --remote_download_toplevel
50+
51+
# The maximum amount of time to wait for remote execution and cache calls.
52+
# https://bazel.build/reference/command-line-reference#flag--remote_timeout
53+
build --remote_timeout=3600
54+
55+
# Upload locally executed action results to the remote cache.
56+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results
57+
build --remote_upload_local_results
58+
59+
# Fall back to standalone local execution strategy if remote execution fails. If the grpc remote
60+
# cache connection fails, it will fail the build, add this so it falls back to the local cache.
61+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_local_fallback
62+
build --remote_local_fallback
63+
64+
# Fixes builds hanging on CI that get the TCP connection closed without sending RST packets.
65+
# Docs: https://bazel.build/reference/command-line-reference#flag--grpc_keepalive_time
66+
build --grpc_keepalive_time=30s

.aspect/workflows/config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See https://docs.aspect.build/workflows/configuration
2+
tasks:
3+
# - format:
4+
# queue: aspect-medium
5+
- buildifier:
6+
queue: aspect-medium
7+
- configure:
8+
queue: aspect-medium
9+
- test:
10+
- finalization:
11+
queue: aspect-small
12+
notifications:
13+
github: {}

0 commit comments

Comments
 (0)