diff --git a/docs/portable-runtime-spec.md b/docs/portable-runtime-spec.md index 9d07d2e..c7ed7e2 100644 --- a/docs/portable-runtime-spec.md +++ b/docs/portable-runtime-spec.md @@ -142,6 +142,9 @@ reims-runtime-/ 2026-11-28 的做法(`runtime-3731afd`): - **源码包内容**:四个上游仓库在对应 commit 的原始源码树(用 `git archive` 导出),加上构建时下载的 QEMU meson 子项目、`patches/` 里的补丁原文和重建说明。补丁不预先打在源码树上,由使用者按说明自行应用;已实测两个补丁都能直接打到这份源码上。 - **DLL**:71 个 DLL 全部来自 55 个 MSYS2 包,`MSYS2-PACKAGES.txt` 按 DLL 列出所属包和版本,并给出源码下载地址(`repo.msys2.org/mingw/sources/` 和 MINGW-packages)。 -- **待人确认**:对 LGPL/GPL 的 DLL,只给出精确版本和源码获取地址,没有把源码一并打进 Release,这是否足够需要由人判断。如果不够,就把对应的 `.src.tar.zst` 一起放进源码包,预计会增加几百 MB。 +- **MSYS2 包的源码(2026-11-28 决定单独打包)**:只给下载地址不够稳妥,因为 MSYS2 删掉旧版本后链接就会失效。所以许可证要求提供源码的包,其源码作为同一个 Release 的第四个附件 `reims-runtime-msys2-src-.tar.zst` 发布。这满足 GPLv2 §3 和 LGPL-2.1 §6「在同一处提供源码」的要求。由 `scripts/pack-msys2-sources.ps1` 生成,`pack-runtime.ps1` 会自动调用它。 + - **筛选规则**:从本机 pacman 数据库读取每个包的 `%BASE%` 和 `%LICENSE%`。只要有一项许可证的所有可选项都含 GPL、LGPL 或 MPL,就需要附源码。如果有可选的宽松许可证(例如 freetype 可选 FTL,zstd 可选 BSD),就不附。只适用于文档的条目(`documentation:`)不算。 + - **内容**:`repo.msys2.org/mingw/sources/` 上原样的 `-.src.tar.zst`,内含 PKGBUILD、上游源码和 MSYS2 的补丁。每个都附 `.sig` 签名文件;打包时用 `gpgv` 和 MSYS2 密钥逐个校验,校验不过就停止。同时附一份 README,列出全部 55 个包的许可证,以及哪些附了源码。 + - **`runtime-3731afd` 的结果**:22 个源码包,110 MB,签名全部通过。下载的源码缓存在 `D:\Data\reims-go\releases\msys2-sources-cache`,下次打包会复用。 `reims-go` 外壳用 MIT,前提是它和这些组件只通过独立进程交互,不链接它们。 diff --git a/scripts/pack-msys2-sources.ps1 b/scripts/pack-msys2-sources.ps1 new file mode 100644 index 0000000..5e39352 --- /dev/null +++ b/scripts/pack-msys2-sources.ps1 @@ -0,0 +1,171 @@ +<# +.SYNOPSIS + Pack the sources of the copyleft MSYS2 packages whose DLLs a runtime bundles, + as a separate release asset. + +.DESCRIPTION + Reads the "# Packages" list from a runtime's MSYS2-PACKAGES.txt, looks up each + package's source name (%BASE%) and licenses in the local pacman database, and + keeps the packages whose license requires source (GPL / LGPL / MPL) unless an + alternative licence without those can be chosen (for example "GPL OR FTL"). + + For each kept package it downloads -.src.tar.zst and its .sig + from repo.msys2.org (cached in -CacheDir), checks the signature against the + MSYS2 keyring with gpgv, and packs them into + reims-runtime-msys2-src-.tar.zst in -OutDir. The archive's hash is + added to -OutDir\SHA256SUMS.txt (an existing line for it is replaced). + + Published in the same GitHub Release as the runtime, so the sources are + offered from the same place as the binaries (GPLv2 §3, LGPL-2.1 §6). + +.EXAMPLE + pwsh -File scripts/pack-msys2-sources.ps1 -PackagesFile MSYS2-PACKAGES.txt -Commit 3731afd -OutDir D:\Data\reims-go\releases\3731afd-candidate +#> +[CmdletBinding()] +param( + [Parameter(Mandatory)] [string]$PackagesFile, + [Parameter(Mandatory)] [string]$Commit, + [Parameter(Mandatory)] [string]$OutDir, + [string]$Msys2 = 'D:\DevTools\msys64', + [string]$CacheDir = 'D:\Data\reims-go\releases\msys2-sources-cache', + [string]$TempRoot = 'D:\Build\Temp', + [string]$Mirror = 'https://repo.msys2.org/mingw/sources' +) + +$ErrorActionPreference = 'Stop' +$localDb = Join-Path $Msys2 'var\lib\pacman\local' +$bash = Join-Path $Msys2 'usr\bin\bash.exe' +$zstd = Join-Path $Msys2 'usr\bin\zstd.exe' + +function Write-Utf8([string]$path, [string]$text) { + [IO.File]::WriteAllText($path, $text.Replace("`r`n", "`n"), [Text.UTF8Encoding]::new($false)) +} + +function Read-Desc([string]$name, [string]$version) { + $file = Join-Path $localDb "$name-$version\desc" + if (-not (Test-Path -LiteralPath $file)) { + throw "$name $version is not in the local pacman database ($file): was MSYS2 updated after the runtime was built?" + } + $fields = @{} + $key = $null + foreach ($line in Get-Content -LiteralPath $file) { + if ($line -match '^%(\w+)%$') { $key = $Matches[1]; $fields[$key] = @(); continue } + if ($key -and $line -ne '') { $fields[$key] += $line } + } + return $fields +} + +# A licence entry needs source unless one OR-alternative is free of copyleft. +# Entries prefixed "documentation:" cover only docs, which aren't shipped. +function Test-NeedsSource([string[]]$licenses) { + foreach ($entry in $licenses) { + if ($entry -like 'documentation:*') { continue } + $expr = $entry -replace '^spdx:', '' + $alternatives = $expr -split '\s+OR\s+' + $allCopyleft = $true + foreach ($alt in $alternatives) { + if ($alt -notmatch 'GPL|MPL') { $allCopyleft = $false } + } + if ($allCopyleft) { return $true } + } + return $false +} + +function To-MsysPath([string]$winPath) { + $p = $winPath -replace '\\', '/' + if ($p -match '^([A-Za-z]):(.*)$') { return '/' + $Matches[1].ToLower() + $Matches[2] } + return $p +} + +# ── 1. Which packages need source ──────────────────────────── +$text = Get-Content -Raw -LiteralPath $PackagesFile +$section = ($text -split '# Packages[^\n]*\n', 2)[1] +if (-not $section) { throw "No '# Packages' section in $PackagesFile" } +$packages = $section -split "`n" | Where-Object { $_ -match '^\S+ \S+$' } | ForEach-Object { + $n, $v = $_ -split ' ' + $d = Read-Desc $n $v + [pscustomobject]@{ + Name = $n + Version = $v + Base = $d['BASE'][0] + Licenses = $d['LICENSE'] + Needs = (Test-NeedsSource $d['LICENSE']) + } +} +$needed = @($packages | Where-Object Needs | Sort-Object Base, Version -Unique) +Write-Host ("==> {0} of {1} packages need source; {2} source archives" -f @($packages | Where-Object Needs).Count, $packages.Count, $needed.Count) + +# ── 2. Download and verify ─────────────────────────────────── +New-Item -ItemType Directory -Force -Path $CacheDir, $OutDir | Out-Null +foreach ($p in $needed) { + $file = "$($p.Base)-$($p.Version).src.tar.zst" + foreach ($f in @($file, "$file.sig")) { + $dest = Join-Path $CacheDir $f + if (-not (Test-Path -LiteralPath $dest)) { + Write-Host " downloading $f" + Invoke-WebRequest -Uri "$Mirror/$f" -OutFile "$dest.part" -UserAgent 'reims-go-packager' + Move-Item -LiteralPath "$dest.part" -Destination $dest -Force + } + } + $cache = To-MsysPath $CacheDir + $out = & $bash -lc "LC_ALL=C gpgv --keyring /etc/pacman.d/gnupg/pubring.gpg '$cache/$file.sig' '$cache/$file' 2>&1" + if ($LASTEXITCODE -ne 0) { throw "Signature check failed for ${file}:`n$out" } + $signer = ($out | Select-String 'Good signature from "([^"]+)"').Matches.Groups[1].Value + $p | Add-Member -NotePropertyName File -NotePropertyValue $file + $p | Add-Member -NotePropertyName Signer -NotePropertyValue $signer +} + +# ── 3. Pack ────────────────────────────────────────────────── +$name = "reims-runtime-msys2-src-$Commit" +$stage = Join-Path $TempRoot "pack-$name" +if (Test-Path -LiteralPath $stage) { Remove-Item -Recurse -Force -LiteralPath $stage } +$dir = Join-Path $stage $name +New-Item -ItemType Directory -Force -Path (Join-Path $dir 'sources') | Out-Null +foreach ($p in $needed) { + Copy-Item -LiteralPath (Join-Path $CacheDir $p.File) -Destination (Join-Path $dir 'sources') + Copy-Item -LiteralPath (Join-Path $CacheDir "$($p.File).sig") -Destination (Join-Path $dir 'sources') +} + +$rows = foreach ($p in ($packages | Sort-Object Name)) { + $lic = ($p.Licenses -join '; ') -replace '\|', '/' + $src = if ($p.Needs) { "``sources/$("$($p.Base)-$($p.Version).src.tar.zst")``" } else { '— (permissive licence; text in the runtime''s licenses/)' } + "| ``$($p.Name -replace '^mingw-w64-clang-x86_64-', '')`` | $($p.Version) | $lic | $src |" +} +Write-Utf8 (Join-Path $dir 'README.md') @" +# MSYS2 package sources for reims-runtime-win-x64-$Commit + +The runtime's ``qemu/bin`` bundles DLLs from MSYS2 CLANG64 packages. This archive +holds, unmodified, the source packages of every one whose licence requires source +(GPL, LGPL or MPL with no permissive alternative), exactly as MSYS2 publishes them +at $Mirror, each with its detached signature (``.sig``), checked with gpgv +against the MSYS2 keyring when this archive was made. + +A ``.src.tar.zst`` contains the PKGBUILD, the upstream source tarball and MSYS2's +patches: ``makepkg-mingw`` in an MSYS2 shell rebuilds the package. + +| Package | Version | Licence | Source | +| :-- | :-- | :-- | :-- | +$($rows -join "`n") +"@ + +$tar = Join-Path $TempRoot "$name.tar" +& tar.exe -cf $tar -C $stage $name +if ($LASTEXITCODE -ne 0) { throw 'tar failed' } +$archive = Join-Path $OutDir "$name.tar.zst" +& $zstd -T0 -3 -q -f $tar -o $archive # contents are already compressed +if ($LASTEXITCODE -ne 0) { throw 'zstd failed' } +Remove-Item -LiteralPath $tar -Force +Remove-Item -Recurse -Force -LiteralPath $stage + +# ── 4. SHA256SUMS.txt ──────────────────────────────────────── +$hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $archive).Hash.ToLowerInvariant() +$sums = Join-Path $OutDir 'SHA256SUMS.txt' +$lines = @() +if (Test-Path -LiteralPath $sums) { + $lines = @(Get-Content -LiteralPath $sums | Where-Object { $_ -and $_ -notmatch " $([regex]::Escape("$name.tar.zst"))$" }) +} +$lines += "$hash $name.tar.zst" +Write-Utf8 $sums (($lines -join "`n") + "`n") + +Write-Host '==> Done' -ForegroundColor Green +'{0} {1:N1} MB ({2} source archives, all signatures good)' -f $archive, ((Get-Item $archive).Length / 1MB), $needed.Count diff --git a/scripts/pack-runtime.ps1 b/scripts/pack-runtime.ps1 index 6d6c551..cb37ea6 100644 --- a/scripts/pack-runtime.ps1 +++ b/scripts/pack-runtime.ps1 @@ -4,13 +4,15 @@ package, and SHA256SUMS.txt, ready to publish as a GitHub Release. .DESCRIPTION - Outputs, in -OutDir: + Outputs, in -OutDir (all four 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/ - SHA256SUMS.txt both archives + 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 manifest.json (schema 2) states what the package was really built from: upstream commit, vendor/qemu commit, reims-util and metal2vulkan commits, @@ -173,7 +175,9 @@ $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 for each package version: +# Sources: every package whose licence requires source (GPL / LGPL / MPL) is in +# reims-runtime-msys2-src-$commit.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: see each package's /clang64/share/licenses// in MSYS2. @@ -281,6 +285,9 @@ $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" +# 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 $commit -OutDir $OutDir -Msys2 $Msys2 -TempRoot $TempRoot + Remove-Item -Recurse -Force -LiteralPath $stageRoot Write-Host ''