-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.zig
99 lines (83 loc) · 3.19 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2024, UNSW
// 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{
"src/arch/aarch64/vgic/vgic_v2.c",
};
const src_aarch64_vgic_v3 = [_][]const u8{
"src/arch/aarch64/vgic/vgic_v3.c",
};
const src_aarch64 = [_][]const u8{
"src/arch/aarch64/vgic/vgic.c",
"src/arch/aarch64/fault.c",
"src/arch/aarch64/psci.c",
"src/arch/aarch64/smc.c",
"src/arch/aarch64/virq.c",
"src/arch/aarch64/linux.c",
"src/arch/aarch64/tcb.c",
"src/arch/aarch64/vcpu.c",
};
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 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.?) {
2 => src_aarch64_vgic_v2,
3 => src_aarch64_vgic_v3,
else => @panic("Unsupported vGIC version given"),
};
break :blk src_aarch64 ++ vgic_src;
},
else => {
std.log.err("Unsupported libvmm architecture given '{s}'", .{ @tagName(target.result.cpu.arch) });
std.posix.exit(1);
}
};
libvmm.addCSourceFiles(.{
.files = &(src ++ src_arch),
.flags = &.{
"-Wall",
"-Werror",
"-Wno-unused-function",
"-mstrict-align",
"-fno-sanitize=undefined", // @ivanv: ideally we wouldn't have to turn off UBSAN
}
});
libvmm.addIncludePath(b.path("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);
}