81 lines
3.3 KiB
PowerShell
81 lines
3.3 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'
|
|
$git = Join-Path $Msys2Root 'usr\bin\git.exe'
|
|
|
|
function Get-ReadyCompilerVersion {
|
|
foreach ($tool in @('gcc.exe', 'g++.exe', 'cmake.exe', 'ctest.exe', 'ninja.exe', 'windres.exe')) {
|
|
if (-not (Test-Path -LiteralPath (Join-Path $bin $tool) -PathType Leaf)) {
|
|
return
|
|
}
|
|
}
|
|
if (-not (Test-Path -LiteralPath $git -PathType Leaf)) {
|
|
return
|
|
}
|
|
$version = & (Join-Path $bin 'g++.exe') -dumpfullversion
|
|
if ($LASTEXITCODE -ne 0 -or $version -notmatch '^\d+\.\d+(\.\d+)?$' -or
|
|
[version]$version -lt [version]'16.0') {
|
|
return
|
|
}
|
|
$cVersion = & (Join-Path $bin 'gcc.exe') -dumpfullversion
|
|
if ($LASTEXITCODE -ne 0 -or $cVersion -ne $version) {
|
|
return
|
|
}
|
|
$cmakeVersion = & (Join-Path $bin 'cmake.exe') --version
|
|
if ($LASTEXITCODE -ne 0 -or $cmakeVersion[0] -notmatch '^cmake version (\d+\.\d+\.\d+)' -or
|
|
[version]$Matches[1] -lt [version]'4.0') {
|
|
return
|
|
}
|
|
return $version
|
|
}
|
|
|
|
$version = Get-ReadyCompilerVersion
|
|
if ($version) {
|
|
Write-Output "MSYS2 UCRT64 GCC $version, CMake, Ninja, and Git are 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 git 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 = Get-ReadyCompilerVersion
|
|
if (-not $version) {
|
|
throw 'Expected MSYS2 UCRT64 with matching GCC 16+ compilers, windres, CMake 4+, CTest, Ninja, and Git.'
|
|
}
|
|
Write-Output "MSYS2 UCRT64 GCC $version, CMake, Ninja, and Git are ready."
|