const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const mod = b.addModule("danos", .{ .root_source_file = b.path("src/root.zig"), .target = target, }); const exe = b.addExecutable(.{ .name = "danos", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "danos", .module = mod }, }, }), }); b.installArtifact(exe); const efiexe = b.addExecutable(.{ .name = "BOOTX64", .root_module = b.createModule(.{ .root_source_file = b.path("src/efi.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .uefi, }), .optimize = optimize, }), }); 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. 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"; 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"; // Assemble an EFI System Partition layout: esp/EFI/BOOT/BOOTX64.efi const efi_install = b.addInstallArtifact(efiexe, .{ .dest_dir = .{ .override = .{ .custom = "esp/EFI/BOOT" } }, }); // The firmware needs to write NVRAM, so give it a writable copy of the vars. const vars_copy = b.addSystemCommand(&.{ "cp", "-f", ovmf_vars }); const vars_out = vars_copy.addOutputFileArg("OVMF_VARS.4m.fd"); const run_efi = b.addSystemCommand(&.{ "qemu-system-x86_64", "-machine", "q35", "-m", "128M", "-drive", b.fmt("if=pflash,format=raw,readonly=on,file={s}", .{ovmf_code}), }); run_efi.addArg("-drive"); run_efi.addPrefixedFileArg("if=pflash,format=raw,file=", vars_out); // Present the ESP directory to the guest as a FAT drive. run_efi.addArgs(&.{ "-drive", b.fmt("format=raw,file=fat:rw:{s}/esp", .{b.install_path}), "-net", "none", }); run_efi.step.dependOn(&efi_install.step); const run_efi_step = b.step("run-efi", "Boot the EFI app in QEMU (OVMF)"); run_efi_step.dependOn(&run_efi.step); // const run_cmd = b.addRunArtifact(exe); // const run_step = b.step("run", "Run the app"); // run_step.dependOn(&run_cmd.step); // run_cmd.step.dependOn(b.getInstallStep()); // // if (b.args) |args| { // run_cmd.addArgs(args); // } const mod_tests = b.addTest(.{ .root_module = mod, }); const run_mod_tests = b.addRunArtifact(mod_tests); const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); const run_exe_tests = b.addRunArtifact(exe_tests); const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_mod_tests.step); test_step.dependOn(&run_exe_tests.step); }