Add infrastructure for build options

This commit is contained in:
Sam Tebbs 2019-08-27 19:28:17 +01:00
parent 47a6dbdb5b
commit b8f0b3131c
4 changed files with 19 additions and 9 deletions

View file

@ -36,5 +36,7 @@ steps:
sudo apt-get install qemu qemu-system --fix-missing sudo apt-get install qemu qemu-system --fix-missing
displayName: 'Download qemu' 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' displayName: 'Runtime tests'

View file

@ -37,6 +37,7 @@ pub fn build(b: *Builder) void {
b.makePath(grub_path.toSlice()) catch unreachable; b.makePath(grub_path.toSlice()) catch unreachable;
b.makePath(kern_path.toSlice()) catch unreachable; b.makePath(kern_path.toSlice()) catch unreachable;
b.makePath(a_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; 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; src_files.append(arch_boot.toSlice()) catch unreachable;
const iso_path = concat(b.allocator, build_path, "/pluto.iso") 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); var link_step = buildLink(b, builtin_target, build_path);
const iso_step = buildISO(b, build_path, iso_path.toSlice()); 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); b.default_step.dependOn(link_step);
for (iso_step.toSlice()) |step| b.default_step.dependOn(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; return &exec.step;
} }
fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_path: []const u8) ArrayList(*Step) { fn buildObjects(b: *Builder, target: builtin.Arch, build_path: []const u8, src_path: []const u8) ArrayList(*std.build.LibExeObjStep) {
var objects = ArrayList(*Step).init(b.allocator); var objects = ArrayList(*std.build.LibExeObjStep).init(b.allocator);
const src_path2 = concat(b.allocator, src_path, "/") catch unreachable; const src_path2 = concat(b.allocator, src_path, "/") catch unreachable;
for (src_files.toSlice()) |file| { for (src_files.toSlice()) |file| {
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable; 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.setMainPkgPath(".");
obj.setOutputDir(build_path); obj.setOutputDir(build_path);
obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu); 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| { for (src_files_asm.toSlice()) |file| {
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable; 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()); const obj = b.addAssemble(file, file_src.toSlice());
obj.setOutputDir(build_path); obj.setOutputDir(build_path);
obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu); obj.setTarget(target, builtin.Os.freestanding, builtin.Abi.gnu);
objects.append(&obj.step) catch unreachable; objects.append(obj) catch unreachable;
} }
return objects; return objects;
} }

View file

@ -45,7 +45,7 @@ const MemProfile = @import("../../mem.zig").MemProfile;
/// ///
/// Initialise the architecture /// 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(); disableInterrupts();
gdt.init(); gdt.init();

View file

@ -9,6 +9,7 @@ const vga = @import("vga.zig");
const log = @import("log.zig"); const log = @import("log.zig");
const serial = @import("serial.zig"); const serial = @import("serial.zig");
const mem = @import("mem.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 // 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 // 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; serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch unreachable;
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n"); 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"); log.logInfo("Arch init done\n");
vga.init(); vga.init();
tty.init(); tty.init();