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" }