Update build to run qemu on MacOS

This commit is contained in:
Daniel Samson
2026-07-03 16:43:00 +01:00
parent 31bf86af56
commit 50f3610768
3 changed files with 76 additions and 10 deletions
+31 -4
View File
@@ -16,6 +16,18 @@ fn ensureZigVersion() void {
}
}
/// Return the first path in `candidates` that exists on the build host, else the
/// first candidate as a fallback so a missing-firmware error still names a
/// concrete (and, by convention, the primary) path. Used to locate OVMF firmware
/// across distro/OS layouts without configuration.
fn firstExisting(io: std.Io, candidates: []const []const u8) []const u8 {
for (candidates) |path| {
std.Io.Dir.accessAbsolute(io, path, .{}) catch continue;
return path;
}
return candidates[0];
}
pub fn build(b: *std.Build) void {
ensureZigVersion();
@@ -105,18 +117,33 @@ pub fn build(b: *std.Build) void {
b.installArtifact(efiexe);
// --- run-efi: boot BOOTX64.efi in QEMU with OVMF firmware ---
// OVMF paths follow the Arch (edk2-ovmf) layout; override with -Dovmf-code
// and -Dovmf-vars if your distro installs them elsewhere.
// Firmware lives in different places per OS/distro, so probe the known
// layouts (Arch, Debian/Ubuntu, Fedora, macOS Homebrew) and use the first
// that exists. Override with -Dovmf-code / -Dovmf-vars if yours is elsewhere.
const ovmf_code = b.option(
[]const u8,
"ovmf-code",
"Path to the OVMF_CODE firmware image",
) orelse "/usr/share/edk2/x64/OVMF_CODE.4m.fd";
) orelse firstExisting(b.graph.io, &.{
"/usr/share/edk2/x64/OVMF_CODE.4m.fd", // Arch
"/usr/share/OVMF/OVMF_CODE_4M.fd", // Debian/Ubuntu
"/usr/share/OVMF/OVMF_CODE.fd", // older Debian/Ubuntu
"/usr/share/edk2-ovmf/x64/OVMF_CODE.fd", // Fedora
"/opt/homebrew/share/qemu/edk2-x86_64-code.fd", // macOS Homebrew (Apple Silicon)
"/usr/local/share/qemu/edk2-x86_64-code.fd", // macOS Homebrew (Intel)
});
const ovmf_vars = b.option(
[]const u8,
"ovmf-vars",
"Path to the OVMF_VARS firmware image (a writable copy is made)",
) orelse "/usr/share/edk2/x64/OVMF_VARS.4m.fd";
) orelse firstExisting(b.graph.io, &.{
"/usr/share/edk2/x64/OVMF_VARS.4m.fd", // Arch
"/usr/share/OVMF/OVMF_VARS_4M.fd", // Debian/Ubuntu
"/usr/share/OVMF/OVMF_VARS.fd", // older Debian/Ubuntu
"/usr/share/edk2-ovmf/x64/OVMF_VARS.fd", // Fedora
"/opt/homebrew/share/qemu/edk2-i386-vars.fd", // macOS Homebrew (Apple Silicon)
"/usr/local/share/qemu/edk2-i386-vars.fd", // macOS Homebrew (Intel)
});
// Assemble an EFI System Partition layout: esp/EFI/BOOT/BOOTX64.efi
const efi_install = b.addInstallArtifact(efiexe, .{