Skip to content

Commit 69c7f47

Browse files
authored
Pin stable, nightly versions of Rust toolchain (Azure#4486)
Resolves Azure#4258
1 parent c8eb8e8 commit 69c7f47

7 files changed

Lines changed: 69 additions & 6 deletions

File tree

eng/cgmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{
2727
"component": {
2828
"type": "cargo",
29-
"cargo": { "name": "cargo-audit", "version": "0.22.0" }
29+
"cargo": { "name": "cargo-audit", "version": "0.22.1" }
3030
},
3131
"developmentDependency": true
3232
},

eng/scripts/Analyze-Code.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Set-StrictMode -Version 2.0
2222
. ([System.IO.Path]::Combine($PSScriptRoot, '..', 'common', 'scripts', 'common.ps1'))
2323
. ([System.IO.Path]::Combine($PSScriptRoot, 'shared', 'Cargo.ps1'))
2424

25+
$resolvedToolchain = [Channels]::Resolve($Toolchain)
26+
2527
Write-Host @"
2628
Analyzing code with
2729
RUSTFLAGS: '${env:RUSTFLAGS}'
@@ -147,7 +149,7 @@ if (!$SkipPackageAnalysis) {
147149
Invoke-LoggedCommand "&$verifyKeywordsScript $packageManifestPath" -GroupOutput
148150

149151
if ($Toolchain -eq 'nightly') {
150-
Invoke-LoggedCommand "cargo +nightly docs-rs --manifest-path $packageManifestPath" -GroupOutput
152+
Invoke-LoggedCommand "cargo +$resolvedToolchain docs-rs --manifest-path $packageManifestPath" -GroupOutput
151153
}
152154

153155
if ($checkApiSupersetCrates -contains $package.Name) {

eng/scripts/Language-Settings.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,60 @@ $SupportsTestResourcesDotenv = $true
99

1010
. (Join-Path $EngCommonScriptsDir "Helpers" "PSModule-Helpers.ps1")
1111

12+
# Channel aliases used throughout scripts to pin channels.
13+
# Lazy-initialized static property accessors cache values on first access.
14+
class Channels {
15+
hidden static [string] $_repoRoot = $null
16+
hidden static [string] $_nightly = 'nightly-2026-04-14'
17+
hidden static [string] $_stable = $null
18+
hidden static [string] $_msrv = $null
19+
20+
static [string] Nightly() {
21+
return [Channels]::_nightly
22+
}
23+
24+
static [string] Stable() {
25+
if (-not [Channels]::_stable) {
26+
$path = [System.IO.Path]::Combine([Channels]::_repoRoot, 'rust-toolchain.toml')
27+
[string] $content = Get-Content -Raw $path
28+
[Channels]::_stable = if ($content -Match 'channel\s+=\s+"([^"]+)"') {
29+
$Matches[1]
30+
} else {
31+
Write-Warning "Failed to get stable channel from $path"
32+
'stable'
33+
}
34+
}
35+
return [Channels]::_stable
36+
}
37+
38+
static [string] MSRV() {
39+
if (-not [Channels]::_msrv) {
40+
$path = [System.IO.Path]::Combine([Channels]::_repoRoot, 'Cargo.toml')
41+
[string] $content = Get-Content -Raw $path
42+
[Channels]::_msrv = if ($content -Match 'rust-version\s+=\s+"([^"]+)"') {
43+
$Matches[1]
44+
} else {
45+
Write-Warning "Failed to get MSRV from $path"
46+
'stable'
47+
}
48+
}
49+
return [Channels]::_msrv
50+
}
51+
52+
# Resolves a toolchain alias ('stable', 'nightly', 'msrv') to its pinned version.
53+
# Any other value (e.g. an explicit version) is passed through unchanged.
54+
static [string] Resolve([string] $toolchain) {
55+
$resolved = switch ($toolchain.ToLower()) {
56+
'stable' { [Channels]::Stable() }
57+
'nightly' { [Channels]::Nightly() }
58+
'msrv' { [Channels]::MSRV() }
59+
default { $toolchain }
60+
}
61+
return $resolved
62+
}
63+
}
64+
[Channels]::_repoRoot = $RepoRoot
65+
1266
function SetPackageVersion ($PackageName, $Version, $ServiceDirectory, $ReleaseDate, $ReplaceLatestEntryTitle = $true) {
1367
if ($null -eq $ReleaseDate) {
1468
$ReleaseDate = Get-Date -Format "yyyy-MM-dd"

eng/scripts/Test-Packages.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $ErrorActionPreference = 'Stop'
99
Set-StrictMode -Version 2.0
1010
. "$PSScriptRoot/../common/scripts/common.ps1"
1111

12+
$resolvedToolchain = [Channels]::Nightly()
13+
1214
# Helper function to run cargo test with JSON output
1315
function Invoke-CargoTestWithJsonOutput (
1416
[string]$TestParams,
@@ -21,7 +23,7 @@ function Invoke-CargoTestWithJsonOutput (
2123
# and uploaded to DevOps for display in the Tests tab
2224
# (requires -Z unstable-options)
2325
$result = Invoke-LoggedCommand `
24-
"cargo +nightly test $TestParams --manifest-path $ManifestPath --all-features --no-fail-fast -- --format json -Z unstable-options" `
26+
"cargo +$resolvedToolchain test $TestParams --manifest-path $ManifestPath --all-features --no-fail-fast -- --format json -Z unstable-options" `
2527
-GroupOutput `
2628
-DoNotExitOnFailedExitCode
2729

eng/scripts/Test-Semver.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ param(
1414
. ([System.IO.Path]::Combine($PSScriptRoot, '..', 'common', 'scripts', 'common.ps1'))
1515
. ([System.IO.Path]::Combine($PSScriptRoot, 'shared', 'Cargo.ps1'))
1616

17+
$resolvedToolchain = [Channels]::Resolve($Toolchain)
18+
1719
function Get-OutputPackages($workspacePackages) {
1820
$packages = @()
1921
switch ($PsCmdlet.ParameterSetName) {
@@ -64,7 +66,7 @@ $finalExitCode = 0
6466
foreach ($package in $outputPackages) {
6567
$packageName = $package.name
6668
$manifestPath = $package.manifest_path
67-
$output = Invoke-LoggedCommand "cargo +$Toolchain semver-checks --manifest-path $manifestPath" -DoNotExitOnFailedExitCode -GroupOutput 2>&1
69+
$output = Invoke-LoggedCommand "cargo +$resolvedToolchain semver-checks --manifest-path $manifestPath" -DoNotExitOnFailedExitCode -GroupOutput 2>&1
6870
if ($output -match 'error: no library targets found in package `(?<name>[\w_]+)`' -and $Matches['name'] -eq $packageName) {
6971
LogWarning "$packageName base version is a placeholder and will be ignored"
7072
continue

eng/scripts/Update-PackageVersion.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ $ErrorActionPreference = 'Stop'
4343
Set-StrictMode -Version 2.0
4444
. "$PSScriptRoot/../common/scripts/common.ps1"
4545

46+
$resolvedToolchain = [Channels]::Nightly()
47+
4648
Write-Host "Getting package properties for $PackageName in $ServiceDirectory."
4749
$pkgProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
4850

@@ -83,8 +85,8 @@ if ($content -ne $updated) {
8385
$updated | Set-Content -Path $tomlPath -Encoding utf8 -NoNewLine
8486
Write-Host "Updated version in $tomlPath from $($pkgProperties.Version) to $packageSemVer."
8587

86-
Write-Host "Updaging dependencies in Cargo.toml files."
87-
Invoke-LoggedCommand "cargo +nightly -Zscript '$RepoRoot/eng/scripts/update-pathversions.rs' update" | Out-Null
88+
Write-Host "Updating dependencies in Cargo.toml files."
89+
Invoke-LoggedCommand "cargo +$resolvedToolchain -Zscript '$RepoRoot/eng/scripts/update-pathversions.rs' update" | Out-Null
8890

8991
Write-Host "Updating Cargo.lock using 'cargo update --workspace'."
9092
Invoke-LoggedCommand "cargo update --workspace" | Out-Null

rust-toolchain.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[toolchain]
2+
channel = "1.95"
23
components = [
34
"rustc",
45
"rustfmt",

0 commit comments

Comments
 (0)