Add infrastructure for build options
This commit is contained in:
parent
47a6dbdb5b
commit
b8f0b3131c
4 changed files with 19 additions and 9 deletions
|
@ -36,5 +36,7 @@ steps:
|
|||
sudo apt-get install qemu qemu-system --fix-missing
|
||||
displayName: 'Download qemu'
|
||||
|
||||
- script: zig*/zig build test -Drt-test=true -Dzig-path=zig*/zig
|
||||
- script: |
|
||||
zig*/zig build -Drt-test=true
|
||||
zig*/zig build test -Drt-test=true -Dzig-path=zig*/zig
|
||||
displayName: 'Runtime tests'
|
||||
|
|
19
build.zig
19
build.zig
|
@ -37,6 +37,7 @@ pub fn build(b: *Builder) void {
|
|||
b.makePath(grub_path.toSlice()) catch unreachable;
|
||||
b.makePath(kern_path.toSlice()) catch unreachable;
|
||||
b.makePath(a_path.toSlice()) catch unreachable;
|
||||
b.makePath("zig-cache/kernel") catch unreachable;
|
||||
|
||||
src_files.append("kernel/kmain") catch unreachable;
|
||||
|
||||
|
@ -54,11 +55,17 @@ pub fn build(b: *Builder) void {
|
|||
src_files.append(arch_boot.toSlice()) catch unreachable;
|
||||
|
||||
const iso_path = concat(b.allocator, build_path, "/pluto.iso") catch unreachable;
|
||||
var objects_steps = buildObjects(b, builtin_target, build_path, src_path);
|
||||
var objects = buildObjects(b, builtin_target, build_path, src_path);
|
||||
var link_step = buildLink(b, builtin_target, build_path);
|
||||
const iso_step = buildISO(b, build_path, iso_path.toSlice());
|
||||
|
||||
for (objects_steps.toSlice()) |step| b.default_step.dependOn(step);
|
||||
for (objects.toSlice()) |obj| {
|
||||
if (std.mem.eql(u8, obj.name, "kernel/kmain")) {
|
||||
// Add build options here
|
||||
obj.addBuildOption(bool, "rt_test", rt_test);
|
||||
}
|
||||
b.default_step.dependOn(&obj.step);
|
||||
}
|
||||
b.default_step.dependOn(link_step);
|
||||
for (iso_step.toSlice()) |step| b.default_step.dependOn(step);
|
||||
|
||||
|
@ -156,8 +163,8 @@ fn buildLink(b: *Builder, target: builtin.Arch, build_path: []const u8) *Step {
|
|||
return &exec.step;
|
||||
}
|
||||
|
||||
fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_path: []const u8) ArrayList(*Step) {
|
||||
var objects = ArrayList(*Step).init(b.allocator);
|
||||
fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_path: []const u8) ArrayList(*std.build.LibExeObjStep) {
|
||||
var objects = ArrayList(*std.build.LibExeObjStep).init(b.allocator);
|
||||
const src_path2 = concat(b.allocator, src_path, "/") catch unreachable;
|
||||
for (src_files.toSlice()) |file| {
|
||||
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable;
|
||||
|
@ -166,7 +173,7 @@ fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_p
|
|||
obj.setMainPkgPath(".");
|
||||
obj.setOutputDir(build_path);
|
||||
obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu);
|
||||
objects.append(&obj.step) catch unreachable;
|
||||
objects.append(obj) catch unreachable;
|
||||
}
|
||||
for (src_files_asm.toSlice()) |file| {
|
||||
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable;
|
||||
|
@ -174,7 +181,7 @@ fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_p
|
|||
const obj = b.addAssemble(file, file_src.toSlice());
|
||||
obj.setOutputDir(build_path);
|
||||
obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu);
|
||||
objects.append(&obj.step) catch unreachable;
|
||||
objects.append(obj) catch unreachable;
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ const MemProfile = @import("../../mem.zig").MemProfile;
|
|||
///
|
||||
/// Initialise the architecture
|
||||
///
|
||||
pub fn init(mem_profile: *const MemProfile, allocator: *std.mem.Allocator) void {
|
||||
pub fn init(mem_profile: *const MemProfile, allocator: *std.mem.Allocator, comptime options: type) void {
|
||||
disableInterrupts();
|
||||
|
||||
gdt.init();
|
||||
|
|
|
@ -9,6 +9,7 @@ const vga = @import("vga.zig");
|
|||
const log = @import("log.zig");
|
||||
const serial = @import("serial.zig");
|
||||
const mem = @import("mem.zig");
|
||||
const options = @import("build_options");
|
||||
|
||||
// Need to import this as we need the panic to be in the root source file, or zig will just use the
|
||||
// builtin panic and just loop, which is what we don't want
|
||||
|
@ -31,7 +32,7 @@ pub export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
|
|||
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch unreachable;
|
||||
|
||||
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n");
|
||||
arch.init(&mem_profile, &fixed_allocator.allocator);
|
||||
arch.init(&mem_profile, &fixed_allocator.allocator, options);
|
||||
log.logInfo("Arch init done\n");
|
||||
vga.init();
|
||||
tty.init();
|
||||
|
|
Loading…
Reference in a new issue