rules_rust archive is fetched by every consumer through register_toolchains("@rust_toolchains//:all")
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 20/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- build-system
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Starlark
- 星标
- 857
- 派生
- 701
- 平均合并
- 4 天 7 小时
- 30 天内合并 PR
- 46
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazelbuild/rules_rust 的其他 Issue
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfiles可能已有人在做 @Wito-1 于 65 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
bazelbuild/rules_rust#4309 ·
维护者通常 3 天内回复
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain condition可能已有人在做 @Mattbusel 于 17 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
bazelbuild/rules_rust#4266 ·
维护者通常 3 天内回复
-
rust.toolchain(strip_level = ...) is silently ignored可能已有人在做 @Mattbusel 于 17 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
bazelbuild/rules_rust#4223 ·
维护者通常 3 天内回复
-
难度 1/5 1-3 小时 新手友好度 90/100
bazelbuild/rules_rust#4152 · 1 个 reaction ·
维护者通常 3 天内回复
-
awaiting-response
难度 2/5 1-3 小时 新手友好度 76/100
bazelbuild/rules_rust#3599 · 1 条评论 ·
维护者通常 3 天内回复
查看 bazelbuild/rules_rust 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
bazelbuild/apple_support#707 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
-
out-of-date
难度 2/5 1-3 小时 新手友好度 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
维护者通常 1 天内回复
-
blast/large refactor risk/low spend-dem
难度 2/5 1-3 小时 新手友好度 68/100
chriskelly/MusicWall#87 · 2 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
neilotoole/sq#1503 ·
维护者通常 1 天内回复