Files
Reims-Go/scripts/stage-runtime-binaries.ps1

43 lines
2.2 KiB
PowerShell

# 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