const std = @import("std"); const build_helpers = @import("build_helpers"); pub fn build(b: *std.Build) void { const arch = b.option(build_helpers.Architecture, "arch", "The target architecture") orelse .amd64; const ukernel_dep = b.dependency("ukernel", .{ .arch = arch, }); const ukernel_artifact = ukernel_dep.artifact("ukernel"); const ukernel_inst = b.addInstallFile(ukernel_artifact.getEmittedBin(), arch.kernelExeName()); b.getInstallStep().dependOn(&ukernel_inst.step); const root_69 = b.dependency("root_server", .{ .arch = arch, .number = 0x69, }).artifact("root_server"); const root_69_inst = b.addInstallFile(root_69.getEmittedBin(), "root-69.elf"); b.getInstallStep().dependOn(&root_69_inst.step); const root_420 = b.dependency("root_server", .{ .arch = arch, .number = 0x420, }).artifact("root_server"); const root_420_inst = b.addInstallFile(root_420.getEmittedBin(), "root-420.elf"); b.getInstallStep().dependOn(&root_420_inst.step); // Run in QEMU run_blk: { // Step 1: Install edk2 files to zig-out const ovmf_code, const ovmf_vars = blk: { const ovmf_dep = b.lazyDependency("edk2_binary", .{}) orelse break :run_blk; break :blk .{ ovmf_dep.path("bin/RELEASEX64_OVMF_CODE.fd"), ovmf_dep.path("bin/RELEASEX64_OVMF_VARS.fd"), }; }; const loader_path = blk: { const limine_dep = b.lazyDependency("limine_binary", .{}) orelse break :run_blk; break :blk limine_dep.path("BOOTX64.EFI"); }; // Install Required dependencies const code_install = b.addInstallFile(ovmf_code, "OVMF_CODE_X64.fd"); const vars_install = b.addInstallFile(ovmf_vars, "OVMF_VARS_X64.fd"); const loader_install = b.addInstallFileWithDir(loader_path, .{ .custom = "EFI/BOOT" }, "BOOTX64.EFI"); const config_install = b.addInstallFileWithDir(b.path("assets/limine.conf"), .{ .custom = "limine" }, "limine.conf"); const qemu_cmd = b.addSystemCommand(&.{ "qemu-system-x86_64", "-smp", "4", "-m", "4G", "-monitor", "stdio", "-drive", "format=raw,file=fat:rw:zig-out", "-drive", "if=pflash,format=raw,readonly=on,file=zig-out/OVMF_CODE_X64.fd", "-drive", "if=pflash,format=raw,file=zig-out/OVMF_VARS_X64.fd" }); // Depend on the install step (ukernel and root task) qemu_cmd.step.dependOn(b.getInstallStep()); // Depend on OVMF code+vars, Limine bootloader, and Limine cfg qemu_cmd.step.dependOn(&code_install.step); qemu_cmd.step.dependOn(&vars_install.step); qemu_cmd.step.dependOn(&loader_install.step); qemu_cmd.step.dependOn(&config_install.step); // Create the actual public callable step and depend on our command const qemu_step = b.step("qemu", "Run in QEMU"); qemu_step.dependOn(&qemu_cmd.step); } }