148 lines
6.0 KiB
PowerShell
148 lines
6.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Pack a standalone, MSYS2-free portable reims-vgpu runtime bundle for Windows x64.
|
|
|
|
.DESCRIPTION
|
|
Collects reims-ctl.exe, reims-util.exe, and the self-contained QEMU directory
|
|
(with its bundled CLANG64/libva DLLs and share/ data), generates manifest.json
|
|
with SHA-256 hashes, copies NOTICE.md and upstream LICENSE files, and compresses
|
|
the bundle into a .tar.zst archive (falling back to .zip if zstd is unavailable).
|
|
|
|
.EXAMPLE
|
|
.\scripts\pack-runtime.ps1
|
|
.\scripts\pack-runtime.ps1 -OutDir D:\Data\reims-go\releases -ZstdLevel 15
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$ReimsRepo = 'D:\DevTools\reims-vgpu',
|
|
[string]$CargoBin = 'D:\DevTools\cargo\bin',
|
|
[string]$QemuDir = 'D:\Data\macos-vm-lab\reims\data\reims-ctl\qemu\current',
|
|
[string]$OutDir = 'D:\Data\reims-go\releases',
|
|
[string]$TempRoot = 'D:\Build\Temp',
|
|
[int]$ZstdLevel = 15
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Resolve-Zstd {
|
|
$candidates = @(
|
|
(Get-Command zstd.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source),
|
|
'D:\DevTools\msys64\usr\bin\zstd.exe',
|
|
'D:\DevTools\msys64\clang64\bin\zstd.exe'
|
|
) | Where-Object { $_ -and (Test-Path -LiteralPath $_) }
|
|
return ($candidates | Select-Object -First 1)
|
|
}
|
|
|
|
# 1. Verify inputs
|
|
$ctlExe = Join-Path $CargoBin 'reims-ctl.exe'
|
|
$utilExe = Join-Path $CargoBin 'reims-util.exe'
|
|
$qemuExe = Join-Path $QemuDir 'bin\qemu-system-x86_64.exe'
|
|
foreach ($p in @($ctlExe, $utilExe, $qemuExe)) {
|
|
if (-not (Test-Path -LiteralPath $p)) {
|
|
throw "Required runtime binary not found: $p"
|
|
}
|
|
}
|
|
|
|
$commit = (git -C $ReimsRepo rev-parse --short HEAD).Trim()
|
|
$fullCommit = (git -C $ReimsRepo rev-parse HEAD).Trim()
|
|
$qemuVersionLine = (& $qemuExe --version | Select-Object -First 1).Trim()
|
|
$utilVersionLine = (& $utilExe --version | Select-Object -First 1).Trim()
|
|
|
|
$bundleName = "reims-runtime-win-x64-$commit"
|
|
$stageRoot = Join-Path $TempRoot "pack-$bundleName"
|
|
$bundleDir = Join-Path $stageRoot $bundleName
|
|
|
|
if (Test-Path -LiteralPath $stageRoot) { Remove-Item -Recurse -Force -LiteralPath $stageRoot }
|
|
New-Item -ItemType Directory -Force -Path "$bundleDir\bin", "$bundleDir\qemu", "$bundleDir\licenses", $OutDir | Out-Null
|
|
|
|
Write-Host "==> Staging $bundleName ..."
|
|
Copy-Item -LiteralPath $ctlExe -Destination "$bundleDir\bin\reims-ctl.exe"
|
|
Copy-Item -LiteralPath $utilExe -Destination "$bundleDir\bin\reims-util.exe"
|
|
|
|
# Resolve junction target so robocopy/copy gets real files cleanly
|
|
$resolvedQemu = (Get-Item -LiteralPath $QemuDir).Target
|
|
if (-not $resolvedQemu) { $resolvedQemu = $QemuDir }
|
|
Copy-Item -Path "$resolvedQemu\*" -Destination "$bundleDir\qemu" -Recurse -Force
|
|
|
|
# Copy NOTICE.md and upstream license(s)
|
|
$repoRoot = Split-Path -Parent $PSScriptRoot
|
|
Copy-Item -LiteralPath (Join-Path $repoRoot 'NOTICE.md') -Destination "$bundleDir\NOTICE.md"
|
|
$upstreamLicense = Join-Path $ReimsRepo 'LICENSE'
|
|
if (Test-Path -LiteralPath $upstreamLicense) {
|
|
Copy-Item -LiteralPath $upstreamLicense -Destination "$bundleDir\licenses\reims-vgpu-LICENSE.txt"
|
|
}
|
|
$qemuLicense = Join-Path $ReimsRepo 'vendor\qemu\COPYING'
|
|
if (Test-Path -LiteralPath $qemuLicense) {
|
|
Copy-Item -LiteralPath $qemuLicense -Destination "$bundleDir\licenses\qemu-COPYING.txt"
|
|
}
|
|
|
|
# 2. Compute file inventory & key hashes
|
|
$allFiles = Get-ChildItem -LiteralPath $bundleDir -Recurse -File
|
|
$rawBytes = ($allFiles | Measure-Object Length -Sum).Sum
|
|
$dllCount = @(Get-ChildItem -Path "$bundleDir\qemu\bin\*.dll" -ErrorAction SilentlyContinue).Count
|
|
|
|
$keyFiles = @(
|
|
'bin/reims-ctl.exe',
|
|
'bin/reims-util.exe',
|
|
'qemu/bin/qemu-system-x86_64.exe',
|
|
'qemu/bin/qemu-img.exe',
|
|
'qemu/bin/reims-vgpu-compile.exe'
|
|
)
|
|
$hashes = [ordered]@{}
|
|
foreach ($rel in $keyFiles) {
|
|
$fp = Join-Path $bundleDir ($rel -replace '/', '\')
|
|
if (Test-Path -LiteralPath $fp) {
|
|
$hashes[$rel] = (Get-FileHash -Algorithm SHA256 -LiteralPath $fp).Hash.ToLowerInvariant()
|
|
}
|
|
}
|
|
|
|
$manifest = [ordered]@{
|
|
schema_version = 1
|
|
name = $bundleName
|
|
platform = 'windows-x86_64'
|
|
upstream_repo = 'https://github.com/steelbrain/reims-vgpu'
|
|
commit = $commit
|
|
full_commit = $fullCommit
|
|
qemu_version = $qemuVersionLine
|
|
util_version = $utilVersionLine
|
|
built_at = (Get-Date).ToString('o')
|
|
file_count = $allFiles.Count
|
|
dll_count = $dllCount
|
|
raw_bytes = $rawBytes
|
|
sha256 = $hashes
|
|
}
|
|
$manifest | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath "$bundleDir\manifest.json" -Encoding utf8
|
|
|
|
# 3. Compress
|
|
$zstd = Resolve-Zstd
|
|
$archivePath = $null
|
|
if ($zstd) {
|
|
$tarPath = Join-Path $stageRoot "$bundleName.tar"
|
|
$archivePath = Join-Path $OutDir "$bundleName.tar.zst"
|
|
Write-Host "==> Creating tar archive..."
|
|
& tar.exe -cf $tarPath -C $stageRoot $bundleName
|
|
if ($LASTEXITCODE -ne 0) { throw "tar.exe failed with exit code $LASTEXITCODE" }
|
|
Write-Host "==> Compressing with zstd (level $ZstdLevel, multi-threaded)..."
|
|
& $zstd -T0 -$ZstdLevel -f $tarPath -o $archivePath
|
|
if ($LASTEXITCODE -ne 0) { throw "zstd failed with exit code $LASTEXITCODE" }
|
|
} else {
|
|
$archivePath = Join-Path $OutDir "$bundleName.zip"
|
|
Write-Host "==> zstd not found; compressing with Compress-Archive (.zip)..."
|
|
Compress-Archive -Path $bundleDir -DestinationPath $archivePath -Force
|
|
}
|
|
|
|
$archiveSizeMB = [math]::Round((Get-Item -LiteralPath $archivePath).Length / 1MB, 1)
|
|
$rawSizeMB = [math]::Round($rawBytes / 1MB, 1)
|
|
$archiveHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $archivePath).Hash.ToLowerInvariant()
|
|
"$archiveHash $(Split-Path -Leaf $archivePath)" | Set-Content -LiteralPath "$archivePath.sha256" -Encoding ascii
|
|
|
|
# 4. Clean staging dir
|
|
Remove-Item -Recurse -Force -LiteralPath $stageRoot
|
|
|
|
Write-Host ""
|
|
Write-Host "==> Done!" -ForegroundColor Green
|
|
Write-Host " Archive : $archivePath"
|
|
Write-Host " Raw : $rawSizeMB MB ($($allFiles.Count) files, $dllCount DLLs)"
|
|
Write-Host " Packed : $archiveSizeMB MB (ratio $([math]::Round($archiveSizeMB / $rawSizeMB * 100, 1))%)"
|
|
Write-Host " SHA256 : $archiveHash"
|