crate_universe silently bootstraps cargo-bazel with hardcoded DEFAULT_RUST_VERSION when no toolchain is registered, producing confusing downstream errors
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- build-system, tooling
Research direction
Read rust/private/common.bzl and trace cargo_bootstrap_repository from the crate.from_specs/crate.spec entry points; reproduce with a MODULE.bazel that omits rust.toolchain(...). Done when the fallback emits a warning naming DEFAULT_RUST_VERSION and explaining how to register an explicit toolchain.
Written by the indexing model from the issue text.
Description
Summary
When a Bazel module has no rust.toolchain(...) registered via
register_toolchains, crate_universe's pip.parse-equivalent
(crate.from_specs / crate.spec extension) silently falls back to
cargo_bootstrap_repository, which builds cargo-bazel from source using a
hardcoded DEFAULT_RUST_VERSION (currently "1.86.0" in rust/private/common.bzl).
If any of cargo-bazel's own pinned transitive dependencies require a newer
Rust language feature than that hardcoded version supports, the build fails
with a confusing compiler error inside a third-party crate deep in the
dependency tree (e.g. time-macros using a syntax feature stabilized after
1.86.0), with no indication that the real issue is "no toolchain was
registered, so we're bootstrapping cargo-bazel with an old pinned version."
Reproduction
- Create a Bazel module using bzlmod that depends on rules_rust's
crate_universe extension (e.g.crate.from_specs(...)), but does NOT call
rust.toolchain(...)/register_toolchains(...)anywhere in the module
or its transitive deps. - Run
bazel build //.... - Observe that cargo-bazel is built from source via
cargo_bootstrap_repository, using DEFAULT_RUST_VERSION, and that this is
not surfaced anywhere in the build output. - If cargo-bazel's own Cargo.lock pulls in a crate requiring a newer
language feature, the build fails with an opaque error[E0658] deep in a
[for tool] compilation, with no mention of the toolchain fallback.
Suggested improvement
Emit a print()/warning when cargo_bootstrap_repository is used because no
explicit toolchain was registered, e.g.:
"No rust.toolchain() registered for this module; bootstrapping cargo-bazel
from source using DEFAULT_RUST_VERSION (X.Y.Z). If the build fails with
confusing compiler errors in a [for tool] target, register an explicit
toolchain version via rust.toolchain(versions=[...])."
This would have saved significant debugging time in our case, where the fix
was simply adding an explicit rust.toolchain(edition="2021",
versions=["1.90.0"]) to MODULE.bazel.
Environment
- rules_rust 0.68.2-score (eclipse-score fork, unmodified in this code path)
- Bazel 8.6.0
- 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