Files
Reims-Go/docs/portable-runtime-spec.md
T

135 lines
9.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 便携运行时规范(Portable Runtime Spec)
> 本文定义 Reims-Go Windows x86-64 便携运行时的打包结构、目录隔离、CI 自动构建、`alpha` → `stable` 发布通道以及开源合规义务。
---
## 1. 自包含前提与上游耦合
`reims-vgpu` 的 Windows 运行时在二进制层面可以脱离 MSYS2、Rust 工具链与源码树独立运行:
- **内嵌引导与驱动资源**:`reims-ctl.exe` 编译时已内嵌 `ReimsGraphics.rom` 与 Guest Kexts,运行时按内容哈希释放到 `<XDG_DATA_HOME>/reims-ctl/prebuilt/`。
- **XDG 路径重定向**:传入 Windows 绝对路径格式的 `XDG_CONFIG_HOME`、`XDG_DATA_HOME`、`XDG_CACHE_HOME` 后,`reims-ctl` 与 `reims-util` 均遵守重定向,不写入 `%USERPROFILE%`(仅短路径 socket 使用 `%TEMP%\reims-ctl`)。
- **QEMU 定位优先级**:`reims-ctl` 优先使用 `REIMS_CTL_QEMU` 指定的 `qemu-system-x86_64.exe`,并在同级目录定位 `qemu-img.exe`。
- **版本强耦合约束**:`reims-ctl.exe`、`reims-util.exe` 与 `qemu/` 必须来自同一个上游 commit,作为单个版本目录原子安装与回滚,避免协议或内嵌 kext 错配。
---
## 2. 运行时包与用户目录规范
### 2.1 运行时压缩包结构(`reims-runtime-win-x64-<commit>.tar.zst`)
```text
reims-runtime-<commit>/
├── manifest.json # 上游各仓库 commit、补丁清单与哈希、构建通道、可执行文件 SHA-256、符号包索引
├── NOTICE.md # 上游来源与第三方许可声明
├── licenses/ # GPL-2.0、LGPL-3.0 等许可证全文
├── patches/ # 实际应用的全部补丁原文(与 manifest.json 一一对应)
├── bin/
│ ├── reims-ctl.exe
│ └── reims-util.exe
└── qemu/
├── bin/
│ ├── qemu-system-x86_64.exe
│ ├── qemu-img.exe
│ ├── reims-vgpu-compile.exe
│ └── *.dll # 自包含 CLANG64 与 libva/vaon12 运行库
└── share/ # x64 pc-bios / edk2 / keymaps 等数据文件
```
### 2.2 裁剪与调试符号分离
打包脚本 [`scripts/stage-runtime-binaries.ps1`](../scripts/stage-runtime-binaries.ps1) 执行两项体积优化,在缩小下载体积的同时保留完整调试能力:
1. **裁剪非必要工具与异架构固件**:仅移除 Windows x64 启动器不会调用的 `qemu-system-x86_64w.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` 从 5 个主可执行文件(`reims-ctl.exe`、`reims-util.exe`、`qemu-system-x86_64.exe`、`qemu-img.exe`、`reims-vgpu-compile.exe`)提取 `.debug` 符号并写入 GNU debug link,打包为同 Release 下的 `reims-runtime-symbols-<commit>.tar.zst`(客户端默认不下载符号包)。`manifest.json` 记录最终剥离后可执行文件的 SHA-256。
### 2.3 用户数据目录与子进程环境
用户首次启动时自选非系统盘数据目录 `<DataRoot>`:
```text
<DataRoot>/
├── reims-go.json # 应用配置(数据目录、语言、外观、代理与通道设置等)
├── runtimes/
│ ├── <commit>/ # 解压后的便携运行时
│ └── current # 当前激活版本指向
├── config/ # 注入为 XDG_CONFIG_HOME(含 reims-ctl/vms.toml)
├── data/ # 注入为 XDG_DATA_HOME(含 reims-ctl/vms/、installers/、prebuilt/)
├── cache/ # 注入为 XDG_CACHE_HOME
├── shared/ # Guest Tools 共享目录
├── reports/ # 导出的脱敏排障日志包
└── tmp/ # 临时文件与 CLI 启动回传状态
```
调用 `reims-ctl.exe` / `reims-util.exe` 时,由 `internal/runtime` 统一注入隔离环境变量:
- `XDG_CONFIG_HOME=<DataRoot>\config`
- `XDG_DATA_HOME=<DataRoot>\data`
- `XDG_CACHE_HOME=<DataRoot>\cache`
- `REIMS_CTL_QEMU=<DataRoot>\runtimes\<active>\qemu\bin\qemu-system-x86_64.exe`
- `PATH=<DataRoot>\runtimes\<active>\bin;<System32>...`
---
## 3. 打包与 CI 自动构建
### 3.1 本地打包
运行 `pwsh -File scripts/pack-runtime.ps1 -Channel alpha` 一次产出以下发布附件:
1. `reims-runtime-win-x64-<commit>.tar.zst`(运行时主体)
2. `reims-runtime-symbols-<commit>.tar.zst`(独立调试符号包)
3. `reims-runtime-src-<commit>.tar.zst`(运行时源码、依赖补丁和重建说明)
4. `reims-runtime-msys2-src-<commit>.tar.zst`(MSYS2 copyleft DLL 源码包,由 [`scripts/pack-msys2-sources.ps1`](../scripts/pack-msys2-sources.ps1) 生成)
5. `SHA256SUMS.txt`(覆盖上述压缩包的统一校验清单)
打包前脚本会核对构建目录的 `git diff` 是否与声明的补丁逐字节一致;存在未声明修改或补丁不匹配时立即停止。
### 3.2 每日 CI 构建
Reims vGPU fork 的 [Preview 工作流](https://github.com/yxc0915/reims-vgpu/blob/master/.github/workflows/runtime-preview.yml) 每日调用 [Reims-Go 的运行时构建工作流](../.github/workflows/build-runtime.yml),也支持手动指定提交。在 `windows-latest`(MSYS2 CLANG64)执行以下步骤。
1. 读取 Reims vGPU fork 的运行时分支,并检出其中固定的 QEMU fork 提交。若该 Reims vGPU 提交已有运行时 Release,则跳过。
2. 按 [`patches/series.txt`](../patches/series.txt) 顺序为固定的依赖版本应用补丁。已合入上游的补丁会跳过并报告,遇到冲突时中止构建。
3. 执行上游 `scripts/install-ctl.sh --yes` 编译,调用 `scripts/pack-runtime.ps1 -Channel alpha` 打包。
4. 运行 [`scripts/check-runtime-alpha.ps1`](../scripts/check-runtime-alpha.ps1) 校验附件哈希、许可证、挂起能力声明,以及在不含 MSYS2 的 `PATH` 下验证 vGPU 设备枚举、CLI 版本和 `qcow2` 创建读取。
5. 通过后在 Reims vGPU fork 的 Releases 发布 Preview,标记为 GitHub 预发布(`alpha`)。从 Reims-Go 仓库发起的手动构建提供 CI 产物供验证。
> **CI 边界**:GitHub 托管的 Windows Server runner 不提供 WHPX,也无法复现 Windows 10 兼容性问题。CI 只验证可编译与控制面基本可用,实际能否启动 macOS 桌面必须经过第 5 节的真机冒烟。
### 3.3 客户端下载与安装
`internal/runtime` 从 GitHub Releases 查找 `runtime-<commit>`。正式运行时来自 `Nwflower/Reims-Go`,开启内核 Alpha 后同时列出 `yxc0915/reims-vgpu` 的 Preview。下载沿用环境变量与 Windows 系统代理,支持 HTTP `Range` 续传、强制 `SHA256SUMS.txt` 校验、临时目录原子解压与多版本切换。
---
## 4. 补丁队列
Reims vGPU 和 QEMU 的修改由各自的运行时 fork 维护。客户端仓库在 [`patches/`](../patches/) 维护其他运行时依赖的补丁。源码和补丁入口如下。
- 机器清单:[`patches/series.txt`](../patches/series.txt)
- 维护文档:[`patches/README.md`](../patches/README.md)
运行时包的 `manifest.json` 记录源码仓库、提交、运行时能力及打包时应用的依赖补丁和哈希。
---
## 5. 发布通道(`alpha` → `stable`)
上游提交频率高且无稳定 Release,默认用户不能直接暴露在未验证的上游 `HEAD` 下。运行时采用两级通道:
| 通道 | GitHub Release 形态 | 准入条件 |
| :--- | :--- | :--- |
| **`alpha`** | 预发布(Pre-release) | CI 每日自动构建并通过 `scripts/check-runtime-alpha.ps1` 全部校验 |
| **`stable`** | 正式发布(Release) | 从 `alpha` 晋升:在真实 Windows 10/11 宿主运行 [`scripts/smoke-runtime.ps1`](../scripts/smoke-runtime.ps1),验证纯净目录 `doctor`、启动至 macOS 桌面、截屏与正常关机,经人工确认后晋升 |
- 客户端默认仅获取 `stable` 通道;`alpha` 需用户在界面开启「接收 Alpha 版」或在 CLI 传入 `--alpha`。
- 晋升 `stable` 时,在 `Nwflower/Reims-Go` 正式 Release 分发已通过冒烟的原始资产及同一份校验清单。客户端以 Release 状态区分通道,包内 `manifest.json` 保留构建时的 `alpha` 标记。
---
## 6. 许可证与源码分发义务
Reims-Go 本体(Go 后端与前端外壳)采用 [Apache-2.0](../LICENSE) 协议,仅通过独立子进程调用运行时组件,不进行静态或动态链接。
由于便携运行时包含 GPLv2(QEMU)、`GPL-2.0-or-later OR LGPL-3.0-or-later`(`reims-vgpu` / `reims-ctl` / `metal2vulkan`)以及 MSYS2 CLANG64 / libva 动态库,每个公开运行时 Release **必须同处附带完整对应源码与许可证文本**:
1. **上游源码包(`reims-runtime-src-<commit>.tar.zst`)**:导出所用 commit 的四个上游仓库源码树、构建所需的 QEMU meson 子项目、`patches/` 中的全部补丁原文及重建说明。
2. **MSYS2 copyleft 源码包(`reims-runtime-msys2-src-<commit>.tar.zst`)**:由 [`scripts/pack-msys2-sources.ps1`](../scripts/pack-msys2-sources.ps1) 根据本机 pacman 元数据自动筛选全部无宽松替代协议的 GPL / LGPL / MPL 依赖包,下载官方 `.src.tar.zst` 并使用 `gpgv` 与 MSYS2 密钥逐一验签,同时附带 `MSYS2-PACKAGES.txt` 说明全部 DLL 归属与许可。
3. **许可证与声明**:运行时包根目录内置 [`NOTICE.md`](../NOTICE.md) 与 `licenses/` 全文。
4. **不含 Apple 专有文件**:任何仓库目录或运行时 Release 均不包含 macOS 安装包、恢复镜像、解密固件或 SMC 密钥;系统安装包均由用户端直连 Apple 服务器获取。