A new x86-64 VM needed an OpenCore image and an installer made by hand with OSX-KVM or ULTMOS. reims-ctl now runs reims-util for both: pick a macOS version (n in the interface, create --macos on the command line) and it downloads the installer from Apple, makes the VM's OpenCore image with OVMF and a Mac identity of its own, and makes the disk. - create --macos VERSION downloads Apple's recovery image (about 1 GB), or with --offline an installer of one release (13 to 20 GB). Installers are kept in the data directory's installers for the next VM, one reims-util at a time writes there, and a stopped download continues. The download comes before the VM's directory, so stopping it leaves no VM half made, and reims-util ends with reims-ctl on Linux. What create is given (a disk, an installer, an OpenCore image and the OVMF beside it, reims-util itself) is checked before the download and the disk's copy, and the VM list is read again before the VM joins it, so VMs made or deleted during a download stay as they are. - --opencore is optional: without it reims-util makes the image, with the VM's MAC as its ROM, and an iMacPro1,1 for macOS 10.13 and 10.14. An image of the user's brings OVMF_CODE.fd and OVMF_VARS.fd beside it, as reims-util writes them. - The interface's form asks where macOS comes from, the version first; with no name, the VM takes the version's, skipping names a VM or a leftover directory has. A VM with an installer says in its details, and create prints, how to install macOS from it; one made from a disk is reminded to set Metal's error mode. - A new disk needs an installer or a download: a VM of an empty disk and no installer is refused. - Every installer attaches as a read-only disk (snapshot=on), a DMG converted to a raw image in the VM's directory, so the CD drive is gone: a change of installer applies at the next start. vm.toml's installer_kind is no longer written, and is ignored where an older vm.toml has it. A missing installer says how to eject it. - reims-ctl __record-install, which scripts/install-ctl.sh runs last, installs reims-util at the commit reims_util.rs pins, so the update that brings this reims-ctl installs it too, though it runs the script it started with. doctor checks for it in place of the system's OVMF, and the install no longer adds the ovmf or edk2-ovmf package. - vm.max_map_count: a new VM's default of up to 16 GiB needs about 1.13 million mappings, more than the 1048576 suggested (CachyOS's stock value). The README, the install script, doctor and the start warning suggest 2097152, which covers 30 GiB, and check against what the VM, the largest VM or a new one's default needs. - Updating from the interface while a create runs says the restart stops it, as quitting does. Dropped, as reims-util's images leave nothing for them to cover: - create --from-script and the interface's launch-script import, which read OSX-KVM's and ULTMOS's QEMU scripts. A VM made from one keeps working; its vm.toml names its own copies. - The search for OVMF beside a user's OpenCore image in those projects' layouts, QEMU's edk2 build and the distributions' packages, and --firmware-code and --firmware-vars. - create --disk-mode overlay: copy, a reflink where the file system can, or in-place covers an existing disk. A VM made with an overlay keeps working. - --cpu-model and --cpu-flags on create and set, and the edit form's CPU fields: new VMs take Skylake-Client-noTSX-IBRS. vm.toml keeps cpu_model and cpu_flags, so an older VM keeps its model; docs/qemu.md says how to change it there. - --installer's --iso and --cdrom aliases. README, the help and the docs no longer point at OSX-KVM or ULTMOS. README step 3 describes reims-util's OpenCore picker (5 seconds, which an arrow key stops, measured on homelab-ms01), and architecture.md 11.4 counts its image among those that keep AvoidRuntimeDefrag on.
11 KiB
Developing reims-vgpu
The repository's layout, its tests, and the Rust library's crates, commands, build profiles and
features. README.md lists what working on the code needs and the make targets,
and AGENTS.md has the rules for changing it.
Repo layout
AGENTS.md the rules for working on the repository
Cargo.toml the Cargo workspace, with Cargo.lock,
rust-toolchain.toml, clippy.toml and
.cargo/config.toml
crates/ its six crates (below), and reims-ctl, a
workspace of its own that links none of them
xtask/ cargo xtask (below)
firmware/ the option ROM: the PCI device's UEFI driver,
in C
tests/
suite/ the behaviour-lock suite (its README)
scripts/
install-ctl.sh builds and installs reims-ctl and its QEMU (and
reims-util, on Linux)
run_vmapple.sh boots a macOS VM on make qemu's QEMU
vm_drive.py, vm_ocr.swift drive a VM through a fixed tour
walk_window_macos.sh the manual walk of a display's window on macOS
docs/
api.md the C API and the Rust API it wraps, with the
settings and environment variables
architecture.md how the code is built
conventions.md the conventions the code follows
development.md this file: the layout, the tests, the crates
and their commands
testing.md the suite's specification, and the guest ABI
qemu.md QEMU on the library: its build, VM boots and
what they measured
lessons.md traps the suite and reviews found
accuracy-ledger.md what the Vulkan platform's defaults trade
against Metal's answers, and the switches
vendor/qemu/ QEMU with apple-gfx on reims-vgpu (submodule)
assets/readme/ the README's screenshots
LICENSE the license, and LICENSES/ its texts (README.md, License)
Testing
cargo xtask checkruns the lints, rustfmt, clippy and every unit test. Run it once before a branch that changes code merges.make smoke(cargo xtask smoke) links a guest program with the library the way QEMU links it and runs an isolated guest task.- The behaviour-lock suite (
tests/suite,make test) plays the hypervisor and the guest, and compares what the guest and the host observe with its expected files. testing.md specifies the suite and the guest ABI it is written against, and tests/suite/README.md is its user's guide. - The pins:
crates/reims-vgpu-c/tests/pins, a C host against the C API, whichcargo xtask checkruns with the other tests.
Expected files and pin files are recorded from the checkout's own build. A change that means to
alter behaviour records them again in the same commit (make bless TEST=<patterns> ARGS=--update,
RVG_PINS_RECORD=1 cargo test -p reims-vgpu-c --test pins), so the diff shows exactly what changed
for the guest and the host.
The Rust library
architecture.md describes the crates, threads and locks, the raise and death
model, the platform boundary, isolated tasks, the APIs, the option ROM and QEMU. Each module's //!
doc holds its area's ordering contracts and the measured platform facts it relies on.
Crates
| crate | path | role |
|---|---|---|
reims-vgpu-core |
crates/reims-vgpu-core |
all behaviour, generic over P: Platform; links no Apple framework |
reims-vgpu-metal |
crates/reims-vgpu-metal |
the Platform over Metal, IOSurface, Mach VM and threads, and the library's shaders (src/gpu/shaders.metal) |
reims-vgpu-vulkan |
crates/reims-vgpu-vulkan |
the Platform over metal2vulkan's runtime: the library on Linux, and on macOS behind the vulkan features, on MoltenVK |
reims-vgpu-window |
crates/reims-vgpu-window |
a display's own window: AppKit's or SDL3's on macOS, SDL3's on Linux, its input and the host's screens; knows nothing of devices or displays. features.md lists what the window does, each entry deliberate |
reims-vgpu |
crates/reims-vgpu |
the public Rust API; the process's platform; a display's window over the window crate |
reims-vgpu-c |
crates/reims-vgpu-c |
the C API (rvg_*, include/reims_vgpu.h), which QEMU links; cdylib, staticlib and rlib |
xtask |
xtask |
cargo xtask, below |
Build and test
Run from the repository root. cargo xtask is an alias for cargo run --package xtask --
(.cargo/config.toml), and with no command it lists the commands.
cargo build --workspace
cargo nextest run --workspace
cargo xtask check # the lints, rustfmt, clippy and every test; run it once before a merge
cargo xtask dist # target/dist: the library, its header, reims-vgpu.pc and
# the option ROM, for a host that links it through pkg-config
cargo xtask smoke # a guest linked with the library as QEMU links it (make smoke)
| command | what it does |
|---|---|
testkit |
core's testkit module is gated, and only dev-dependencies turn its feature on (D50) |
header [--check] |
include/reims_vgpu.h from cbindgen; --check fails when the committed header drifts from cbindgen's output |
dist |
the library as a plain library, below |
smoke |
the arm64 smoke of the library, below |
check |
testkit, header --check, rustfmt, clippy and the tests (architecture.md 13.1); --no-cargo skips the cargo steps |
cargo xtask check tests with every feature but reims-vgpu-c/vulkan, which puts the C API on the
Vulkan platform, and lints with every feature too. On a Mac it also clippy-checks the Linux target,
and, where Rosetta is installed, runs core's tests as x86_64-apple-darwin.
Dist
cargo xtask dist # release, into target/dist
cargo xtask dist --profile checked --out /tmp/reims-vgpu
cargo xtask dist --platform vulkan # the Vulkan platform, into target/dist-vulkan
cargo xtask dist builds reims-vgpu-c and writes the library for a host that links it the way it
links its other dependencies, through pkg-config:
target/dist/
include/reims_vgpu.h the committed header
lib/libreims_vgpu.a the staticlib
lib/libreims_vgpu.dylib the cdylib, @rpath/libreims_vgpu.dylib, signed ad hoc
lib/pkgconfig/reims-vgpu.pc the package
share/reims-vgpu/ReimsVgpu.rom the EFI option ROM, built from firmware/
share/doc/reims-vgpu/ the license: LICENSE and LICENSES/, as in the repository
reims-vgpu.pc takes its prefix from its own path, so the tree can move. Its Libs.private lists
the system frameworks and libraries a static link needs, and its optionrom variable names the
ROM, which QEMU installs as apple-gfx-pci's default romfile. QEMU and the smoke link
libreims_vgpu.a, so the library is part of their binaries; the suite's runner links
libreims_vgpu.dylib with an LC_RPATH at the tree's lib.
--platform vulkan builds the C API on the Vulkan platform into target/dist-vulkan, laid out the
same; the smoke (--dist) and the suite (pgtest run --dist) take either tree. On Linux dist
builds that platform alone, with libreims_vgpu.so in place of the dylib (architecture 11.3).
CARGO_TARGET_DIR moves every output, the dist tree included, out of target.
Smoke
cargo xtask dist
cargo xtask smoke # --dist DIR for another tree
It runs arm64 only: a guest program (xtask/src/smoke_guest.m), linked statically with the dist
tree's library, that brings up a device and runs an isolated task, whose facts must equal the
library's expected values (GUEST_EXPECTED in xtask/src/smoke.rs). make smoke builds the tree
and runs it.
The behaviour suite
The suite (tests/suite) runs against the library, by default the checkout's dist tree
(target/dist):
make test # the dist tree, then the suite
cd tests/suite && python3 -m pgtest run -j 32 # the same, with pgtest's options
make bless TEST=<patterns> # record new or changed scenarios from the checkout's build
make bless TEST=<patterns> ARGS=--update # record them again after a deliberate change
testing.md 5.7 and tests/suite/README.md have the rest.
Profiles
Set in Cargo.toml (architecture 2.3):
| profile | settings | why |
|---|---|---|
dev |
panic = "unwind", overflow checks on |
an unannotated arithmetic slip dies in tests |
release |
panic = "unwind", overflow checks off, debug = "line-tables-only", thin LTO |
the product. Wrapping is explicit where the guest's values wrap (D19), so the checks add nothing |
checked |
release plus overflow checks and debug assertions |
a second pass of the suite: a death here is an arithmetic site review missed |
panic = "unwind"everywhere (D9). objc2'sexception::catchneeds it. It is not a way to survive a panic:reims-vgpu's singleton installs a hook that aborts before anything unwinds, so an unintended panic dies at its op with no side effects.- objc2's debug assertions are on in
devand off inchecked([profile.checked.package.objc2], D36). They panic on a message to nil, a missing method and an encoding the runtime disagrees with, which the library never sends, so the tests that send to real Metal check each send. Declarations are also checked withAnyClass::verify_selinreims-vgpu-metal/tests/spi_encodings.rs. - objc2's
exceptionfeature is always on, andcatch-allnever.
Features
reims-vgpu/vulkanandreims-vgpu-c/vulkan: the Vulkan platform as the API's, and the C API's, platform. Off by default on macOS; on Linux the library builds only with them.macos-sdl(reims-vgpu-window, forwarded byreims-vgpuandreims-vgpu-c), on by default: SDL3's window on macOS, whichREIMS_VGPU_WINDOW_IMPL=sdlopens in place of AppKit's. Without it the macOS library has no SDL.reims-vgpu-window/sdl-no-link: SDL left unbuilt, for the Linux target's clippy on a Mac.reims-vgpu-core/testkit:core::testkitfor other crates' tests.reims-vgpu/testkit: the same, through the public crate, and each handle's core object.
api.md section 2 lists the device's settings and the environment variables the library reads.