Bazel Workspaces
Query, build, and test an existing Bazel workspace with Struo: no manifest needed, Bazel keeps analysis, and Struo executes and caches the actions.
Struo reads the workspace through bazel query and exposes every rule as a
Struo target. Bazel still loads targets, resolves toolchains, and downloads
external repositories. Struo runs the resulting actions itself, and falls back
to the native bazel command for actions it does not support.
Prerequisites#
Install Bazel, or Bazelisk to use the version pinned by the workspace, and check that it resolves in the shell that runs Struo:
bazel --versionA workspace that cannot load through the raw bazel command cannot load
through Struo either. When graph loading fails, run the same bazel query
from the workspace root to diagnose it.
Add the Struo cache directory to .bazelignore next to MODULE.bazel:
.struoWithout that entry, BUILD.bazel files that other integrations write under
.struo/out/ can be picked up by bazel query and fail graph loading.
Start from an existing project#
Inspect, build, and test#
Struo recognizes MODULE.bazel, WORKSPACE.bazel, and WORKSPACE
automatically. From the workspace root, without a struo.toml:
struo query targets
struo build
struo teststruo query targets lists every rule returned by
bazel query 'kind("rule", //...)'. struo build builds the workspace's
non-test rules, and struo test runs its test rules. Discovery skips the
generated bazel-bin, bazel-out, and bazel-testlogs directories and does
not write a Struo manifest.
Keep Bazel commands#
Struo can sit behind the bazel command for one workspace. Add this mise
wrapper, then run mise reshim and activate mise in the shell that starts the
build:
[wrappers.bazel]
command = "struo"
args = ["bazel", "--"]Labeled build and test commands then run through the Struo graph:
bazel build //src:kura
bazel test //src:kura_lib_testThe wrapper accepts one fully qualified label per invocation. Every other
request, including wildcards (//...), extra flags (--config=debug),
queries, and bazel run, runs the system bazel executable with its original
arguments and exit status.
To troubleshoot without mise, call the compatibility command directly and put the separator before the Bazel arguments:
struo bazel -- --version
struo bazel -- query "kind(rule, //:*)"Set STRUO_BAZEL_PATH to select a specific bazel executable while the
wrapper is active. By default Struo searches PATH and honors
bazelisk shims.
Choose which rules to include#
Declare a bazel_workspace target in
struo.toml when the defaults do not fit:
queryreplaces the defaultkind("rule", //...)expression.exclude_packagesdrops package prefixes from the default query.test_queryselects which tests a barestruo testruns, without removing any targets from the graph.envandtest_envset the environment for Bazel and for native tests.
Struo does not read test filters from .bazelrc. If your native suite skips
tagged tests, declare the matching test_query.
Limitations#
- Compile and link actions are cached only when the workspace declares
toolchain_inputscovering every host tool, system header, and library the actions use. Without it, those actions run on every build. - Actions Struo does not support run through the native
bazelcommand. Struo does not cache them; Bazel's own cache applies. - Test execution itself is not cached, and Struo does not implement Bazel's flaky-test retries.
- Bazel targets cannot be authored by hand in
struo.toml; they always come from the workspace. - Native actions can contain absolute host paths, so cached results are not
portable across machines. Declaring
toolchain_inputsdoes not enable remote execution.
Target kinds#
bazel_workspace: the workspace seed, its queries, environment, and caching inputs.bazel_target: library-style rules.bazel_binary: rules whose class ends in_binary.bazel_test: test rules, including per-test coverage.
Next steps#
struo bazel: the full compatibility command reference.- Testing and scheduling: plan and run Bazel tests with Struo's test commands.
- Ecosystems: export a graph reproduction when the derived graph disagrees with Bazel.