rules_rust archive is fetched by every consumer through register_toolchains("@rust_toolchains//:all")

Abierto
#4,475 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
build-system

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage

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:

  1. Put the toolchain type targets (toolchain_type, and the types for rustfmt, cargo, rust_analyzer, rustdoc etc.) in a small module (for example rules_rust_toolchain_types, a few KB, no loads). rules_rust depends on it and re-exports with alias, so existing @rules_rust//rust:toolchain_type labels keep working.
  2. Make the generated hub reference those types and use only @platforms constraints and target_settings that live in the same small module.
  3. 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.

Lenguaje dominante
Starlark
Estrellas
857
Forks
701
Merge medio
4 d 7 h
PR fusionados (30 d)
46

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bazelbuild/rules_rust

Todos los issues de bazelbuild/rules_rust

Issues similares

Más issues de Build System

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.