Skip to content

Commit

Permalink
build.zig: compile libvmm with virtIO devices as well
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Sep 26, 2024
1 parent 3880812 commit 3aada7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 22 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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.?) {
Expand Down Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
.name = "libvmm",
.version = "0.1.0",

.dependencies = .{
.sddf = .{
.path = "dep/sddf"
},
},
.paths = .{
"LICENSE",
"README.md",
Expand Down

0 comments on commit 3aada7a

Please sign in to comment.