Skip to content

Add system_sysroot to rust_toolchain for pre-installed toolchains#3920

Closed
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
rejuvenile:feat-system-sysroot
Closed

Add system_sysroot to rust_toolchain for pre-installed toolchains#3920
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
rejuvenile:feat-system-sysroot

Conversation

@rejuvenile
Copy link

Summary

  • Adds a system_sysroot attribute to rust_toolchain that specifies an absolute path to a pre-installed Rust toolchain on build workers
  • When set, Rust toolchain files (~670MB) are excluded from action inputs, significantly reducing transfer overhead for remote execution
  • RUSTC, RUSTDOC, CARGO paths in build scripts and make variables are redirected to the system-installed binaries
  • CC toolchain files and custom linker inputs are preserved as action inputs

Motivation

When using remote execution (or local builds with --disk_cache), every Rustc action packages the entire Rust sysroot as inputs. For a typical nightly toolchain this is ~670MB of files that must be uploaded, hashed, and transferred per action. If the remote workers already have the toolchain installed (e.g. via container image or system package), this transfer is pure overhead.

Setting system_sysroot = "/path/to/toolchain" on rust_toolchain tells rules_rust to use the pre-installed toolchain directly, eliminating the transfer cost.

Test plan

  • Verify builds succeed with system_sysroot set to a valid rustup toolchain path
  • Verify builds still succeed without system_sysroot set (default behavior unchanged)
  • Verify remote execution works with pre-installed toolchain on workers

🤖 Generated with Claude Code

When using remote execution with a locally-installed Rust toolchain,
the entire sysroot (~670MB) is transferred per action. This adds a
`system_sysroot` attribute to `rust_toolchain` that tells rules_rust
the sysroot is pre-installed on workers, avoiding the transfer.

When `system_sysroot` is set:
- Rust toolchain files are excluded from action inputs
- RUSTC, RUSTDOC, CARGO paths point to system-installed binaries
- Make variable expansion uses system paths
- CC toolchain and custom linker inputs are preserved
@google-cla
Copy link

google-cla bot commented Mar 24, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

Thanks! Could this be a repository rule instead? Much like @rules_cc//cc/private/toolchain/cc_configure.bzl%cc_configure?

@rejuvenile rejuvenile closed this Mar 24, 2026
@rejuvenile rejuvenile deleted the feat-system-sysroot branch March 24, 2026 22:42
@rejuvenile
Copy link
Author

@UebelAndre I screwed up this PR slightly, so recreated it at #3928. I'll make those changes there. Thanks for the quick response!

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.

3 participants