#Requires -Version 5.1 param( [switch]$SkipTests ) $ErrorActionPreference = "Stop" $Root = Split-Path -Parent $PSScriptRoot Set-Location $Root function Test-IsInteractive { try { return [Environment]::UserInteractive -and -not [Console]::IsInputRedirected } catch { return $Host.Name -eq "ConsoleHost" } } function Ask-YesNo([string]$Prompt) { if (-not (Test-IsInteractive)) { return $false } $answer = Read-Host "$Prompt [y/N]" return $answer -match '^[Yy]([Ee][Ss])?$' } function Ensure-Rust { if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) { return } $cargoEnv = Join-Path $env:USERPROFILE ".cargo\env" if (Test-Path $cargoEnv) { # Best-effort: put cargo on PATH for this session if rustup is installed. $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin" if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) { $env:PATH = "$cargoBin;$env:PATH" } } if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Command rustc -ErrorAction SilentlyContinue)) { return } Write-Host "cargo/rustc not found." $winget = Get-Command winget -ErrorAction SilentlyContinue if ($winget -and (Ask-YesNo "Install Rust via winget (Rustlang.Rustup) now?")) { & winget install --id Rustlang.Rustup -e --accept-package-agreements --accept-source-agreements $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin" if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) { $env:PATH = "$cargoBin;$env:PATH" } } elseif (Ask-YesNo "Download and run rustup-init.exe now?") { $tmp = Join-Path $env:TEMP "rustup-init.exe" Invoke-WebRequest -Uri "https://win.rustup.rs/x86_64" -OutFile $tmp & $tmp -y $cargoBin = Join-Path $env:USERPROFILE ".cargo\bin" if ((Test-Path $cargoBin) -and ($env:PATH -notlike "*$cargoBin*")) { $env:PATH = "$cargoBin;$env:PATH" } } else { Write-Error "Install Rust from https://rustup.rs (or: winget install Rustlang.Rustup), then re-run this script." } if (-not (Get-Command cargo -ErrorAction SilentlyContinue) -or -not (Get-Command rustc -ErrorAction SilentlyContinue)) { Write-Error "Rust install finished but cargo/rustc are still not on PATH. Open a new PowerShell window and re-run." } } Ensure-Rust Write-Host "Building posprint for Windows (x64)..." if (-not $SkipTests) { cargo test if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } } cargo build --release if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $exe = Join-Path $Root "target\release\posprint.exe" if (-not (Test-Path $exe)) { Write-Error "Build failed: $exe not found" } Write-Host "OK: $exe" Get-Item $exe | Select-Object FullName, Length, LastWriteTime