Conversation
A repository that has a rust-toolchain.toml for rustup and cargo has to write the same version a second time in MODULE.bazel, and nothing keeps the two in step. The new rust_toolchain_file attribute on rust.toolchain reads the file instead, with toml.bzl: channel becomes versions (it must be an exact release, since rules_rust does not resolve stable or 1.85 the way rustup does), targets add to extra_target_triples, and rustc-dev in components enables dev_components. Setting versions as well is an error. Fixes bazelbuild#2753
u9g
force-pushed
the
rust-toolchain-file
branch
from
September 25, 2026 08:54
9f3825f to
b03f74e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A repository that has a
rust-toolchain.tomlfor rustup and cargo has to write the same version a second time inMODULE.bazel, and nothing keeps the two in step (#2753). This is the toml.bzl version of #3792 that @UebelAndre asked for there.rust.toolchain(rust_toolchain_file = "//:rust-toolchain.toml")reads the file with toml.bzl, which is a newbazel_dep:channelbecomesversions. It must be an exact release (1.85.0,nightly-2025-01-01,beta-2025-01-01): rules_rust downloads a fixed release, and resolvingstableor1.85to one is something rustup does with the network, so those fail with a message saying so.targetsare added toextra_target_triples.rustc-devincomponentsenablesdev_components.versionsas well is an error, so neither attribute silently does nothing.module_ctx.readwatches the file, so editing it re-evaluates the extension.Tested with the unit tests in
test/unit/rust_toolchain_file, and by pointingexamples/hello_world_no_cargoat arust-toolchain.toml(included, so CI keeps exercising the attribute): withchannel = "1.97.0"@rust_toolchainsregistersrust_analyzer_1.97.0and only stable toolchains,channel = "1.98"fails with the exact-release message, and addingversionsfails with the both-set message.Fixes #2753