crate_universe silently bootstraps cargo-bazel with hardcoded DEFAULT_RUST_VERSION when no toolchain is registered, producing confusing downstream errors

オープン
#4,210 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rust

調査の方向性

rust/private/common.bzl を読み、crate.from_specs/crate.spec のエントリポイントから cargo_bootstrap_repository を追跡します。rust.toolchain(...) を省略した MODULE.bazel で再現します。フォールバックが DEFAULT_RUST_VERSION を示し、明示的なツールチェーンを登録する方法を説明する警告を出力すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

  1. 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.
  2. Run bazel build //....
  3. 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.
  4. 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
主要言語
Starlark
スター
857
フォーク
701
平均マージ
4日 7時間
マージ済み PR(30日)
46

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_rust のほかの issue

bazelbuild/rules_rust の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。