[CmdletBinding()] param() $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest function Invoke-StrictNative { param( [Parameter(Mandatory = $true)] [string]$FilePath, [Parameter(Mandatory = $true)] [string[]]$ArgumentList ) & $FilePath @ArgumentList if ($LASTEXITCODE -ne 0) { throw "Command failed with exit code ${LASTEXITCODE}: $FilePath $($ArgumentList -join ' ')" } } function Get-OptionalCommandPath { param( [Parameter(Mandatory = $true)] [string]$Name ) $command = Get-Command -Name $Name -ErrorAction SilentlyContinue if ($null -eq $command) { return $null } return $command.Source } function Resolve-XperfPath { $commandPath = Get-OptionalCommandPath -Name 'xperf' if (-not [string]::IsNullOrWhiteSpace($commandPath)) { return $commandPath } $candidates = @() foreach ($root in @($env:ProgramFiles, ${env:ProgramFiles(x86)})) { if (-not [string]::IsNullOrWhiteSpace($root)) { $candidates += (Join-Path $root 'Windows Kits\10\Windows Performance Toolkit\xperf.exe') } } foreach ($candidate in $candidates) { if (Test-Path -LiteralPath $candidate) { return $candidate } } return $null } function Ensure-CargoBinstall { if ($null -ne (Get-Command -Name 'cargo-binstall' -ErrorAction SilentlyContinue)) { return } Write-Host 'cargo-binstall is missing; installing it first so required Jade tools can use binary releases when available.' Invoke-StrictNative -FilePath cargo -ArgumentList @("install", "cargo-binstall", "--locked") } function Test-IsElevated { if (-not $IsWindows) { return $false } $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = [Security.Principal.WindowsPrincipal]::new($identity) return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } Invoke-StrictNative -FilePath rustup -ArgumentList @("toolchain", "install", "nightly") Invoke-StrictNative -FilePath rustup -ArgumentList @("component", "add", "miri", "--toolchain", "nightly") Invoke-StrictNative -FilePath rustup -ArgumentList @("component", "add", "rust-src", "--toolchain", "nightly") Invoke-StrictNative -FilePath rustup -ArgumentList @("component", "add", "llvm-tools-preview", "--toolchain", "stable") Invoke-StrictNative -FilePath rustup -ArgumentList @("component", "add", "llvm-tools-preview", "--toolchain", "nightly") Ensure-CargoBinstall Invoke-StrictNative -FilePath cargo -ArgumentList @("binstall", "-y", "cargo-nextest", "cargo-deny", "cargo-udeps", "cargo-llvm-cov", "cargo-expand", "cargo-bloat", "cargo-asm", "cargo-llvm-lines", "cargo-geiger", "cargo-outdated", "cargo-audit") Invoke-StrictNative -FilePath cargo -ArgumentList @("install", "cargo-fuzz", "--locked") Invoke-StrictNative -FilePath cargo -ArgumentList @("binstall", "-y", "flamegraph") Invoke-StrictNative -FilePath cargo -ArgumentList @("binstall", "-y", "samply") Invoke-StrictNative -FilePath cargo -ArgumentList @("binstall", "-y", "sccache") Invoke-StrictNative -FilePath cargo -ArgumentList @("binstall", "-y", "just", "bacon") if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) { Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force -AllowClobber -Repository PSGallery } if ($IsWindows) { if (-not (Test-IsElevated)) { Write-Warning 'cargo flamegraph falls back to blondie on Windows when DTrace is not configured, and blondie requires an elevated shell.' } if ([string]::IsNullOrWhiteSpace((Resolve-XperfPath))) { Write-Warning 'samply is installed, but recording on Windows still needs xperf from Windows Performance Toolkit (WPT).' } }