From 3aada7a58a3a3a30806cf599dba05224582ffafc Mon Sep 17 00:00:00 2001 From: Ivan Velickovic Date: Thu, 26 Sep 2024 14:10:28 +1000 Subject: [PATCH] build.zig: compile libvmm with virtIO devices as well Signed-off-by: Ivan Velickovic --- build.zig | 25 ++++++++++++++++++++++--- build.zig.zon | 5 +++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index db08f83e6..1a88124a4 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 e82c2fef0..a4dbd384d 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",