From 0934d9d206756ebf4652b46bdc451af04c213310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Sun, 29 Nov 2026 05:45:15 -0700 Subject: [PATCH] ci(runtime): strip runtime executables into detached symbols and trim unused QEMU payloads --- .github/workflows/build-runtime.yml | 6 ++- docs/portable-runtime-spec.md | 21 +++++--- scripts/check-runtime-alpha.ps1 | 59 +++++++++++++++++--- scripts/pack-runtime.ps1 | 84 ++++++++++++++++++++++++----- scripts/stage-runtime-binaries.ps1 | 42 +++++++++++++++ 5 files changed, 182 insertions(+), 30 deletions(-) create mode 100644 scripts/stage-runtime-binaries.ps1 diff --git a/.github/workflows/build-runtime.yml b/.github/workflows/build-runtime.yml index a11e19f..659355b 100644 --- a/.github/workflows/build-runtime.yml +++ b/.github/workflows/build-runtime.yml @@ -196,7 +196,7 @@ jobs: $ErrorActionPreference = 'Stop' & ./scripts/check-runtime-alpha.ps1 ` -OutDir (Join-Path $env:RUNNER_TEMP 'releases') ` - -Commit $env:RELEASE_ID ` + -Commit $env:RELEASE_ID -RequireSlim ` -Zstd (Join-Path '${{ steps.msys2.outputs.msys2-location }}' 'usr\bin\zstd.exe') ` -AppliedPatches @($env:APPLIED_PATCHES -split ',' | Where-Object { $_ }) @@ -220,7 +220,7 @@ jobs: $c = $env:RELEASE_ID $short = $env:SHORT_COMMIT $dir = Join-Path $env:RUNNER_TEMP 'releases' - $assets = @("reims-runtime-win-x64-$c.tar.zst", "reims-runtime-src-$c.tar.zst", "reims-runtime-msys2-src-$c.tar.zst", 'SHA256SUMS.txt') | + $assets = @("reims-runtime-win-x64-$c.tar.zst", "reims-runtime-src-$c.tar.zst", "reims-runtime-msys2-src-$c.tar.zst", "reims-runtime-symbols-$c.tar.zst", 'SHA256SUMS.txt') | ForEach-Object { Join-Path $dir $_ } $applied = if ($env:APPLIED_PATCHES) { ($env:APPLIED_PATCHES -split ',' | ForEach-Object { "- ``$_``" }) -join "`n" } else { '- (none)' } $merged = if ($env:MERGED) { "`n`nAlready upstream, skipped (retire from patches/): $env:MERGED" } else { '' } @@ -232,6 +232,8 @@ jobs: Local patches applied (sources and patches are in the attached source packages): $applied$merged + The optional ``reims-runtime-symbols-$c.tar.zst`` contains matching debug files for crash analysis. + Build: $env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID "@ gh release create "runtime-$c" @assets --prerelease --title "Portable Runtime runtime-$c (alpha)" --notes $notes diff --git a/docs/portable-runtime-spec.md b/docs/portable-runtime-spec.md index 0945919..028d442 100644 --- a/docs/portable-runtime-spec.md +++ b/docs/portable-runtime-spec.md @@ -41,7 +41,14 @@ ## 3. 便携运行时体积与目录规范 -本机实测未压缩体积:**917.8 MB**(`qemu/` 828.5 MB + `reims-ctl.exe` 58.0 MB + `reims-util.exe` 31.3 MB);2026-11-28 实测使用 `zstd -T0 -15` 打包 `reims-runtime-win-x64-3731afd.tar.zst` 后仅 **`160.4 MB`**(压缩率 **17.5%**,不到同类 PySide6 打包方案 1.68 GB 的十分之一)。 +已发布的 `runtime-3731afd` 是未裁剪、保留调试符号的历史基线:本机实测未压缩体积 **917.8 MB**,`zstd -T0 -15` 压缩包 **160.4 MB**。下文的新布局不改变这个既有 Release 的内容。 + +2026-11-29 起,新打包流程采用以下两项可复现的体积优化: + +1. 只删除 Windows x64 启动器不会调用的通用工具 `qemu-system-x86_64.exe`、`elf2dmp.exe`、`qemu-edid.exe`、`qemu-io.exe`、`qemu-nbd.exe`、`qemu-storage-daemon.exe`,以及 ARM64、RISC-V、LoongArch64 的 EDK2 固件及其描述文件。x64 固件、BIOS、ROM、keymaps、动态加载的 `libva` 视频驱动和全部 DLL 均保留。 +2. 对五个主要可执行文件使用 MSYS2 CLANG64 的 `llvm-objcopy` 提取调试符号、剥离 `.debug_*` 节并写入 GNU debug link。对应的 `.debug` 文件单独发布,不丢失崩溃定位能力。通用 DLL 的符号仍保留。 + +同一上游 `3731afd` 和相同两项本地补丁的暂存实验结果为:删除上述工具和异架构固件后 **425.3 MiB** 解压 / **98.3 MiB** 压缩;再剥离主要程序调试符号后 **166.4 MiB** 解压 / **48.0 MiB** 压缩。前者与旧包的目录统计口径略有差异,最终以实际归档解压结果为准。 ### 3.1 运行时发布包结构(`reims-runtime-win-x64-.tar.zst`) @@ -60,9 +67,11 @@ reims-runtime-/ │ ├── qemu-img.exe │ ├── reims-vgpu-compile.exe │ └── *.dll # 71 个自包含 CLANG64 + libva/vaon12 DLL - └── share/ # QEMU pc-bios / edk2 / keymaps 等数据文件 + └── share/ # x64 pc-bios / edk2 / keymaps 等数据文件 ``` +同一 Release 另有 `reims-runtime-symbols-.tar.zst`,按运行时相同路径保存五个 `*.exe.debug` 文件。`manifest.json` 的 `symbols_package` 指向该附件,`sha256` 记录最终已剥离程序的哈希。GNU 调试器可通过程序内的 debug link 和符号包目录定位对应文件。调试符号包不参与客户端下载。 + > **版本耦合约束**:`reims-ctl.exe`、`reims-util.exe` 与 `qemu/` 必须来自**同一个上游 commit**,作为单一版本目录原子安装与回滚,避免协议或内嵌 kext 版本错配。 ### 3.2 用户数据目录结构(由用户在向导中选择,默认非系统盘如 `D:\Data\reims-go\`) @@ -89,17 +98,17 @@ reims-runtime-/ ## 4. 打包与发布流水线(M0 / M4) - **本地打包验证(M0)**:编写 `scripts/pack-runtime.ps1`,直接从本机已编译的 `reims-vgpu` 产物生成 `reims-runtime-win-x64-3731afd.tar.zst` 与 `manifest.json`(含 SHA256),验证纯净解压启动。 -- **本地打包与发布(2026-11-28 起)**:`pwsh -File scripts/pack-runtime.ps1 -Channel alpha` 一次产出三个文件:运行时包、对应源码包 `reims-runtime-src-.tar.zst`、覆盖两者的 `SHA256SUMS.txt`。补丁按 `patches/series.txt` 的顺序取,`-Patches` 可以只列实际打上的那几个。 +- **本地打包与发布(2026-11-29 起)**:`pwsh -File scripts/pack-runtime.ps1 -Channel alpha` 一次产出四个压缩包及 `SHA256SUMS.txt`:运行时包、对应源码包 `reims-runtime-src-.tar.zst`、MSYS2 源码包和可选调试符号包。补丁按 `patches/series.txt` 的顺序取,`-Patches` 可以只列实际打上的那几个。 - **打包前的检查**:脚本先核对每个补丁是否与构建目录里的 diff 完全一致;不一致、或者构建目录里有补丁没涉及的文件被改动,就直接停止,不会自动修改补丁。允许改动的文件从补丁本身读出(2026-11-28 前写死为 `whpx-all.c`,带上 fiber 补丁就会误报)。 - **manifest 版本 2**:比版本 1 多记录 `vendor_qemu_commit`、`util_commit`、`metal2vulkan_commit`、`patches`(名称、作用对象、SHA256)、`channel`、`source_package`。`dll_count` 改为按实际文件统计;版本 1 的统计有误,记为 0。 - - **发布位置**:运行时发布在 [`Nwflower/reims-go`](https://github.com/Nwflower/reims-go/releases) 的 GitHub Release。tag 为 `runtime-`,附件就是上面三个文件。GitHub 的预发布对应 `alpha`(2026-11-28 前叫 `candidate`),正式发布对应 `stable`。三个附件缺任何一个,客户端就不会列出这个版本。 + - **发布位置**:运行时发布在 [`Nwflower/reims-go`](https://github.com/Nwflower/reims-go/releases) 的 GitHub Release。tag 为 `runtime-`,附件包含上述四个压缩包和校验清单。GitHub 的预发布对应 `alpha`(2026-11-28 前叫 `candidate`),正式发布对应 `stable`。客户端下载仍只需要运行时包与校验清单,因此旧客户端也可安装新布局。 - **客户端安装**(`internal/runtime/remote.go`):从 GitHub API 列出版本 → 下载运行时包,支持续传 → 对照 `SHA256SUMS.txt` 校验,不一致就丢弃 → 用原有的导入流程解压并激活 → 删除下载的压缩包。 - **已发布**:`runtime-3731afd`,先以候选版(即现在的 alpha)发布,同日升为稳定版。实测从 GitHub 下载 169 MB、校验、解压、激活,全程约 75 秒。 - **自动化 CI(M4,2026-11-28 改为每日自动构建)**:[`build-runtime.yml`](../.github/workflows/build-runtime.yml) 每天 03:23 UTC 运行,也可手动触发并指定上游 commit。流程: 1. 取上游默认分支的 HEAD。已有 `runtime-` 的 Release(alpha 或 stable)就跳过,所以上游不动时不消耗构建时间。 2. 在 `windows-latest` 上用 MSYS2 CLANG64,由 `scripts/apply-patch-series.ps1` 按 `patches/series.txt` 逐个处理补丁:能打上就打;反向检查通过(上游已经包含)就跳过并提醒退役;两者都不行就停止,不改补丁(AGENTS.md 规则 4)。 3. 执行上游 `scripts/install-ctl.sh --yes`,再用 `pack-runtime.ps1 -Channel alpha -Patches <实际打上的补丁>` 打包,manifest 只写实际打上的补丁(规则 5)。 - 4. `scripts/check-runtime-alpha.ps1` 做 alpha 准入检查(第 6 节),通过后发布为 GitHub 预发布,附件四个缺一不可。 + 4. `scripts/check-runtime-alpha.ps1` 做 alpha 准入检查(第 6 节),通过后发布为 GitHub 预发布,五个附件缺一不可。 5. 只保留最近 7 个未升级的 alpha 预发布,更早的连同 tag 删除;正式发布不受影响。 6. 构建失败、或有补丁已被上游合并时,在本仓库开一个 issue(已有同名的未关闭 issue 就追加评论)。 @@ -145,7 +154,7 @@ reims-runtime-/ | 通道 | 来源 | 进入条件 | | :--- | :--- | :--- | -| `alpha` | CI 每天从上游最新 commit 自动构建并打补丁(2026-11-28 前叫 `candidate`,当时是人工指定 commit) | 由 `scripts/check-runtime-alpha.ps1` 自动检查:能构建;四个附件齐全;`SHA256SUMS.txt` 覆盖三个压缩包且校验一致;manifest 的 commit、通道、补丁与实际一致;在不含 MSYS2 的 PATH 下 `qemu-system-x86_64.exe -device help` 列出 `reims-graphics-pci` | +| `alpha` | CI 每天从上游最新 commit 自动构建并打补丁(2026-11-28 前叫 `candidate`,当时是人工指定 commit) | 由 `scripts/check-runtime-alpha.ps1` 自动检查:能构建;新布局的五个附件齐全;`SHA256SUMS.txt` 覆盖四个压缩包且校验一致;manifest 的 commit、通道、补丁、五个最终可执行文件哈希及符号包一致;视频驱动和许可证文件齐全;在不含 MSYS2 的 PATH 下列出 `reims-graphics-pci`,执行 CLI 版本检查及 qcow2 创建、读取。`-RequireSlim` 用于强制新布局,省略时仍可检查历史包 | | `stable` | 从 `alpha` 升级 | 在一台真实 Win10 或 Win11 宿主上跑通冒烟测试:`doctor` 的运行时检查全部通过,用 golden 镜像启动到 macOS 桌面,截一张屏,正常关机。由人确认后升级 | `reims-go` 客户端默认只拉 `stable`,`alpha` 要用户主动打开(界面开关「接收 Alpha 版」,CLI `--alpha`)。旧配置里的 `runtime_channel: "candidate"` 读作 `alpha`,CLI 的 `--candidate` 保留为 `--alpha` 的别名。这层筛选是 `reims-go` 相对于「自己跑上游安装脚本」的主要价值之一。 diff --git a/scripts/check-runtime-alpha.ps1 b/scripts/check-runtime-alpha.ps1 index 4c6e6ef..9900001 100644 --- a/scripts/check-runtime-alpha.ps1 +++ b/scripts/check-runtime-alpha.ps1 @@ -5,10 +5,9 @@ .DESCRIPTION Fails unless all of these hold: - 1. All four release assets exist in -OutDir: the runtime, its source - package, the MSYS2 source package and SHA256SUMS.txt (spec section 7: - a runtime is never published without its sources). - 2. SHA256SUMS.txt lists the three archives, and every hash matches. + 1. The runtime, both source packages and SHA256SUMS.txt exist. Slim + releases also require the matching detached symbols archive. + 2. SHA256SUMS.txt lists all release archives and every hash matches. 3. manifest.json in the runtime names -Commit, channel "alpha", the source package, and exactly the patches in -AppliedPatches. 4. The runtime's own qemu-system-x86_64.exe, run with a PATH holding only @@ -27,6 +26,7 @@ param( [Parameter(Mandatory = $true)] [string]$Zstd, [string[]]$AppliedPatches = @(), + [switch]$RequireSlim, # Only for checking packages built before the 2026-11-28 rename ("candidate"). [string]$ExpectChannel = 'alpha', [string]$TempRoot = $env:RUNNER_TEMP @@ -42,19 +42,23 @@ $names = @{ sums = 'SHA256SUMS.txt' } -# 1. All four assets. +$symbolsName = "reims-runtime-symbols-$Commit" +if ($RequireSlim -or (Test-Path -LiteralPath (Join-Path $OutDir "$symbolsName.tar.zst"))) { + $names.symbols = "$symbolsName.tar.zst" +} +# 1. All assets for this layout. foreach ($k in $names.Keys) { $p = Join-Path $OutDir $names[$k] if (-not (Test-Path -LiteralPath $p)) { throw "Missing release asset: $($names[$k])" } } -Write-Host 'PASS four release assets present' +Write-Host "PASS $($names.Count) release assets present" -# 2. Sums cover the three archives and match. +# 2. Sums cover the archives and match. $sums = @{} foreach ($line in Get-Content -LiteralPath (Join-Path $OutDir $names.sums)) { if ($line -match '^([0-9a-fA-F]{64})\s+\*?(.+)$') { $sums[$Matches[2].Trim()] = $Matches[1].ToLowerInvariant() } } -foreach ($k in 'runtime', 'source', 'msys2') { +foreach ($k in ($names.Keys | Where-Object { $_ -ne 'sums' })) { $n = $names[$k] if (-not $sums.ContainsKey($n)) { throw "SHA256SUMS.txt has no entry for $n" } $got = (Get-FileHash -Algorithm SHA256 -LiteralPath (Join-Path $OutDir $n)).Hash.ToLowerInvariant() @@ -80,12 +84,34 @@ try { if ($m.commit -ne $Commit) { throw "manifest commit is $($m.commit), expected $Commit" } if ($m.channel -ne $ExpectChannel) { throw "manifest channel is $($m.channel), expected $ExpectChannel" } if ($m.source_package -ne $names.source) { throw "manifest source_package is $($m.source_package), expected $($names.source)" } + $files = @(Get-ChildItem -LiteralPath $root -Recurse -File) + if ($m.file_count -ne $files.Count) { throw "manifest file_count is $($m.file_count), actual $($files.Count)" } + $rawBytes = [int64](($files | Measure-Object Length -Sum).Sum) + if ($m.raw_bytes -ne $rawBytes) { throw "manifest raw_bytes is $($m.raw_bytes), actual $rawBytes" } $declared = @($m.patches | ForEach-Object { $_.name }) if (($declared -join ',') -ne ($AppliedPatches -join ',')) { throw "manifest patches [$($declared -join ', ')] differ from those applied [$($AppliedPatches -join ', ')]" } Write-Host "PASS manifest: commit $Commit, channel $($m.channel), patches [$($declared -join ', ')]" + if ($m.symbols_package -or $names.symbols) { + if (!$names.symbols -or $m.symbols_package -ne $names.symbols) { throw 'Missing or mismatched symbols package' } + $symTar = Join-Path $work 'symbols.tar' + & $Zstd -d -q -f (Join-Path $OutDir $names.symbols) -o $symTar + if ($LASTEXITCODE) { throw 'Cannot decompress symbols package' } + $members = & (Join-Path $env:SystemRoot 'System32\tar.exe') -tf $symTar + if ($LASTEXITCODE) { throw 'Cannot list symbols package' } + foreach ($rel in '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') { + $hash = (Get-FileHash -LiteralPath (Join-Path $root $rel) -Algorithm SHA256).Hash + if ($hash -ne $m.sha256.$rel) { throw "Manifest hash mismatch for $rel" } + if ("$symbolsName/$rel.debug" -notin $members) { throw "Missing debug file for $rel" } + } + foreach ($rel in 'qemu/bin/libva.dll','qemu/bin/libva_win32.dll','qemu/bin/vaon12_drv_video.dll','NOTICE.md','MSYS2-PACKAGES.txt') { + if (!(Test-Path -LiteralPath (Join-Path $root $rel) -PathType Leaf)) { throw "Missing runtime dependency: $rel" } + } + Write-Host 'PASS stripped executable hashes, detached debug members and video driver files' + } + # 4. QEMU runs from the bundle alone and has the reims device. $qemuBin = Join-Path $root 'qemu\bin' $psi = [Diagnostics.ProcessStartInfo]::new((Join-Path $qemuBin 'qemu-system-x86_64.exe'), '-device help') @@ -102,6 +128,23 @@ try { if ($proc.ExitCode -ne 0) { throw "qemu -device help exited $($proc.ExitCode): $err" } if ($out -notmatch 'reims-graphics-pci') { throw "qemu -device help does not list reims-graphics-pci`n$out`n$err" } Write-Host 'PASS qemu-system-x86_64 -device help lists reims-graphics-pci (no MSYS2 on PATH)' + if ($names.symbols) { + $oldPath = $env:PATH + $img = Join-Path $qemuBin 'qemu-img.exe' + try { + $env:PATH = $psi.Environment['PATH'] + foreach ($exe in 'reims-ctl.exe','reims-util.exe') { + & (Join-Path $root "bin/$exe") --version + if ($LASTEXITCODE) { throw "$exe --version failed ($LASTEXITCODE)" } + } + $disk = Join-Path $work 'test.qcow2' + & $img create -f qcow2 $disk 32M + if ($LASTEXITCODE) { throw "qemu-img create failed ($LASTEXITCODE)" } + $info = & $img info --output=json $disk + if ($LASTEXITCODE -or (($info -join "`n" | ConvertFrom-Json).'virtual-size' -ne 32MB)) { throw 'qemu-img info failed' } + } finally { $env:PATH = $oldPath } + Write-Host 'PASS CLI versions and qcow2 creation / inspection (no MSYS2 on PATH)' + } } finally { Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue } diff --git a/scripts/pack-runtime.ps1 b/scripts/pack-runtime.ps1 index f25b293..d4db09a 100644 --- a/scripts/pack-runtime.ps1 +++ b/scripts/pack-runtime.ps1 @@ -4,7 +4,7 @@ package, and SHA256SUMS.txt, ready to publish as a GitHub Release. .DESCRIPTION - Outputs, in -OutDir (all four are assets of one GitHub Release): + 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) @@ -12,7 +12,8 @@ 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) - SHA256SUMS.txt all three archives + 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, @@ -30,7 +31,7 @@ pwsh -File scripts/pack-runtime.ps1 -Channel alpha pwsh -File scripts/pack-runtime.ps1 -Patches reims-vgpu-cargo-lock.patch,qemu-whpx-win10-compat.patch #> -[CmdletBinding()] +[CmdletBinding(PositionalBinding = $false)] param( [string]$ReimsRepo = 'D:\DevTools\reims-vgpu', [string]$CargoHome = 'D:\DevTools\cargo', @@ -61,6 +62,27 @@ function Invoke-Native([string]$exe, [string[]]$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() } @@ -174,16 +196,41 @@ foreach ($targetName in $byTarget.Keys) { 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 - Invoke-Native 'git' @('-C', $verifyDir, 'apply', '--check', $pf) - Invoke-Native 'git' @('-C', $verifyDir, 'apply', $pf) + # .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) { @@ -213,6 +260,7 @@ if ($otherCtl.Count -or $otherQemu.Count) { $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 @@ -221,11 +269,16 @@ New-Item -ItemType Directory -Force -Path "$bundleDir\bin", "$bundleDir\qemu", " # ── 3. Runtime bundle ──────────────────────────────────────── Write-Host "==> Staging $bundleName ($Channel)" -Copy-Item -LiteralPath $ctlExe -Destination "$bundleDir\bin\reims-ctl.exe" -Copy-Item -LiteralPath $utilExe -Destination "$bundleDir\bin\reims-util.exe" $resolvedQemu = (Get-Item -LiteralPath $QemuDir).Target if (-not $resolvedQemu) { $resolvedQemu = $QemuDir } -Copy-Item -Path "$resolvedQemu\*" -Destination "$bundleDir\qemu" -Recurse -Force +$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\" } @@ -333,12 +386,10 @@ packages listed in ``MSYS2-PACKAGES.txt``, with links to their sources. "@ # ── 5. Manifest (schema 2) ─────────────────────────────────── -$allFiles = Get-ChildItem -LiteralPath $bundleDir -Recurse -File -$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-Sha256 $fp } + $hashes[$rel] = Get-Sha256 $fp } $manifest = [ordered]@{ schema_version = 2 @@ -353,15 +404,18 @@ $manifest = [ordered]@{ patches = $patchEntries channel = $Channel source_package = "$srcName.tar.zst" + symbols_package = "$symbolsName.tar.zst" qemu_version = $qemuVersionLine util_version = $utilVersionLine built_at = (Get-Date).ToString('o') - file_count = $allFiles.Count + 1 + file_count = (Get-ChildItem -LiteralPath $bundleDir -Recurse -File).Count + 1 dll_count = $dlls.Count - raw_bytes = [int64](($allFiles | Measure-Object Length -Sum).Sum) # PowerShell 7 sums to a double; JSON must stay an integer + raw_bytes = [int64]((Get-ChildItem -LiteralPath $bundleDir -Recurse -File | Measure-Object Length -Sum).Sum) # Add the manifest's own size after writing it below. sha256 = $hashes } Write-Utf8 "$bundleDir\manifest.json" ($manifest | ConvertTo-Json -Depth 5) +$manifest.raw_bytes += (Get-Item -LiteralPath "$bundleDir\manifest.json").Length +Write-Utf8 "$bundleDir\manifest.json" ($manifest | ConvertTo-Json -Depth 5) # ── 6. Archives and sums ───────────────────────────────────── Write-Host '==> Compressing runtime' @@ -370,11 +424,13 @@ 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" +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 diff --git a/scripts/stage-runtime-binaries.ps1 b/scripts/stage-runtime-binaries.ps1 new file mode 100644 index 0000000..14e8f55 --- /dev/null +++ b/scripts/stage-runtime-binaries.ps1 @@ -0,0 +1,42 @@ +# Stage the Windows x64 payload and matching GNU debug files. Inputs are read-only. +[CmdletBinding()] +param( + [Parameter(Mandatory)] [string]$CargoBin, + [Parameter(Mandatory)] [string]$QemuDir, + [Parameter(Mandatory)] [string]$BundleDir, + [Parameter(Mandatory)] [string]$SymbolsDir, + [Parameter(Mandatory)] [string]$Objcopy +) +$ErrorActionPreference = 'Stop' +$programs = @('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') + +# Omit only the paths tested with the x64 launcher. Keep new upstream files, +# in particular dynamically loaded video drivers, ROMs, and license notices. +$tools = @('bin/qemu-system-x86_64w.exe', 'bin/elf2dmp.exe', 'bin/qemu-edid.exe', + 'bin/qemu-io.exe', 'bin/qemu-nbd.exe', 'bin/qemu-storage-daemon.exe') +foreach ($file in Get-ChildItem -LiteralPath $QemuDir -Recurse -Force -File) { + $rel = [IO.Path]::GetRelativePath($QemuDir, $file.FullName).Replace('\', '/') + if ($rel -in $tools) { continue } + if ($rel -match '^share/edk2-(aarch64|riscv64|loongarch64)-(code|vars)\.fd$' -or + $rel -match '^share/firmware/\d+-edk2-(aarch64|riscv64|loongarch64)\.json$') { continue } + if ("qemu/$rel" -in $programs) { continue } + $dest = Join-Path $BundleDir "qemu/$rel" + [void][IO.Directory]::CreateDirectory((Split-Path -Parent $dest)) + Copy-Item -LiteralPath $file.FullName -Destination $dest +} + +foreach ($rel in $programs) { + $src = if ($rel.StartsWith('qemu/')) { Join-Path $QemuDir $rel.Substring(5) } + else { Join-Path $CargoBin (Split-Path -Leaf $rel) } + $dest = Join-Path $BundleDir $rel + $debug = Join-Path $SymbolsDir "$rel.debug" + [void][IO.Directory]::CreateDirectory((Split-Path -Parent $dest)) + [void][IO.Directory]::CreateDirectory((Split-Path -Parent $debug)) + & $Objcopy --only-keep-debug $src $debug | Out-Null + if ($LASTEXITCODE) { throw "Extracting symbols from $src failed ($LASTEXITCODE)" } + & $Objcopy --strip-debug "--add-gnu-debuglink=$debug" $src $dest | Out-Null + if ($LASTEXITCODE) { throw "Stripping $src failed ($LASTEXITCODE)" } +} +# The packer hashes these final, stripped bytes for manifest.json. +$programs