Files
stoneheart_at_home/setup-toolchain.ps1

58 lines
2.6 KiB
PowerShell

param([string]$Msys2Root = $env:SETTLEMENT_MSYS2_ROOT)
$ErrorActionPreference = 'Stop'
if (-not [Environment]::Is64BitOperatingSystem) {
throw 'MSYS2 UCRT64 requires 64-bit Windows.'
}
$toolRoot = Join-Path $PSScriptRoot '.tools\toolchain'
$portableRoot = Join-Path $toolRoot 'msys64'
if (-not $Msys2Root) { $Msys2Root = $portableRoot }
$bash = Join-Path $Msys2Root 'usr\bin\bash.exe'
$bin = Join-Path $Msys2Root 'ucrt64\bin'
$compiler = Join-Path $bin 'g++.exe'
if ((Test-Path -LiteralPath $compiler -PathType Leaf) -and
(Test-Path -LiteralPath (Join-Path $bin 'cmake.exe') -PathType Leaf) -and
(Test-Path -LiteralPath (Join-Path $bin 'ninja.exe') -PathType Leaf)) {
$version = & $compiler -dumpfullversion
if ($LASTEXITCODE -eq 0 -and $version -match '^16(\.|$)') {
Write-Output "MSYS2 UCRT64 GCC $version is ready."
return
}
}
if (-not (Test-Path -LiteralPath $bash -PathType Leaf)) {
if ([IO.Path]::GetFullPath($Msys2Root) -ne [IO.Path]::GetFullPath($portableRoot)) {
throw "MSYS2 was not found at $Msys2Root."
}
$downloadRoot = Join-Path $PSScriptRoot '.tools\downloads'
New-Item -ItemType Directory -Path $downloadRoot, $toolRoot -Force | Out-Null
$name = 'msys2-base-x86_64-20261120.tar.zst'
$archive = Join-Path $downloadRoot $name
$expected = 'adde59fcb53760bd0fd2aa3c3e8da516f03159b771dc62b77c340e4ac187fcdd'
if (-not (Test-Path -LiteralPath $archive -PathType Leaf) -or
(Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash -ne $expected) {
Invoke-WebRequest -Uri "https://repo.msys2.org/distrib/x86_64/$name" -OutFile $archive -UseBasicParsing
}
if ((Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash -ne $expected) {
throw 'MSYS2 archive hash does not match the release.'
}
& tar.exe -xf $archive -C $toolRoot
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$previousMsysSystem = $env:MSYSTEM
try {
$env:MSYSTEM = 'UCRT64'
# An MSYS2 runtime upgrade can close the first shell. Start a fresh shell for the remaining packages.
& $bash --login -c 'pacman -Syu --noconfirm'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& $bash --login -c 'pacman -Syu --needed --noconfirm mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally {
$env:MSYSTEM = $previousMsysSystem
}
$version = & $compiler -dumpfullversion
if ($LASTEXITCODE -ne 0 -or $version -notmatch '^16(\.|$)') {
throw "Expected GCC 16 in MSYS2 UCRT64. Found: $version"
}
Write-Output "MSYS2 UCRT64 GCC $version is ready."