<# .SYNOPSIS Makes sure a Rust toolchain (stable, x86_64-pc-windows-msvc) is there to build the Remote View screen host. CI calls this before packaging the agent. Does nothing while src/ScreenHost is not in the tree. Installs rustup (no modifications to the system PATH; cargo's bin folder is added to this job's PATH through GITHUB_PATH) only when cargo is missing. #> [CmdletBinding()] param( [string]$Target = 'x86_64-pc-windows-msvc' ) $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $PSScriptRoot if (-not (Test-Path (Join-Path $repoRoot 'src/ScreenHost/Cargo.toml'))) { Write-Host 'Rust: src/ScreenHost is not in this tree; nothing to install.' return } $cargoBin = Join-Path $HOME '.cargo/bin' if (-not (Get-Command cargo -ErrorAction SilentlyContinue) -and (Test-Path (Join-Path $cargoBin 'cargo.exe'))) { $env:PATH = "$cargoBin;$env:PATH" } if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { Write-Host 'Rust: installing rustup (stable, minimal profile).' $installer = Join-Path ([System.IO.Path]::GetTempPath()) 'rustup-init.exe' Invoke-WebRequest -Uri "https://static.rust-lang.org/rustup/dist/$Target/rustup-init.exe" -OutFile $installer -UseBasicParsing & $installer -y --no-modify-path --profile minimal --default-toolchain stable --default-host $Target if ($LASTEXITCODE -ne 0) { throw "rustup-init failed ($LASTEXITCODE)." } $env:PATH = "$cargoBin;$env:PATH" } # An older toolchain left on the machine (the CI runner keeps its own) is brought up to the # screen host's rust-version (Cargo.toml) before anything builds. $manifest = Get-Content (Join-Path $repoRoot 'src/ScreenHost/Cargo.toml') -Raw $required = if ($manifest -match '(?m)^rust-version\s*=\s*"([0-9.]+)"') { [version]($Matches[1] + ('.0' * (3 - $Matches[1].Split('.').Count))) } else { $null } $installed = if ((& rustc --version 2>$null) -match '^rustc ([0-9]+\.[0-9]+\.[0-9]+)') { [version]$Matches[1] } else { $null } if ($required -and (-not $installed -or $installed -lt $required)) { Write-Host "Rust: rustc $installed is older than the screen host's rust-version $required; updating stable." & rustup toolchain install stable --profile minimal --no-self-update if ($LASTEXITCODE -ne 0) { throw "rustup toolchain install stable failed ($LASTEXITCODE)." } & rustup default stable if ($LASTEXITCODE -ne 0) { throw "rustup default stable failed ($LASTEXITCODE)." } } & rustup target add $Target if ($LASTEXITCODE -ne 0) { throw "rustup target add $Target failed ($LASTEXITCODE)." } # Later steps of the same job find cargo too. if ($env:GITHUB_PATH) { $cargoBin | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8 } & cargo --version