Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely you would also have a normal build as well, as adding the testing and setting to true would have the OS be in testing mode when released. Then with the build OS with runtime testing enabled, add a command to start the kernel which would trigger the runtime tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually a normal build without runtime testing enabled earlier on in the pipeline, check the "Build kernel" step.

zig*/zig build -Drt-test=true
zig*/zig build test -Drt-test=true -Dzig-path=zig*/zig
displayName: 'Runtime tests'
19 changes: 13 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -166,15 +173,15 @@ 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;
file_src.append(".s") catch unreachable;
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;
}
2 changes: 1 addition & 1 deletion src/kernel/arch/x86/arch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/kernel/kmain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, how can you just pass in this string like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's a hardcoded thing in the compiler and it just finds the right build options file :)


// 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
Expand All @@ -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();
Expand Down