🐛 Resolve a working zstd for Windows runtime archives

This commit is contained in:
YXC0915 committed 2026-12-03 01:02:03 +08:00
1 parent 1bc441947c
commit 116ef68ae8
3 files changed
+29 -11

No files matched your search

@@ -33,9 +33,10 @@ param(
)
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot 'runtime-zstd.ps1')
$localDb = Join-Path $Msys2 'var\lib\pacman\local'
$bash = Join-Path $Msys2 'usr\bin\bash.exe'
$zstd = Join-Path $Msys2 'usr\bin\zstd.exe'
$zstd = Resolve-Zstd -Msys2 $Msys2
function Write-Utf8([string]$path, [string]$text) {
[IO.File]::WriteAllText($path, $text.Replace("`r`n", "`n"), [Text.UTF8Encoding]::new($false))
@@ -59,6 +59,7 @@ param(
)
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot 'runtime-zstd.ps1')
$repoRoot = Split-Path -Parent $PSScriptRoot
$patchesDir = Join-Path $repoRoot 'patches'
$CargoBin = Join-Path $CargoHome 'bin'
@@ -97,17 +98,7 @@ function Write-Utf8([string]$path, [string]$text) {
[IO.File]::WriteAllText($path, $text.Replace("`r`n", "`n"), [Text.UTF8Encoding]::new($false))
}
function Resolve-Zstd {
@(
(Get-Command zstd.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source),
(Join-Path $Msys2 'usr\bin\zstd.exe'),
(Join-Path $Msys2 'clang64\bin\zstd.exe')
) | Where-Object { $_ -and (Test-Path -LiteralPath $_) } | Select-Object -First 1
}
function New-TarZst([string]$parent, [string]$name, [string]$archive) {
$zstd = Resolve-Zstd
if (-not $zstd) { throw 'zstd not found (install MSYS2 zstd or put zstd.exe on PATH)' }
$tar = Join-Path $TempRoot "$name.tar"
Invoke-Native 'tar.exe' @('-cf', $tar, '-C', $parent, $name)
Invoke-Native $zstd @('-T0', "-$ZstdLevel", '-q', '-f', $tar, '-o', $archive)
@@ -563,6 +554,7 @@ $manifest.raw_bytes += (Get-Item -LiteralPath "$bundleDir\manifest.json").Length
Write-Utf8 "$bundleDir\manifest.json" ($manifest | ConvertTo-Json -Depth 5)
# ── 6. Archives and sums ─────────────────────────────────────
$zstd = Resolve-Zstd -Msys2 $Msys2
Write-Host '==> Compressing runtime'
$runtimeArchive = Join-Path $OutDir "$bundleName.tar.zst"
New-TarZst $stageRoot $bundleName $runtimeArchive
@@ -0,0 +1,25 @@
function Resolve-Zstd([string]$Msys2) {
$candidates = @(
Get-Command zstd.exe -CommandType Application -All -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Source
Join-Path $Msys2 'usr\bin\zstd.exe'
Join-Path $Msys2 'clang64\bin\zstd.exe'
)
$failures = @()
foreach ($candidate in ($candidates | Select-Object -Unique)) {
if (-not (Test-Path -LiteralPath $candidate -PathType Leaf)) { continue }
# A binary can exist but fail to load its DLLs outside the MSYS2 shell.
try {
& $candidate --version *> $null
if ($LASTEXITCODE -eq 0) { return $candidate }
$failures += "$candidate (exit $LASTEXITCODE)"
} catch {
$failures += "$candidate ($($_.Exception.Message))"
}
}
if ($failures.Count) { throw "Could not run zstd.exe: $($failures -join '; ')" }
throw "zstd.exe not found on PATH or in MSYS2 at $Msys2"
}