Skip to content

cargo: declare build-script tool files and runfiles - #4302

Open
jrandolf wants to merge 2 commits into
bazelbuild:mainfrom
jrandolf:fix/build-script-tool-inputs
Open

jrandolf wants to merge 2 commits into
bazelbuild:mainfrom
jrandolf:fix/build-script-tool-inputs

Conversation

@jrandolf

@jrandolf jrandolf commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build scripts now register their explicitly declared tools as FilesToRunProvider values in the action's tools list. Bazel stages each executable and its own runfiles at the execution paths used by build_script_env, including when a compiler incoming transition configures the script's runfiles differently from the action's tools.

The regression uses a rust_binary with runtime data generated by write_file. The tool reads that data through Runfiles and rlocation!; the build script clears inherited runfiles environment variables before launching it, so the test exercises the tool's own runfiles. Coverage includes the public macro and an incoming-transition fixture, plus analysis checks for the exact tool execution paths. The fixture uses the default build-setting scope for compatibility with Bazel 7.4.1.

Fixes #4297.

Validation on macOS arm64 after rebasing onto b11ab7e2:

  • All six tests in //cargo/tests/cargo_build_script/tool_inputs:all, //cargo/tests/cargo_build_script/runfiles:all, and //cargo/tests/cargo_build_script/tools_exec:all pass with Bazel 9.3.1 and 7.4.1, sandboxed execution, rustfmt, and clippy. The Bazel 7.4.1 invocation uses --build_runfile_links, matching the minimum-version CI configuration.
  • The revised regression fails with RunfilesDirNotFound before the provider fix and passes after it.
  • Repository pre-commit checks and git diff --check pass.

@krasimirgg krasimirgg left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

I've got a suggestion for simplifying the manual tool_files extraction and tools = depset(...) addition, shared in inline comments.

Putting tool artifacts into a depset[File] strips FilesToRunProvider for runfiles support and fails to materialize <tool>.runfiles/ (RunfilesTreeArtifact) in the sandbox, instead scattering the tool's runfiles at bare execroot paths. I suggested changes along these lines to the fix and tests, please let me know if the use case you have in mind for this fix doesn't match my thoughts. (see also #4040)

Comment thread cargo/private/cargo_build_script.bzl Resolved
@jrandolf
jrandolf force-pushed the fix/build-script-tool-inputs branch from 7f2ed5b to 1e96caa Compare October 29, 2026 23:14
@jrandolf

jrandolf commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@krasimirgg Done

Pass declared tools as FilesToRunProvider values to the build-script
action. Replace the generated-tool fixture with a Rust binary that reads
generated runtime data through its own runfiles, covering the ordinary
macro and incoming-transition cases.

Use the default build-setting scope for Bazel 7.4.1 compatibility and
simplify the fixture executable extension handling.

Assisted-by: OpenAI Codex
@jrandolf
jrandolf force-pushed the fix/build-script-tool-inputs branch from 1e96caa to 32d6540 Compare November 25, 2026 21:16
@jrandolf

Copy link
Copy Markdown
Contributor Author

@krasimirgg Could you take another look? It is rebased on main.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo_build_script tools referenced through execpath are missing from action inputs

2 participants