Wails shell over the existing Go core (app.go, main.go, wails.json, build/), with a React frontend for the VM list, VM detail, host page, create wizard and settings, plus process helpers for the driver and runtime packages. UI redesign stage 0 (docs/ui-redesign.md): - VM actions live in the page header: one primary action per state, icon-only secondary actions with tooltips, the rest in a "..." menu - install guide is a single card with the only "eject installer" button - summary is an icon + value row; paths, ICD, CPU model and runtime hash moved to a collapsed "technical details" section - logs no longer auto-open; a status bar shows merged download progress and an error count; the log view sticks to the bottom - busy states on actions, toasts for results, custom delete dialog with "keep disk files" - design tokens, Windows font stack, integer type scale, no inline styles - keyboard: sidebar listbox navigation, focus rings, Ctrl+N / Ctrl+, / Ctrl+L - copy rewritten per the restraint rules in §4.5 - Radix primitives and lucide icons replace hand-rolled widgets Backend: OpenVMFolder binding to show a VM's directory in Explorer. Docs: shell-design.md revised for decisions D1 and D4. Vite dev server pinned to 127.0.0.1 so `wails dev` can reach it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
13 KiB
Markdown
137 lines
13 KiB
Markdown
# 便携运行时规范(Portable Runtime Spec)
|
||
|
||
> 实测日期:2026-11-28
|
||
> 基准上游:`steelbrain/reims-vgpu` commit `3731afd9b13416a24f74ec27a90b3913aef2dcc0`(QEMU `11.1.90`,`reims-util 0.1.0`)
|
||
> **本地补丁**:本机实测用的 QEMU **不是纯上游构建**。`vendor/qemu`(`4571bc5`)的 `target/i386/whpx/whpx-all.c` 带着一个未提交的修改,内容与 [`macos-vm-lab/patches/qemu-whpx-win10-compat.patch`](../../macos-vm-lab/patches/qemu-whpx-win10-compat.patch)(SHA256 `3eed7895…0304b8`,无 BOM、LF 行尾)一致。没有它,Win10 19045 上 VM 起不来。见第 5 节。
|
||
|
||
## 1. 脱离 MSYS2 / Rust / 源码仓库的实测结论
|
||
|
||
2026-11-28 在本机(Windows 10 19045 x64 + i7-12700K + RTX 4070 Ti)构造了纯净临时环境:
|
||
- `PATH` 仅保留便携 `bin\` 与 Windows 系统目录(`System32` / `Wbem` / `WindowsPowerShell`),**完全不含** `MSYS2`、`Cargo/Rust`、`Git`、`reims-vgpu` 源码目录。
|
||
- 通过 `XDG_CONFIG_HOME`、`XDG_DATA_HOME`、`XDG_CACHE_HOME` 将所有读写重定向至隔离目录。
|
||
|
||
实测结果:
|
||
|
||
| 检查项 | 结果 | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| `qemu-system-x86_64.exe -device help` | ✅ PASS | 正确列出 `reims-graphics-pci`(71 个 CLANG64/libva DLL 已由上游 `install-ctl.sh:783-797` 随 `bin\` 打包) |
|
||
| `reims-util.exe --version` | ✅ PASS | 输出 `reims-util 0.1.0` |
|
||
| `reims-ctl.exe list --json` | ✅ PASS | 输出 `[]`,无报错 |
|
||
| `reims-ctl.exe doctor` — `host` / `files` / `qemu` / `audio` / `hypervisor platform` / `vulkan` / `sound` / `desktop` / `reims-util` | ✅ 9/9 PASS | 全部 `ok`,正确识别 RTX 4070 Ti(`nv-vk64.json`)与 XDG 数据路径 |
|
||
| `reims-ctl.exe doctor` — `checkout` | ❌ FAIL(预期内) | 见第 2 节源码分析:仅因 `install.toml` 缺少必填 `repo` 字段,且 `checkout` 仅用于 `reims-ctl update` |
|
||
|
||
**结论**:`reims-vgpu` 的 Windows 运行时在二进制层面**已经自包含,可以脱离 MSYS2 与编译环境独立运行**。
|
||
|
||
**限定条件**:这次实测的 `qemu/` 带着第 5 节的 Win10 补丁。纯上游构建在 Win10 19045 上已于 2026-11-28 实测必现两处崩溃(见第 5 节证据)。所以运行时包必须说明自己带了哪些补丁,不能写成「纯上游 `3731afd`」。
|
||
|
||
## 2. 上游源码关键发现(`3731afd`)
|
||
|
||
1. **Option ROM 与 Guest Kext 已内嵌**(`crates/reims-ctl/src/prebuilt.rs:1-32`):
|
||
- `reims-ctl.exe` 编译时已将 `ReimsGraphics.rom` 与 `guest/prebuilt/set.toml` 内的全部 kext 嵌入二进制,运行时按内容哈希释放到 `<XDG_DATA_HOME>/reims-ctl/prebuilt/`,不依赖源码树。
|
||
2. **XDG 路径重定向在 Windows 原生生效**(`crates/reims-ctl/src/paths.rs:54-77`):
|
||
- 只要传入 Windows 绝对路径格式的 `XDG_CONFIG_HOME`、`XDG_DATA_HOME`、`XDG_CACHE_HOME`,`reims-ctl` 与 `reims-util` 均遵守重定向,不会写入 `%USERPROFILE%`。
|
||
- 唯一仍在系统盘的是临时运行目录 `%TEMP%\reims-ctl`(用于短路径 socket,体积极小)。
|
||
- 上游另有两个专用变量,优先级高于 XDG:`REIMS_CTL_CONFIG_DIR`(`paths.rs:61-66`)和 `REIMS_CTL_DATA_DIR`(`paths.rs:68-73`)。它们直接给出 `reims-ctl` 的目录,不再拼 `reims-ctl` 子目录。缓存目录没有专用变量,只认 `XDG_CACHE_HOME`(`paths.rs:75-77`)。`reims-util` 是否认这两个变量**待验证**,所以 `reims-go` 先继续注入 XDG 三件套。
|
||
3. **QEMU 定位优先级**(`crates/reims-ctl/src/install.rs:85-101`):
|
||
- 优先读取环境变量 `REIMS_CTL_QEMU`(`qemu-img.exe` 自动从其同级目录查找);
|
||
- 未设置时回退到 `<XDG_DATA_HOME>\reims-ctl\qemu\current\bin\qemu-system-x86_64.exe`。
|
||
4. **`install.toml` 的 `repo` 字段**(`crates/reims-ctl/src/install.rs:34-50`):
|
||
- `Install.repo` 没有 `#[serde(default)]`,省略会导致 `Install::load()` 返回 `None`,令 `doctor` 报 `FAIL checkout`。
|
||
- `reims-go` **不调用 `reims-ctl update`**,而是由自带的 Runtime Manager 下载新版预编译包并原子切换版本目录;自检模块直接消费 `reims-go` 的健康检查,不依赖 `checkout` 项。
|
||
|
||
## 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 的十分之一)。
|
||
|
||
### 3.1 运行时发布包结构(`reims-runtime-win-x64-<commit>.tar.zst`)
|
||
|
||
```text
|
||
reims-runtime-<commit>/
|
||
├── manifest.json # 上游 commit、vendor/qemu commit、补丁清单与哈希、通道、构建日期、各文件 SHA256
|
||
├── 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 # 71 个自包含 CLANG64 + libva/vaon12 DLL
|
||
└── share/ # QEMU pc-bios / edk2 / keymaps 等数据文件
|
||
```
|
||
|
||
> **版本耦合约束**:`reims-ctl.exe`、`reims-util.exe` 与 `qemu/` 必须来自**同一个上游 commit**,作为单一版本目录原子安装与回滚,避免协议或内嵌 kext 版本错配。
|
||
|
||
### 3.2 用户数据目录结构(由用户在向导中选择,默认非系统盘如 `D:\Data\reims-go\`)
|
||
|
||
```text
|
||
<DataRoot>/
|
||
├── reims-go.json # reims-go 自身配置(数据目录、默认硬件参数、镜像加速等)
|
||
├── runtimes/
|
||
│ ├── <commit>/ # 解压后的便携运行时(含 bin/ 与 qemu/)
|
||
│ └── current -> <commit> # 当前激活版本(目录联接或配置文件指向)
|
||
├── config/ # 注入为 XDG_CONFIG_HOME(含 reims-ctl/vms.toml)
|
||
├── data/ # 注入为 XDG_DATA_HOME(含 reims-ctl/vms/、installers/、prebuilt/)
|
||
├── cache/ # 注入为 XDG_CACHE_HOME
|
||
└── images/ # Golden Images 与 CoW backing files(M3)
|
||
```
|
||
|
||
调用 `reims-ctl.exe` 时,`reims-go` 在子进程环境变量中统一注入:
|
||
- `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>...`(确保 `reims-ctl` 能直接找到同目录的 `reims-util.exe`)
|
||
|
||
## 4. 打包与发布流水线(M0 / M4)
|
||
|
||
- **本地打包验证(M0)**:编写 `scripts/pack-runtime.ps1`,直接从本机已编译的 `reims-vgpu` 产物生成 `reims-runtime-win-x64-3731afd.tar.zst` 与 `manifest.json`(含 SHA256),验证纯净解压启动。
|
||
- **自动化 CI(M4)**:在 GitHub Actions `windows-latest` runner 上使用 MSYS2 CLANG64,先打上第 5 节的补丁队列,再执行上游构建脚本,产出 `reims-runtime-win-x64-<commit>.tar.zst`、`SHA256SUMS.txt` 和对应源码包(第 7 节)。CI 产物只进 `candidate` 通道,不直接发给用户(第 6 节)。
|
||
- **CI 测不到 Win10**:`windows-latest` 是 Windows Server 2022/2025,复现不了第 5 节的 Win10 问题,而且 GitHub 托管 runner 一般不提供 WHPX。CI 只能保证「能构建、`-device help` 列出 `reims-graphics-pci`」,能不能启动 VM 要靠第 6 节的本机冒烟测试。
|
||
|
||
## 5. 补丁队列(把上游当内核来优化的方式)
|
||
|
||
原则:**不长期维护 fork,补丁数以清零为目标。** 每个补丁都要经过「本地带着发 → 由人向上游提 PR → 上游合并后删掉本地副本」这个周期。
|
||
|
||
| 补丁 | 作用对象 | 解决的问题 | 状态 |
|
||
| :--- | :--- | :--- | :--- |
|
||
| `qemu-whpx-win10-compat.patch` | `vendor/qemu` 的 `target/i386/whpx/whpx-all.c` | ① `whpx_tsc_deadline_refused()`(`3210-3230`)原实现在真实分区上建、删 vCPU 0,Win10 19045 上随后 `whpx_init_vcpu()` 再次创建 vCPU 0 时必现 `WHvCreateVirtualProcessor` 返回 `E_INVALIDARG`(`hr=80070057`),改为独立临时探测分区;② `whpx_set_registers()`(`534`)直接调用 `WHvResetPartition` 未判空,Win10 19045 的 `WinHvPlatform.dll` 不导出该接口导致重置阶段必现 `0xc0000005 at 0x0` 崩溃(已核对导出表,10 个 supplemental API 中仅此一处漏判空) | 2026-11-28 实测复现并修复,待提交上游 PR(由人操作) |
|
||
|
||
### 5.1 本机实测排障与待验证优化沉淀(2026-11-28,Win10 19045)
|
||
1. **Win10 下默认关闭 `kernel-irqchip` 导致高 CPU 开销(待验证优化)**:
|
||
- Win10 19045 因缺少 `WHvCapabilityCodeProcessorPerfmonFeatures`(`hr=80370300`)进入 `whpx_is_legacy_os()` 分支(`whpx-all.c:3347-3397`),默认关闭 `kernel-irqchip`,导致上游专为 WHPX 实现的无锁 MSI-X(`whpx_send_msi_direct`)和无 BQL 运行(`whpx_vcpu_pre_run`,见上游 `docs/qemu.md:135-136`)全部失效;实测在 Guest 内以 6.7–10 MB/s 写入磁盘时 QEMU 消耗达 1.7–2.7 个满核 CPU 与 ~15,530 ops/s。
|
||
- 本机 `WinHvPlatform.dll` 导出表已确认包含 `WHvSetVirtualProcessorInterruptControllerState2` 与 `WHvRequestInterrupt`,后续在 M3.1 实测强制 `-accel whpx,kernel-irqchip=on` 的稳定性;若稳定则优先向上游提 PR。
|
||
2. **Windows 提交内存(Commit Limit)硬拦截**:
|
||
- 32 GB 物理内存宿主在开启常见软件后,实测可用提交内存(`FreeVirtualMemory`)仅 `14.7 GiB`(即使空闲物理内存仍有 `17.3 GiB`);QEMU 启动时一次性 `CreateFileMapping` 提交全部 Guest RAM,分配 `16G` 直接退出报 `Cannot set up guest memory 'ram': 系统资源不足`。`reims-go` 必须在体检与启动前检测提交内存并动态限位(详见 [`architecture.md`](architecture.md) 3.1 节)。
|
||
3. **在线 Recovery 拉取 17 GB 极易因 Apple CDN 断流失败**:
|
||
- 实测拉取 961 MB 恢复镜像期间 Apple CDN 即出现 6 次 `Peer disconnected`;在 Recovery 内经 QEMU 用户态 NAT(`slirp`)拉取 ~17 GB 系统包时,`OSISDownloadOperation` 抗断流能力差,易在接近完成(实测 `disk.qcow2` 已达 `16.95 GiB`)时失败。因此 `reims-go` GUI 默认改为宿主机调用 `reims-util offline-installer --json` 断点续传下载离线安装包(详见 [`architecture.md`](architecture.md) 3.3 节)。
|
||
|
||
规则:
|
||
1. 补丁原文的权威副本放在 `reims-go/patches/`。macos-vm-lab 的那份是研究时的原始记录。
|
||
2. 每次跟进上游 commit 时,先 `git apply --check`。打不上就停在 `candidate`,不要自动改补丁。
|
||
3. 补丁文件必须是**无 BOM、LF 行尾**,由 `.gitattributes` 的 `*.patch -text` 保证。用 PowerShell 5.1 的 `Out-File` 或 `>` 生成的补丁会带 BOM 和 CRLF,`git apply` 不认(2026-11-28 实测,原始副本就是这样)。
|
||
4. 上游合并之后,在表里记下合并 commit,然后删掉补丁。
|
||
|
||
## 6. 发布通道(已验证通道)
|
||
|
||
上游变动非常快(2026-11-21 到 11-28 有 100 多个提交,截至 2026-11-28 没有任何 GitHub Release),出现过某个提交弄坏 `reims-ctl` 安装的情况([issue #138](https://github.com/steelbrain/reims-vgpu/issues/138))。所以运行时**不跟上游最新 commit**,而是分两级:
|
||
|
||
| 通道 | 来源 | 进入条件 |
|
||
| :--- | :--- | :--- |
|
||
| `candidate` | CI 按指定上游 commit 构建并打补丁 | 能构建;`qemu-system-x86_64.exe -device help` 列出 `reims-graphics-pci`;SHA256 清单齐全 |
|
||
| `stable` | 从 `candidate` 升级 | 在一台真实 Win10 或 Win11 宿主上跑通冒烟测试:`doctor` 的运行时检查全部通过,用 golden 镜像启动到 macOS 桌面,截一张屏,正常关机。由人确认后升级 |
|
||
|
||
`reims-go` 客户端默认只拉 `stable`,`candidate` 要用户主动打开。这层筛选是 `reims-go` 相对于「自己跑上游安装脚本」的主要价值之一。
|
||
|
||
## 7. 许可证与源码义务
|
||
|
||
发布二进制,就要同时提供对应的源码。只给上游链接不够,因为本地补丁不在上游。每个运行时 Release 附带:
|
||
- `reims-vgpu`(含 `reims-ctl`)、`qemu-reims-vgpu`(**含本地补丁**)、`metal2vulkan`、`reims-util` 在所用 commit 的源码包;
|
||
- 运行时里 MSYS2 CLANG64 DLL 对应的包名、版本,以及其中 LGPL/GPL 组件(如 glib)的源码或获取方式(具体清单**待 M0.1 打包时列出**);
|
||
- `licenses/` 里的许可证全文。
|
||
|
||
`reims-go` 外壳用 MIT,前提是它和这些组件只通过独立进程交互,不链接它们。
|