rules_rust archive is fetched by every consumer through register_toolchains("@rust_toolchains//:all")
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- build-system
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Starlark
- Star
- 857
- Fork
- 701
- Merge trung bình
- 4 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 46
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bazelbuild/rules_rust
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfilesCó thể đã có người làm @Wito-1 đã nhận 65 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
bazelbuild/rules_rust#4309 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain conditionCó thể đã có người làm @Mattbusel đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
bazelbuild/rules_rust#4266 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
rust.toolchain(strip_level = ...) is silently ignoredCó thể đã có người làm @Mattbusel đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
bazelbuild/rules_rust#4223 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 90/100
bazelbuild/rules_rust#4152 · 1 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
awaiting-response
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bazelbuild/rules_rust#3599 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của bazelbuild/rules_rust
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
bazelbuild/apple_support#707 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
blocky: new version 0.38.0Đang mởout-of-date
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blast/large refactor risk/low spend-dem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
chriskelly/MusicWall#87 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
neilotoole/sq#1503 ·
Maintainer thường phản hồi trong vòng 1 ngày