Add architecture option to build.zig
This commit is contained in:
parent
10a629c6ed
commit
a9589c2e56
1 changed files with 36 additions and 19 deletions
47
build.zig
47
build.zig
|
@ -8,16 +8,19 @@ const CrossTarget = std.zig.CrossTarget;
|
||||||
const fs = std.fs;
|
const fs = std.fs;
|
||||||
const Mode = builtin.Mode;
|
const Mode = builtin.Mode;
|
||||||
|
|
||||||
pub fn build(b: *Builder) !void {
|
const x86_i686 = CrossTarget{
|
||||||
const target = CrossTarget{
|
|
||||||
.cpu_arch = .i386,
|
.cpu_arch = .i386,
|
||||||
.os_tag = .freestanding,
|
.os_tag = .freestanding,
|
||||||
.cpu_model = .{ .explicit = &Target.x86.cpu._i686 },
|
.cpu_model = .{ .explicit = &Target.x86.cpu._i686 },
|
||||||
};
|
};
|
||||||
|
|
||||||
const target_str = switch (target.getCpuArch()) {
|
pub fn build(b: *Builder) !void {
|
||||||
.i386 => "x86",
|
const arch = b.option([]const u8, "arch", "Architecture to build for: x86") orelse "x86";
|
||||||
else => unreachable,
|
const target: CrossTarget = if (std.mem.eql(u8, "x86", arch))
|
||||||
|
x86_i686
|
||||||
|
else {
|
||||||
|
std.debug.warn("Unsupported or unknown architecture '{}'\n", .{arch});
|
||||||
|
unreachable;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fmt_step = b.addFmt(&[_][]const u8{
|
const fmt_step = b.addFmt(&[_][]const u8{
|
||||||
|
@ -28,12 +31,12 @@ pub fn build(b: *Builder) !void {
|
||||||
b.default_step.dependOn(&fmt_step.step);
|
b.default_step.dependOn(&fmt_step.step);
|
||||||
|
|
||||||
const main_src = "src/kernel/kmain.zig";
|
const main_src = "src/kernel/kmain.zig";
|
||||||
const constants_path = try fs.path.join(b.allocator, &[_][]const u8{ "src/kernel/arch", target_str, "constants.zig" });
|
const constants_path = try fs.path.join(b.allocator, &[_][]const u8{ "src/kernel/arch", arch, "constants.zig" });
|
||||||
|
|
||||||
const build_mode = b.standardReleaseOptions();
|
const build_mode = b.standardReleaseOptions();
|
||||||
const rt_test = b.option(bool, "rt-test", "enable/disable runtime testing") orelse false;
|
const rt_test = b.option(bool, "rt-test", "enable/disable runtime testing") orelse false;
|
||||||
|
|
||||||
const exec = b.addExecutable("pluto", main_src);
|
const exec = b.addExecutable("pluto.elf", main_src);
|
||||||
exec.addPackagePath("constants", constants_path);
|
exec.addPackagePath("constants", constants_path);
|
||||||
exec.setOutputDir(b.cache_root);
|
exec.setOutputDir(b.cache_root);
|
||||||
exec.addBuildOption(bool, "rt_test", rt_test);
|
exec.addBuildOption(bool, "rt_test", rt_test);
|
||||||
|
@ -46,14 +49,17 @@ pub fn build(b: *Builder) !void {
|
||||||
const boot_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "boot" });
|
const boot_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "boot" });
|
||||||
const modules_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "modules" });
|
const modules_path = try fs.path.join(b.allocator, &[_][]const u8{ b.exe_dir, "iso", "modules" });
|
||||||
|
|
||||||
const make_iso = b.addSystemCommand(&[_][]const u8{ "./makeiso.sh", boot_path, modules_path, iso_dir_path, exec.getOutputPath(), output_iso });
|
const make_iso = switch (target.getCpuArch()) {
|
||||||
|
.i386 => b.addSystemCommand(&[_][]const u8{ "./makeiso.sh", boot_path, modules_path, iso_dir_path, exec.getOutputPath(), output_iso }),
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
|
|
||||||
make_iso.step.dependOn(&exec.step);
|
make_iso.step.dependOn(&exec.step);
|
||||||
b.default_step.dependOn(&make_iso.step);
|
b.default_step.dependOn(&make_iso.step);
|
||||||
|
|
||||||
const test_step = b.step("test", "Run tests");
|
const test_step = b.step("test", "Run tests");
|
||||||
if (rt_test) {
|
if (rt_test) {
|
||||||
const script = b.addSystemCommand(&[_][]const u8{ "python3", "test/rt-test.py", "x86", b.zig_exe });
|
const script = b.addSystemCommand(&[_][]const u8{ "python3", "test/rt-test.py", arch, b.zig_exe });
|
||||||
test_step.dependOn(&script.step);
|
test_step.dependOn(&script.step);
|
||||||
} else {
|
} else {
|
||||||
const mock_path = "\"../../test/mock/kernel/\"";
|
const mock_path = "\"../../test/mock/kernel/\"";
|
||||||
|
@ -68,7 +74,7 @@ pub fn build(b: *Builder) !void {
|
||||||
|
|
||||||
if (builtin.os.tag != .windows) unit_tests.enable_qemu = true;
|
if (builtin.os.tag != .windows) unit_tests.enable_qemu = true;
|
||||||
|
|
||||||
unit_tests.setTarget(.{ .cpu_arch = .i386 });
|
unit_tests.setTarget(.{ .cpu_arch = target.cpu_arch });
|
||||||
|
|
||||||
test_step.dependOn(&unit_tests.step);
|
test_step.dependOn(&unit_tests.step);
|
||||||
}
|
}
|
||||||
|
@ -82,16 +88,25 @@ pub fn build(b: *Builder) !void {
|
||||||
};
|
};
|
||||||
const qemu_args = &[_][]const u8{
|
const qemu_args = &[_][]const u8{
|
||||||
qemu_bin,
|
qemu_bin,
|
||||||
"-cdrom",
|
|
||||||
output_iso,
|
|
||||||
"-boot",
|
|
||||||
"d",
|
|
||||||
"-serial",
|
"-serial",
|
||||||
"stdio",
|
"stdio",
|
||||||
};
|
};
|
||||||
|
const qemu_machine_args = switch (target.getCpuArch()) {
|
||||||
|
.i386 => &[_][]const u8{
|
||||||
|
"-boot",
|
||||||
|
"d",
|
||||||
|
"-cdrom",
|
||||||
|
output_iso,
|
||||||
|
},
|
||||||
|
else => null,
|
||||||
|
};
|
||||||
const qemu_cmd = b.addSystemCommand(qemu_args);
|
const qemu_cmd = b.addSystemCommand(qemu_args);
|
||||||
const qemu_debug_cmd = b.addSystemCommand(qemu_args);
|
const qemu_debug_cmd = b.addSystemCommand(qemu_args);
|
||||||
qemu_debug_cmd.addArgs(&[_][]const u8{ "-s", "-S" });
|
qemu_debug_cmd.addArgs(&[_][]const u8{ "-s", "-S" });
|
||||||
|
if (qemu_machine_args) |machine_args| {
|
||||||
|
qemu_cmd.addArgs(machine_args);
|
||||||
|
qemu_debug_cmd.addArgs(machine_args);
|
||||||
|
}
|
||||||
|
|
||||||
if (rt_test) {
|
if (rt_test) {
|
||||||
const qemu_rt_test_args = &[_][]const u8{ "-display", "none" };
|
const qemu_rt_test_args = &[_][]const u8{ "-display", "none" };
|
||||||
|
@ -108,9 +123,11 @@ pub fn build(b: *Builder) !void {
|
||||||
const debug_step = b.step("debug", "Debug with gdb and connect to a running qemu instance");
|
const debug_step = b.step("debug", "Debug with gdb and connect to a running qemu instance");
|
||||||
const symbol_file_arg = try std.mem.join(b.allocator, " ", &[_][]const u8{ "symbol-file", exec.getOutputPath() });
|
const symbol_file_arg = try std.mem.join(b.allocator, " ", &[_][]const u8{ "symbol-file", exec.getOutputPath() });
|
||||||
const debug_cmd = b.addSystemCommand(&[_][]const u8{
|
const debug_cmd = b.addSystemCommand(&[_][]const u8{
|
||||||
"gdb",
|
"gdb-multiarch",
|
||||||
"-ex",
|
"-ex",
|
||||||
symbol_file_arg,
|
symbol_file_arg,
|
||||||
|
"-ex",
|
||||||
|
"set architecture auto",
|
||||||
});
|
});
|
||||||
debug_cmd.addArgs(&[_][]const u8{
|
debug_cmd.addArgs(&[_][]const u8{
|
||||||
"-ex",
|
"-ex",
|
||||||
|
|
Loading…
Reference in a new issue