-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
98 lines (82 loc) · 3.21 KB
/
build.zig
File metadata and controls
98 lines (82 loc) · 3.21 KB
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
const std = @import("std");
pub fn build(b: *std.Build) void {
// Define the target
const target = b.resolveTargetQuery(.{
.cpu_arch = .riscv64,
.os_tag = .freestanding,
.abi = .none,
});
const optimize = .ReleaseSmall;
// Create the executable
const exe = b.addExecutable(.{
.name = "kernel",
.root_module = b.createModule(.{
.root_source_file = b.path("kernel.zig"),
.target = target,
.optimize = optimize,
.strip = false, // -fno-strip equivalent
.code_model = .medium, // -mcmodel=medium
}),
});
const enable_debug_logs = b.option(bool, "debug-logs", "Enable debug logging") orelse false;
const options = b.addOptions();
options.addOption(bool, "enable_debug_logs", enable_debug_logs);
const build_options_module = options.createModule();
// Create modules that don't have dependencies first
const sbi_module = b.createModule(.{
.root_source_file = b.path("sbi.zig"),
.optimize = optimize,
});
const thread_module = b.createModule(.{
.root_source_file = b.path("thread.zig"),
.optimize = optimize,
});
const uart_mmio_module = b.createModule(.{
.root_source_file = b.path("uart_mmio.zig"),
.optimize = optimize,
});
const interrupts_module = b.createModule(.{
.root_source_file = b.path("interrupts.zig"),
.optimize = optimize,
});
const context_module = b.createModule(.{
.root_source_file = b.path("context.zig"),
.optimize = optimize,
});
// Create timer module with sbi as a dependency
const timer_module = b.createModule(.{
.root_source_file = b.path("timer.zig"),
.optimize = optimize,
});
timer_module.addImport("sbi", sbi_module);
const scheduling_module = b.createModule(.{
.root_source_file = b.path("scheduling.zig"),
.optimize = optimize,
});
scheduling_module.addImport("sbi", sbi_module);
scheduling_module.addImport("thread", thread_module);
scheduling_module.addImport("build_options", build_options_module);
const syscall_module = b.createModule(.{
.root_source_file = b.path("syscall.zig"),
.optimize = optimize,
});
// Add all imports to the main executable
exe.root_module.addImport("thread", thread_module);
exe.root_module.addImport("sbi", sbi_module);
exe.root_module.addImport("uart_mmio", uart_mmio_module);
exe.root_module.addImport("interrupts", interrupts_module);
exe.root_module.addImport("timer", timer_module);
exe.root_module.addImport("scheduling", scheduling_module);
exe.root_module.addImport("context", context_module);
exe.root_module.addImport("build_options", build_options_module);
thread_module.addImport("sbi", sbi_module);
thread_module.addImport("context", context_module);
thread_module.addImport("uart_mmio", uart_mmio_module);
thread_module.addImport("syscall", syscall_module);
// Add the assembly source file
exe.addAssemblyFile(b.path("startup.S"));
// Set the linker script
exe.setLinkerScript(b.path("linker.ld"));
// Install the executable
b.installArtifact(exe);
}