-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.zig
82 lines (67 loc) · 2.53 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
// Copyright 2024, UNSW
// SPDX-License-Identifier: BSD-2-Clause
const std = @import("std");
const src = [_][]const u8{
"src/guest.c",
"src/util/util.c",
"src/util/printf.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_include_opt = b.option([]const u8, "libmicrokit_include", "Path to the libmicrokit include directory") orelse null;
const microkit_board_opt = b.option([]const u8, "microkit_board", "Name of Microkit board") 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 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
b.fmt("-DBOARD_{s}", .{ microkit_board_opt.? }) // @ivanv: shouldn't be needed as the library should not depend on the board
}
});
libvmm.addIncludePath(b.path("include"));
libvmm.addIncludePath(.{ .cwd_relative = libmicrokit_include });
libvmm.installHeadersDirectory(b.path("include/libvmm"), "libvmm", .{});
b.installArtifact(libvmm);
}