diff --git a/build.zig b/build.zig index db08f83e..1a88124a 100644 --- a/build.zig +++ b/build.zig @@ -2,11 +2,17 @@ // SPDX-License-Identifier: BSD-2-Clause const std = @import("std"); +const LazyPath = std.Build.LazyPath; const src = [_][]const u8{ "src/guest.c", "src/util/util.c", "src/util/printf.c", + "src/virtio/mmio.c", + "src/virtio/block.c", + "src/virtio/console.c", + "src/virtio/net.c", + "src/virtio/sound.c", }; const src_aarch64_vgic_v2 = [_][]const u8{ @@ -32,19 +38,27 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + const libmicrokit_opt = b.option([]const u8, "libmicrokit", "Path to libmicrokit.a") orelse null; const libmicrokit_include_opt = b.option([]const u8, "libmicrokit_include", "Path to the libmicrokit include directory") orelse null; + const libmicrokit_linker_script_opt = b.option([]const u8, "libmicrokit_linker_script", "Path to the libmicrokit linker script") orelse null; // Default to vGIC version 2 const arm_vgic_version = b.option(usize, "arm_vgic_version", "ARM vGIC version to emulate") orelse null; - const libmicrokit_include = libmicrokit_include_opt.?; - const libvmm = b.addStaticLibrary(.{ .name = "vmm", .target = target, .optimize = optimize, }); + const sddf = b.dependency("sddf", .{ + .target = target, + .optimize = optimize, + .libmicrokit = @as([]const u8, libmicrokit_opt.?), + .libmicrokit_include = @as([]const u8, libmicrokit_include_opt.?), + .libmicrokit_linker_script = @as([]const u8, libmicrokit_linker_script_opt.?), + }); + const src_arch = switch (target.result.cpu.arch) { .aarch64 => blk: { const vgic_src = switch (arm_vgic_version.?) { @@ -72,9 +86,14 @@ pub fn build(b: *std.Build) void { }); libvmm.addIncludePath(b.path("include")); - libvmm.addIncludePath(.{ .cwd_relative = libmicrokit_include }); + libvmm.addIncludePath(sddf.path("include")); + libvmm.addIncludePath(.{ .cwd_relative = libmicrokit_include_opt.? }); libvmm.installHeadersDirectory(b.path("include/libvmm"), "libvmm", .{}); + libvmm.installHeadersDirectory(sddf.path("include/sddf"), "sddf", .{}); + + libvmm.linkLibrary(sddf.artifact("util")); + libvmm.linkLibrary(sddf.artifact("util_putchar_debug")); b.installArtifact(libvmm); } diff --git a/build.zig.zon b/build.zig.zon index e82c2fef..a4dbd384 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,6 +2,11 @@ .name = "libvmm", .version = "0.1.0", + .dependencies = .{ + .sddf = .{ + .path = "dep/sddf" + }, + }, .paths = .{ "LICENSE", "README.md", diff --git a/examples/simple/build.zig b/examples/simple/build.zig index b1746fd3..c723c49f 100644 --- a/examples/simple/build.zig +++ b/examples/simple/build.zig @@ -101,7 +101,9 @@ pub fn build(b: *std.Build) void { const libvmm_dep = b.dependency("libvmm", .{ .target = target, .optimize = optimize, + .libmicrokit = @as([]const u8, libmicrokit), .libmicrokit_include = @as([]const u8, libmicrokit_include), + .libmicrokit_linker_script = @as([]const u8, libmicrokit_linker_script), .arm_vgic_version = arm_vgic_version, }); const libvmm = libvmm_dep.artifact("vmm"); diff --git a/examples/zig/build.zig b/examples/zig/build.zig index 1f49227e..a6e64cd5 100644 --- a/examples/zig/build.zig +++ b/examples/zig/build.zig @@ -52,8 +52,9 @@ pub fn build(b: *std.Build) void { const libvmm_dep = b.dependency("libvmm", .{ .target = target, .optimize = optimize, + .libmicrokit = @as([]const u8, libmicrokit), .libmicrokit_include = @as([]const u8, libmicrokit_include), - // Because we only support QEMU virt AArch64, vGIC version is 2. + .libmicrokit_linker_script = @as([]const u8, libmicrokit_linker_script), // Because we only support QEMU virt AArch64, vGIC version is always 2. .arm_vgic_version = @as(usize, 2), });