fix: use channel key not version from rust-toolchain.toml (#304)

* fix(rust): pull version from channel, not version field

fixes #296

* test: use correct rust-toolchain.toml channel key

* docs: update rust version specification docs

* refactor: inline ifs

* test: assert against mise-specified rust version

* test: update snapshot
This commit is contained in:
Michael Bianco
2025-10-21 20:34:03 -06:00
committed by GitHub
parent d7302e8ea6
commit 9de51aed8f
6 changed files with 28 additions and 15 deletions
@@ -38,6 +38,10 @@
{
"path": "/mise/shims"
},
{
"dest": ".tool-versions",
"src": ".tool-versions"
},
{
"customName": "create mise config",
"name": "mise.toml",
+15 -7
View File
@@ -330,20 +330,28 @@ func (p *RustProvider) InstallMisePackages(ctx *generate.GenerateContext, miseSt
}
}
if cargoToml != nil {
if cargoToml.Package.RustVersion != "" {
// Newer versions of Rust allow the `rust-version` field in Cargo.toml
if version := utils.ExtractSemverVersion(cargoToml.Package.RustVersion); version != "" {
miseStep.Version(rust, version, "Cargo.toml")
}
if cargoToml != nil && cargoToml.Package.RustVersion != "" {
// Newer versions of Rust allow the `rust-version` field in Cargo.toml
if version := utils.ExtractSemverVersion(cargoToml.Package.RustVersion); version != "" {
miseStep.Version(rust, version, "Cargo.toml")
}
}
if toolchain, err := parseRustToolchain(ctx); err == nil {
if version := utils.ExtractSemverVersion(toolchain.Toolchain.Version); version != "" {
versionSource := toolchain.Toolchain.Channel
// TODO: Remove support for deprecated Version field in a future release
if toolchain.Toolchain.Version != "" {
ctx.Logger.LogWarn("The 'version' field in rust-toolchain.toml is deprecated and will be removed in a future release. Please use 'channel' instead.")
if versionSource == "" {
versionSource = toolchain.Toolchain.Version
}
}
if version := utils.ExtractSemverVersion(versionSource); version != "" {
miseStep.Version(rust, version, "rust-toolchain.toml")
}
}
miseStep.UseMiseVersions(ctx, []string{"rust"})
}
var wasmRegex = regexp.MustCompile(`target\s*=\s*"wasm32-wasi"`)
+6 -5
View File
@@ -15,12 +15,13 @@ Your project will be detected as a Rust application if any of these conditions a
The Rust version is determined in the following order:
- Set via the `package.edition` field in the `Cargo.toml` file
- Set via the `RAILPACK_RUST_VERSION` environment variable
- Read from the `.rust-version` or `rust-version.txt` file
- Any mise-supported version file (`mise.toml`, `.tool-versions`, etc).
- Read from the `toolchain.channel` field in the `rust-toolchain.toml` file
- Read from the `package.rust-version` field in the `Cargo.toml` file
- Read from the `toolchain.version` field in the `rust-toolchain.toml` file
- Defaults to `1.85.1`
- Read from the `.rust-version` or `rust-version.txt` file
- Set via the `RAILPACK_RUST_VERSION` environment variable
- Set via the `package.edition` field in the `Cargo.toml` file
- Defaults to `1.89`
## Runtime Variables
@@ -0,0 +1 @@
rust 1.88.0
@@ -1,5 +1,5 @@
[
{
"expectedOutput": "Hello from rust (rustc 1.89.0)"
"expectedOutput": "Hello from rust (rustc 1.88.0)"
}
]
@@ -1,4 +1,3 @@
[toolchain]
channel = "nightly-2024-08-12"
version = "1.59.0"
channel = "1.59.0"
profile = "minimal"