rules_rust archive is fetched by every consumer through register_toolchains("@rust_toolchains//:all")
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- build-system
Research direction
Start with the register_toolchains call in MODULE.bazel (lines 46-53) and the BUILD_for_toolchain generator in rust/private/repository_utils.bzl, which produces the @rust_toolchains hub. The proposal needs a small toolchain-types package that the hub can reference without loading the full @rules_rust archive. Done would mean a consumer that never requests a Rust toolchain no longer fetches @rules_rust+. This is design work across module layout and toolchain resolution, so confirm the approach with maintainers first.
Written by the indexing model from the issue text.
Description
Problem
A consumer that never builds Rust still downloads the whole rules_rust source archive (66.6 MB for 0.75.0, rules_rust-0.75.0.tar.gz) as soon as rules_rust is anywhere in its module graph. A common way in is a transitive non-dev bazel_dep (for example protobuf 37.0-rc3 depends on rules_rust 0.69.0).
The cause is rules_rust's own MODULE.bazel (0.75.0, lines 46-53):
rust = use_extension("//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")
use_repo(rust, "rust_toolchains")
register_toolchains(
"@rust_toolchains//:all",
)
Bazel resolves every registered toolchain() target when it computes the toolchain candidates, so it loads each toolchain_type, target_settings and constraint label. The @rust_toolchains hub (generated by BUILD_for_toolchain in rust/private/repository_utils.bzl) is load-free, but every entry uses toolchain_type = "@rules_rust//rust:toolchain_type" (and, for the other tool kinds, the matching types in @rules_rust). Reading that package needs the @rules_rust repository, so Bazel fetches and extracts the full archive even though no Rust toolchain is ever requested. This matches how Bazel 9 declares toolchain_type as a label with mandatoryProviders(ToolchainTypeInfo).
Repro
I have not built this standalone; this is derived from reading the sources and from a downstream tracking issue.
# MODULE.bazel
module(name = "repro")
bazel_dep(name = "rules_rust", version = "0.75.0")
Then run bazel fetch //... (or any build that needs toolchain resolution, such as a cc or python target in a larger graph). @rules_rust+ is downloaded and extracted although no target uses it. bazel mod graph shows rules_rust reached as a plain dependency.
Cost
66.6 MB download and about 228 MB extracted for every consumer, including CI cold starts, per output base. It is separate from the rustc/cargo downloads discussed in protocolbuffers/protobuf#30684, which only happen with crate_universe.
Proposed fix
Move what the hub points at out of the big archive:
- Put the toolchain type targets (
toolchain_type, and the types for rustfmt, cargo, rust_analyzer, rustdoc etc.) in a small module (for examplerules_rust_toolchain_types, a few KB, no loads).rules_rustdepends on it and re-exports withalias, so existing@rules_rust//rust:toolchain_typelabels keep working. - Make the generated hub reference those types and use only
@platformsconstraints andtarget_settingsthat live in the same small module. - The
toolchain =targets inside the per-platform repos can keep loading@rules_rust//rust:toolchain.bzl; they are only resolved after a toolchain is selected.
Smaller mitigation: shrink the release tarball (strip examples/, test/, extensions/ unused by consumers).
Assisted by Claude.
- Dominant language
- Starlark
- Stars
- 857
- Forks
- 701
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 46
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_rust
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfilesPossibly taken @Wito-1 claimed this 65 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
bazelbuild/rules_rust#4309 ·
Maintainers usually reply within 3 days
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain conditionPossibly taken @Mattbusel claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
bazelbuild/rules_rust#4266 ·
Maintainers usually reply within 3 days
-
rust.toolchain(strip_level = ...) is silently ignoredPossibly taken @Mattbusel claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
bazelbuild/rules_rust#4223 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
bazelbuild/rules_rust#4152 · 1 reaction ·
Maintainers usually reply within 3 days
-
awaiting-response
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bazelbuild/rules_rust#3599 · 1 comment ·
Maintainers usually reply within 3 days
All issues in bazelbuild/rules_rust
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
bazelbuild/apple_support#707 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
out-of-date
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
Maintainers usually reply within 1 day
-
blast/large refactor risk/low spend-dem
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
chriskelly/MusicWall#87 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
neilotoole/sq#1503 ·
Maintainers usually reply within 1 day