Files
FluidSimCpp/tools/Setup-Windows.ps1

50 lines
2.7 KiB
PowerShell

# Install a portable GCC/GDB/Ninja toolchain for the Windows CMake preset.
# Visual Studio and administrator access are not required.
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$toolRoot = Join-Path $env:LOCALAPPDATA 'FluidSimTools'
$compilerBin = Join-Path $toolRoot 'mingw64/bin'
$requiredTools = @('gcc.exe', 'g++.exe', 'gdb.exe', 'ninja.exe')
$missingTools = @($requiredTools | Where-Object { -not (Test-Path (Join-Path $compilerBin $_)) })
if ($missingTools.Count -eq 0) {
Write-Output "Toolchain is already installed in $compilerBin"
& (Join-Path $compilerBin 'g++.exe') --version
exit $LASTEXITCODE
}
# Use the GCC-only x64 UCRT build published by WinLibs, excluding the larger LLVM bundle.
$release = Invoke-RestMethod 'https://api.github.com/repos/brechtsanders/winlibs_mingw/releases/latest'
$archive = $release.assets | Where-Object {
$_.name -match '^winlibs-x86_64-posix-seh-gcc-.*ucrt.*\.zip$' -and $_.name -notmatch 'llvm'
} | Select-Object -First 1
if (-not $archive) { throw 'The latest WinLibs release has no GCC-only x64 UCRT ZIP.' }
$checksumAsset = $release.assets | Where-Object { $_.name -eq "$($archive.name).sha256" } | Select-Object -First 1
if (-not $checksumAsset) { throw 'The WinLibs archive has no SHA-256 checksum.' }
New-Item -ItemType Directory -Force $toolRoot | Out-Null
$downloadPath = Join-Path ([IO.Path]::GetTempPath()) ("fluidsim-toolchain-" + [guid]::NewGuid() + '.zip')
try {
Write-Output "Downloading $($archive.name) ..."
Invoke-WebRequest -UseBasicParsing $archive.browser_download_url -OutFile $downloadPath
$checksumText = (Invoke-WebRequest -UseBasicParsing $checksumAsset.browser_download_url).Content
if ($checksumText -is [byte[]]) { $checksumText = [Text.Encoding]::UTF8.GetString($checksumText) }
$expectedHash = [regex]::Match([string]$checksumText, '(?i)\b[0-9a-f]{64}\b').Value
if (-not $expectedHash -or (Get-FileHash $downloadPath -Algorithm SHA256).Hash -ne $expectedHash) {
throw 'The toolchain archive failed SHA-256 verification.'
}
Write-Output "Extracting to $toolRoot ..."
& tar.exe -xf $downloadPath -C $toolRoot
if ($LASTEXITCODE -ne 0) { throw 'Toolchain extraction failed.' }
foreach ($tool in $requiredTools) {
if (-not (Test-Path (Join-Path $compilerBin $tool))) { throw "Missing tool after extraction: $tool" }
}
& (Join-Path $compilerBin 'g++.exe') --version
if ($LASTEXITCODE -ne 0) { throw 'The installed compiler could not start.' }
Write-Output 'Ready. In VS Code, select FluidSim desktop in Run and Debug, then press F5.'
} finally {
if (Test-Path -LiteralPath $downloadPath) { Remove-Item -LiteralPath $downloadPath }
}