<# .SYNOPSIS Pack a portable reims-vgpu runtime for Windows x64, its matching source package, and SHA256SUMS.txt, ready to publish as a GitHub Release. .DESCRIPTION Outputs, in -OutDir (all five are assets of one GitHub Release): reims-runtime-win-x64-.tar.zst runtime (bin/, qemu/, manifest.json, NOTICE.md, licenses/, patches/, MSYS2-PACKAGES.txt) reims-runtime-src-.tar.zst corresponding source: pristine upstream trees at the built commits + patches/ reims-runtime-msys2-src-.tar.zst sources of the copyleft MSYS2 packages whose DLLs are bundled (pack-msys2-sources.ps1) reims-runtime-symbols-.tar.zst detached debug files for the five programs SHA256SUMS.txt all four archives manifest.json (schema 2) states what the package was really built from: upstream commit, vendor/qemu commit, reims-util and metal2vulkan commits, every local patch with its SHA256, and the channel. A package built with patches is never described as pure upstream (AGENTS.md rule 5). The patches come from patches/series.txt (in that order). -Patches narrows them to the ones really applied to the build tree (CI passes the list from apply-patch-series.ps1, which skips patches already merged upstream). Before packing, the build tree's diff must equal the declared patches, so the source package matches the binaries, and any other change in the build trees is refused. A mismatch stops the script. .EXAMPLE pwsh -File scripts/pack-runtime.ps1 -Channel alpha pwsh -File scripts/pack-runtime.ps1 -Patches reims-util-parallel-offline-download.patch,metal2vulkan-snapshot-replay.patch #> [CmdletBinding(PositionalBinding = $false)] param( [string]$ReimsRepo = 'D:\DevTools\reims-vgpu', [string]$UtilRepo = '', [string]$Metal2VulkanRepo = '', [string]$CargoHome = 'D:\DevTools\cargo', [string]$QemuDir = 'D:\Data\macos-vm-lab\reims\data\reims-ctl\qemu\current', [string]$Msys2 = 'D:\DevTools\msys64', [string]$OutDir = 'D:\Data\reims-go\releases', [string]$TempRoot = 'D:\Build\Temp', # Channel at build time. A runtime is promoted to stable by turning its # GitHub prerelease into a release, never by repacking (spec section 6). [ValidateSet('alpha', 'stable')] [string]$Channel = 'alpha', [int]$ZstdLevel = 15, # Release identifier for archive names and manifest.commit (defaults to short # upstream commit; e.g. "3731afd-p2" for a patch-queue rebuild of 3731afd). [string]$ReleaseId = '', [ValidatePattern('^(?:[0-9a-f]{7,40})?$')] [string]$SuspendCompatID = '', [ValidatePattern('^(?:[0-9a-f]{40})?$')] [string]$PackagingCommit = '', # Names from patches/series.txt actually applied. Not given: all of them. # Given but empty: none (every patch already upstream). [string[]]$Patches = @() ) $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $PSScriptRoot $patchesDir = Join-Path $repoRoot 'patches' $CargoBin = Join-Path $CargoHome 'bin' function Invoke-Native([string]$exe, [string[]]$argv) { & $exe @argv if ($LASTEXITCODE -ne 0) { throw "$exe $($argv -join ' ') failed ($LASTEXITCODE)" } } function Invoke-GitApply([string]$repo, [string]$patchText, [switch]$Check) { $psi = [Diagnostics.ProcessStartInfo]::new() $psi.FileName = (Get-Command git).Source $psi.WorkingDirectory = $repo $psi.UseShellExecute = $false $psi.RedirectStandardInput = $true $psi.RedirectStandardOutput = $true $psi.RedirectStandardError = $true $psi.ArgumentList.Add('apply') if ($Check) { $psi.ArgumentList.Add('--check') } $psi.ArgumentList.Add('-') $proc = [Diagnostics.Process]::Start($psi) $proc.StandardInput.NewLine = "`n" $proc.StandardInput.Write($patchText) $proc.StandardInput.Close() $stdout = $proc.StandardOutput.ReadToEnd() $stderr = $proc.StandardError.ReadToEnd() $proc.WaitForExit() if ($proc.ExitCode) { throw "git apply failed in $repo ($($proc.ExitCode)): $stdout$stderr" } } function Get-Sha256([string]$path) { (Get-FileHash -Algorithm SHA256 -LiteralPath $path).Hash.ToLowerInvariant() } 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) Remove-Item -LiteralPath $tar -Force } # ── 1. Inputs and provenance ───────────────────────────────── function Get-GitHubSource([string]$Url, [string]$Fallback) { if ($Url -match '^(?:https://(?:[^/@]+@)?github\.com/|git@github\.com:)([\w.-]+/[\w.-]+?)(?:\.git)?/?$') { return "https://github.com/$($Matches[1])" } return "https://github.com/$Fallback" } $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() $id = if ($ReleaseId -and $ReleaseId.Trim()) { $ReleaseId.Trim() } else { $commit } if ($SuspendCompatID -and $id -cnotmatch ('^' + [regex]::Escape($SuspendCompatID) + '(?:-p[1-9][0-9]*)?$')) { throw "Suspend compatibility ID $SuspendCompatID does not match release $id" } $qemuRepo = Join-Path $ReimsRepo 'vendor\qemu' $qemuCommit = (git -C $qemuRepo rev-parse HEAD).Trim() $reimsOrigin = git -C $ReimsRepo config --get remote.origin.url 2>$null $qemuOrigin = git -C $ReimsRepo config --file .gitmodules --get submodule.vendor/qemu.url $reimsSource = Get-GitHubSource $reimsOrigin 'steelbrain/reims-vgpu' $qemuSource = Get-GitHubSource $qemuOrigin 'steelbrain/qemu-reims-vgpu' $capabilities = @() $runtimeFeatures = Join-Path $ReimsRepo 'reims-go-runtime.json' if (Test-Path -LiteralPath $runtimeFeatures) { $capabilities = @((Get-Content -Raw -LiteralPath $runtimeFeatures | ConvertFrom-Json).capabilities) } # reims-util's pinned commit is a constant in reims-ctl (crates/reims-ctl/src/reims_util.rs, REV). $utilSrc = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'crates\reims-ctl\src\reims_util.rs') if ($utilSrc -notmatch 'pub const REV: &str = "([0-9a-f]{40})"') { throw 'reims-util REV not found in reims_util.rs' } $utilCommit = $Matches[1] $checkouts = Join-Path $CargoHome 'git\checkouts' $utilTree = if ($UtilRepo) { (Resolve-Path -LiteralPath $UtilRepo).Path } else { Get-ChildItem -LiteralPath $checkouts -Directory -Filter 'reims-util-*' | ForEach-Object { Join-Path $_.FullName $utilCommit.Substring(0, 7) } | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1 } if (-not $utilTree) { throw "reims-util source at $utilCommit not found" } $actualUtil = git -C $utilTree rev-parse HEAD if ($LASTEXITCODE -ne 0 -or $actualUtil -ne $utilCommit) { throw "reims-util checkout must be at $utilCommit" } # metal2vulkan's pinned commit (workspace Cargo.toml, falling back to Cargo.lock). $cargoToml = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'Cargo.toml') if ($cargoToml -match 'metal2vulkan\s*=\s*\{[^}]*rev\s*=\s*"([0-9a-f]{40})"') { $m2vCommit = $Matches[1] } else { $lock = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'Cargo.lock') if ($lock -notmatch 'metal2vulkan\?rev=([0-9a-f]{40})') { throw 'metal2vulkan rev not found in Cargo.toml or Cargo.lock' } $m2vCommit = $Matches[1] } $m2vTree = if ($Metal2VulkanRepo) { (Resolve-Path -LiteralPath $Metal2VulkanRepo).Path } else { Get-ChildItem -LiteralPath $checkouts -Directory -Filter 'metal2vulkan-*' -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName $m2vCommit.Substring(0, 7) } | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1 } if (-not $m2vTree) { throw "metal2vulkan source at $m2vCommit not found (pass -Metal2VulkanRepo or check $checkouts)" } $actualM2v = (git -C $m2vTree rev-parse HEAD).Trim() if ($LASTEXITCODE -ne 0 -or $actualM2v -ne $m2vCommit) { throw "metal2vulkan checkout must be at $m2vCommit (got $actualM2v)" } $qemuVersionLine = (& $qemuExe --version | Select-Object -First 1).Trim() $utilVersionLine = (& $utilExe --version | Select-Object -First 1).Trim() # ── 2. Patches must equal the build tree's diffs ───────────── $repositories = @{ 'reims-vgpu' = $ReimsRepo 'vendor/qemu' = $qemuRepo 'reims-util' = $utilTree 'metal2vulkan' = $m2vTree } $series = @(foreach ($line in Get-Content -LiteralPath (Join-Path $patchesDir 'series.txt')) { $t = $line.Trim() if (-not $t -or $t.StartsWith('#')) { continue } $parts = $t -split '\s+' if ($parts.Count -ne 2 -or -not $repositories.ContainsKey($parts[0])) { throw "Bad line in patches/series.txt: '$line'" } [pscustomobject]@{ Target = $parts[0]; Name = $parts[1] } }) # PowerShell -File passes "a,b" as one string: accept both forms. $Patches = @($Patches | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ }) foreach ($n in $Patches) { if ($n -notin $series.Name) { throw "-Patches names $n, which is not in patches/series.txt" } } $patchSpecs = @() $usePatchList = $PSBoundParameters.ContainsKey('Patches') foreach ($e in $series) { if ($usePatchList -and $e.Name -notin $Patches) { continue } $file = Join-Path $patchesDir $e.Name if (-not (Test-Path -LiteralPath $file)) { throw "Patch missing: $file" } # Files the patch touches ("--- a/x" / "+++ b/x"), to scope the diff checks. $paths = @(Get-Content -LiteralPath $file | ForEach-Object { if ($_ -match '^(?:---|\+\+\+) [ab]/(.+?)\s*$') { $Matches[1] } } | Select-Object -Unique) $patchSpecs += @{ Name = $e.Name Target = $e.Target Repo = $repositories[$e.Target] Paths = $paths } } # Avoid colliding with the [string[]]$Patches parameter (PowerShell variable # names are case-insensitive; reusing $patches coerces every entry to a string). $patchEntries = @() # Group patches by repo so multi-patch stacks (e.g. 2-3 QEMU WHPX patches) are # verified together against a clean HEAD export with zero undeclared diff. $byTarget = [ordered]@{} foreach ($ps in $patchSpecs) { $file = Join-Path $patchesDir $ps.Name if (-not (Test-Path -LiteralPath $file)) { throw "Patch missing: $file" } if (-not $byTarget.Contains($ps.Target)) { $byTarget[$ps.Target] = [Collections.Generic.List[hashtable]]::new() } $byTarget[$ps.Target].Add($ps) $patchEntries += [ordered]@{ name = $ps.Name; target = $ps.Target; sha256 = (Get-Sha256 $file) } } foreach ($targetName in $byTarget.Keys) { $group = $byTarget[$targetName] $repo = $group[0].Repo $paths = @($group | ForEach-Object { $_.Paths } | Where-Object { $_ } | Select-Object -Unique) # Use --full-index so blob hash abbreviation lengths match regardless of # object count between the upstream clone and the single-commit verify repo. $diffArgs = @('-C', $repo, '-c', 'core.autocrlf=false', 'diff', '--full-index') if ($paths.Count) { $diffArgs += '--'; $diffArgs += $paths } $treeDiff = (& git @diffArgs | Out-String).Replace("`r`n", "`n").TrimEnd() # Apply the declared patch stack to a clean temporary clone of HEAD and compare diffs byte-for-byte. $verifyDir = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid()) try { New-Item -ItemType Directory -Force -Path $verifyDir | Out-Null $headRev = (git -C $repo rev-parse HEAD).Trim() Invoke-Native 'git' @('init', '-q', $verifyDir) Invoke-Native 'git' @('-C', $verifyDir, 'config', 'core.autocrlf', 'false') Invoke-Native 'git' @('-C', $verifyDir, 'config', 'core.eol', 'lf') Invoke-Native 'git' @('-C', $verifyDir, 'config', 'core.filemode', 'false') Write-Utf8 (Join-Path $verifyDir '.gitattributes') '* text eol=lf`n' $tar = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid() + '.tar') Invoke-Native 'git' @('-C', $repo, 'archive', '--format=tar', '-o', $tar, $headRev) Invoke-Native 'tar.exe' @('-xf', $tar, '-C', $verifyDir) Remove-Item -LiteralPath $tar -Force # bsdtar expands the upstream LF bytes, but Windows text tools used # during extraction must not decide the comparison's line endings. foreach ($file in Get-ChildItem -LiteralPath $verifyDir -Recurse -File) { if ($file.LinkType) { continue } $bytes = [IO.File]::ReadAllBytes($file.FullName) $text = [Text.Encoding]::UTF8.GetString($bytes) if ($text.Contains([char]0)) { continue } $lf = $text.Replace("`r`n", "`n") if ($lf -cne $text) { [IO.File]::WriteAllText($file.FullName, $lf, [Text.UTF8Encoding]::new($false)) } } Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'add', '-A') Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'commit', '-q', '-m', 'base') Invoke-Native 'git' @('-C', $verifyDir, 'add', '--renormalize', '.') Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'commit', '-q', '--allow-empty', '-m', 'normalize-lf') foreach ($ps in $group) { $pf = Join-Path $patchesDir $ps.Name # .patch files may be checked out with CRLF on Windows. Keep the # authoritative file intact while comparing its LF representation # with a Git tree archived and indexed with LF line endings. $patchLf = Join-Path $TempRoot ("patch-lf-" + [guid]::NewGuid() + '.patch') $patchText = [IO.File]::ReadAllText($pf).Replace("`r`n", "`n") [IO.File]::WriteAllText($patchLf, $patchText, [Text.UTF8Encoding]::new($false)) Invoke-GitApply $verifyDir $patchText -Check Invoke-GitApply $verifyDir $patchText Remove-Item -LiteralPath $patchLf -Force } $expectedDiff = (& git -C $verifyDir -c core.autocrlf=false diff --full-index | Out-String).Replace("`r`n", "`n").TrimEnd() if ($treeDiff -ne $expectedDiff) { $treeStat = (& git -C $repo diff --stat -- @paths | Out-String).Trim() $expStat = (& git -C $verifyDir diff --stat | Out-String).Trim() Write-Host "Build tree diff --stat:`n$treeStat" Write-Host "Expected patch stack diff --stat:`n$expStat" throw "Patch stack ($(($group | ForEach-Object { $_.Name }) -join ', ')) does not match the build tree's diff in $repo. Stop: don't edit patches automatically (AGENTS.md rule 4)." } # Also verify newly created (untracked) files added by patches byte-for-byte. $addedFiles = @(& git -C $verifyDir ls-files --others --exclude-standard | Where-Object { $_ }) foreach ($rel in $addedFiles) { $expPath = Join-Path $verifyDir ($rel -replace '/', '\') $treePath = Join-Path $repo ($rel -replace '/', '\') if (-not (Test-Path -LiteralPath $treePath -PathType Leaf)) { throw "Patch stack expected new file $rel in $repo, but it is missing." } $expText = [IO.File]::ReadAllText($expPath).Replace("`r`n", "`n") $treeText = [IO.File]::ReadAllText($treePath).Replace("`r`n", "`n") if ($treeText -cne $expText) { throw "New file $rel in $repo does not match the declared patch stack. Stop: don't edit patches automatically (AGENTS.md rule 4)." } } } finally { if (Test-Path -LiteralPath $verifyDir) { Remove-Item -Recurse -Force -LiteralPath $verifyDir } } } # Anything else changed in the build trees is undeclared: refuse. function Get-Undeclared([string]$repo, [string]$target, [string[]]$statusArgs) { $declared = @($patchSpecs | Where-Object { $_.Target -eq $target } | ForEach-Object { $_.Paths }) @(& git -C $repo status --porcelain @statusArgs | Where-Object { $path = $_.Substring(3).Trim('"') $path -notin $declared }) } $otherCtl = Get-Undeclared $ReimsRepo 'reims-vgpu' @('--ignore-submodules=all') $otherQemu = Get-Undeclared $qemuRepo 'vendor/qemu' @('--untracked-files=no') $utilStatusArgs = if ($UtilRepo) { '--untracked-files=all' } else { '--untracked-files=no' } $otherUtil = Get-Undeclared $utilTree 'reims-util' @($utilStatusArgs) $m2vStatusArgs = if ($Metal2VulkanRepo) { '--untracked-files=all' } else { '--untracked-files=no' } $otherM2v = Get-Undeclared $m2vTree 'metal2vulkan' @($m2vStatusArgs) if ($otherCtl.Count -or $otherQemu.Count -or $otherUtil.Count -or $otherM2v.Count) { throw "Undeclared changes in the build trees:`n$($otherCtl + $otherQemu + $otherUtil + $otherM2v -join "`n")" } $bundleName = "reims-runtime-win-x64-$id" $srcName = "reims-runtime-src-$id" $symbolsName = "reims-runtime-symbols-$id" $stageRoot = Join-Path $TempRoot "pack-$id" $bundleDir = Join-Path $stageRoot $bundleName $srcDir = Join-Path $stageRoot $srcName if (Test-Path -LiteralPath $stageRoot) { Remove-Item -Recurse -Force -LiteralPath $stageRoot } New-Item -ItemType Directory -Force -Path "$bundleDir\bin", "$bundleDir\qemu", "$bundleDir\licenses", "$bundleDir\patches", $srcDir, $OutDir | Out-Null # ── 3. Runtime bundle ──────────────────────────────────────── Write-Host "==> Staging $bundleName ($Channel)" $resolvedQemu = (Get-Item -LiteralPath $QemuDir).Target if (-not $resolvedQemu) { $resolvedQemu = $QemuDir } $keyFiles = @(& (Join-Path $PSScriptRoot 'stage-runtime-binaries.ps1') -CargoBin $CargoBin -QemuDir $resolvedQemu ` -BundleDir $bundleDir -SymbolsDir (Join-Path $stageRoot $symbolsName) -Objcopy (Join-Path $Msys2 'clang64/bin/llvm-objcopy.exe') | ForEach-Object { $_ }) $expectedKeyFiles = @('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') if ($keyFiles.Count -ne 5 -or (Compare-Object $expectedKeyFiles $keyFiles)) { $keyFiles | ForEach-Object { Write-Host "Unexpected stager output [$($_.GetType().FullName)]: $_" } throw 'Binary stager did not return exactly the five expected executable paths' } Copy-Item -LiteralPath (Join-Path $repoRoot 'NOTICE.md') -Destination "$bundleDir\NOTICE.md" foreach ($ps in $patchSpecs) { Copy-Item -LiteralPath (Join-Path $patchesDir $ps.Name) -Destination "$bundleDir\patches\" } Copy-Item -LiteralPath (Join-Path $patchesDir 'README.md') -Destination "$bundleDir\patches\README.md" if (Test-Path -LiteralPath (Join-Path $patchesDir 'LICENSE')) { Copy-Item -LiteralPath (Join-Path $patchesDir 'LICENSE') -Destination "$bundleDir\patches\LICENSE" } # The order the patches above were applied in (only those really applied). Write-Utf8 "$bundleDir\patches\series.txt" ((($patchSpecs | ForEach-Object { '{0,-12} {1}' -f $_.Target, $_.Name }) -join "`n") + "`n") $licenses = @{ 'reims-vgpu-LICENSE.txt' = (Join-Path $ReimsRepo 'LICENSE') 'qemu-COPYING.txt' = (Join-Path $qemuRepo 'COPYING') 'qemu-COPYING.LIB.txt' = (Join-Path $qemuRepo 'COPYING.LIB') } foreach ($k in $licenses.Keys) { if (Test-Path -LiteralPath $licenses[$k]) { Copy-Item -LiteralPath $licenses[$k] -Destination (Join-Path "$bundleDir\licenses" $k) } } if (Test-Path -LiteralPath (Join-Path $ReimsRepo 'LICENSES')) { Copy-Item -Path (Join-Path $ReimsRepo 'LICENSES\*') -Destination "$bundleDir\licenses\" -Recurse -Force } # MSYS2 CLANG64 DLLs: owning package and version, and where its source is. Write-Host '==> Listing MSYS2 packages of bundled DLLs' $bash = Join-Path $Msys2 'usr\bin\bash.exe' $dlls = @(Get-ChildItem -LiteralPath "$bundleDir\qemu\bin" -Filter '*.dll' -File | Sort-Object Name) $pkgLines = [Collections.Generic.List[string]]::new() $pkgSet = [ordered]@{} $pkgNames = [ordered]@{} foreach ($d in $dlls) { $owner = (& $bash -lc "LC_ALL=C pacman -Qqo /clang64/bin/$($d.Name) 2>/dev/null" | Select-Object -First 1) if ($owner) { $ver = (& $bash -lc "LC_ALL=C pacman -Q $owner" | Select-Object -First 1).Split(' ')[1] $pkgLines.Add("$($d.Name)`t$owner`t$ver") $pkgSet["$owner $ver"] = $true $pkgNames[$owner] = $true } else { $pkgLines.Add("$($d.Name)`t(not from an MSYS2 package: built with qemu, source in the source package)`t-") } } # Bundle each MSYS2 package's installed license texts under licenses/msys2/. $msysLicRoot = Join-Path $bundleDir 'licenses\msys2' foreach ($owner in $pkgNames.Keys) { $licFiles = @(& $bash -lc "LC_ALL=C pacman -Ql $owner 2>/dev/null" | ForEach-Object { if ($_ -match '^\S+\s+(/clang64/share/licenses/.+)$' -and -not $Matches[1].EndsWith('/')) { $Matches[1] } }) foreach ($lf in $licFiles) { $rel = $lf.Substring('/clang64/share/licenses/'.Length) $srcFile = Join-Path $Msys2 ($lf.TrimStart('/') -replace '/', '\') if (Test-Path -LiteralPath $srcFile -PathType Leaf) { $dstFile = Join-Path $msysLicRoot ($rel -replace '/', '\') [void][IO.Directory]::CreateDirectory((Split-Path -Parent $dstFile)) Copy-Item -LiteralPath $srcFile -Destination $dstFile -Force } } } $msysText = @" # DLLs bundled in qemu/bin and the MSYS2 CLANG64 packages they come from # (pacman -Qo on the build machine, $(Get-Date -Format 'yyyy-MM-dd')). # # Sources: every package whose licence requires source (GPL / LGPL / MPL) is in # reims-runtime-msys2-src-$id.tar.zst, published beside this runtime. # The same files are also at: # https://repo.msys2.org/mingw/sources/ (-.src.tar.zst, by pkgbase) # https://github.com/msys2/MINGW-packages (build recipes) # Licenses: bundled under licenses/msys2/ from each package's /clang64/share/licenses/ in MSYS2. DLL`tPACKAGE`tVERSION $($pkgLines -join "`n") # Packages ($($pkgSet.Count)) $($pkgSet.Keys -join "`n") "@ Write-Utf8 "$bundleDir\MSYS2-PACKAGES.txt" $msysText # ── 4. Source bundle ───────────────────────────────────────── Write-Host "==> Staging $srcName" function Export-GitTree([string]$repo, [string]$rev, [string]$dest) { New-Item -ItemType Directory -Force -Path $dest | Out-Null $tar = Join-Path $TempRoot ("git-export-" + [guid]::NewGuid() + '.tar') Invoke-Native 'git' @('-C', $repo, 'archive', '--format=tar', '-o', $tar, $rev) Invoke-Native 'tar.exe' @('-xf', $tar, '-C', $dest) Remove-Item -LiteralPath $tar -Force } Export-GitTree $ReimsRepo $fullCommit (Join-Path $srcDir "reims-vgpu-$commit") Export-GitTree $qemuRepo $qemuCommit (Join-Path $srcDir "reims-vgpu-$commit\vendor\qemu") # QEMU's meson wraps downloaded for this build (dtc, keycodemapdb, ...): part of what was built. Get-ChildItem -LiteralPath (Join-Path $qemuRepo 'subprojects') -Directory | Where-Object { $_.Name -ne 'packagecache' -and -not (Test-Path -LiteralPath (Join-Path $srcDir "reims-vgpu-$commit\vendor\qemu\subprojects\$($_.Name)")) } | ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $srcDir "reims-vgpu-$commit\vendor\qemu\subprojects\") -Recurse -Force } Export-GitTree $utilTree $utilCommit (Join-Path $srcDir "reims-util-$($utilCommit.Substring(0, 7))") Export-GitTree $m2vTree $m2vCommit (Join-Path $srcDir "metal2vulkan-$($m2vCommit.Substring(0, 7))") foreach ($extra in @( @{ Name = 'reims-util'; Tree = $utilTree }, @{ Name = 'metal2vulkan'; Tree = $m2vTree } )) { foreach ($lf in @('LICENSE', 'LICENSE.txt', 'LICENSE.md', 'COPYING', 'COPYING.LIB')) { $srcLic = Join-Path $extra.Tree $lf if (Test-Path -LiteralPath $srcLic -PathType Leaf) { Copy-Item -LiteralPath $srcLic -Destination (Join-Path "$bundleDir\licenses" "$($extra.Name)-$lf") -Force } } if (Test-Path -LiteralPath (Join-Path $extra.Tree 'LICENSES') -PathType Container) { Copy-Item -Path (Join-Path $extra.Tree 'LICENSES\*') -Destination "$bundleDir\licenses\" -Recurse -Force } } New-Item -ItemType Directory -Force -Path "$srcDir\patches" | Out-Null Copy-Item -Path "$bundleDir\patches\*" -Destination "$srcDir\patches\" Copy-Item -LiteralPath "$bundleDir\MSYS2-PACKAGES.txt" -Destination "$srcDir\MSYS2-PACKAGES.txt" Copy-Item -LiteralPath "$bundleDir\NOTICE.md" -Destination "$srcDir\NOTICE.md" $m2vBuildSteps = if ($byTarget.Contains('metal2vulkan')) { $m2vDir = "metal2vulkan-$($m2vCommit.Substring(0, 7))" $m2vApply = ($byTarget['metal2vulkan'] | ForEach-Object { " git -C $m2vDir apply `"`$(pwd)/patches/$($_.Name)`"" }) -join "`n" @" Before running ``scripts/install-ctl.sh``, apply the ``metal2vulkan`` patches and point Cargo at the patched checkout via ```$CARGO_HOME/config.toml``: $m2vApply cat >> "`${CARGO_HOME:-`$HOME/.cargo}/config.toml" < Compressing runtime' $runtimeArchive = Join-Path $OutDir "$bundleName.tar.zst" New-TarZst $stageRoot $bundleName $runtimeArchive Write-Host '==> Compressing sources' $srcArchive = Join-Path $OutDir "$srcName.tar.zst" New-TarZst $stageRoot $srcName $srcArchive $symbolsArchive = Join-Path $OutDir "$symbolsName.tar.zst" New-TarZst $stageRoot $symbolsName $symbolsArchive $rtHash = Get-Sha256 $runtimeArchive $srcHash = Get-Sha256 $srcArchive Write-Utf8 "$runtimeArchive.sha256" "$rtHash $bundleName.tar.zst`n" Write-Utf8 (Join-Path $OutDir 'SHA256SUMS.txt') "$rtHash $bundleName.tar.zst`n$srcHash $srcName.tar.zst`n$(Get-Sha256 $symbolsArchive) $symbolsName.tar.zst`n" # Sources of the copyleft MSYS2 packages, as their own asset (adds a line to SHA256SUMS.txt). & (Join-Path $PSScriptRoot 'pack-msys2-sources.ps1') -PackagesFile (Join-Path $bundleDir 'MSYS2-PACKAGES.txt') -Commit $id -OutDir $OutDir -Msys2 $Msys2 -TempRoot $TempRoot Remove-Item -Recurse -Force -LiteralPath $stageRoot Write-Host '' Write-Host '==> Done' -ForegroundColor Green '{0,-10} {1} {2:N1} MB' -f 'runtime', $runtimeArchive, ((Get-Item $runtimeArchive).Length / 1MB) '{0,-10} {1} {2:N1} MB' -f 'source', $srcArchive, ((Get-Item $srcArchive).Length / 1MB) "channel $Channel; patches: $(($patchEntries | ForEach-Object { $_.name }) -join ', '); DLLs: $($dlls.Count)"