Restrict the target to .freestanding/.none/supported cpu #2

Closed
arjaz2 wants to merge 1 commits from build_cpu_target into master
+19 -3
View File
@@ -46,13 +46,29 @@ fn insertFakeLinuxImageHeader(step: *std.Build.Step, opts: std.Build.Step.MakeOp
_ = opts;
}
pub const SupportedArchitecture = enum {
riscv64,
pub fn toTargetCpuArch(self: @This()) std.Target.Cpu.Arch {
return switch (self) {
.riscv64 => .riscv64,
};
}
};
pub fn build(b: *std.Build) anyerror!void {
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const target = b.standardTargetOptions(.{ .default_target = .{
.cpu_arch = .riscv64,
const cpu_arch = (b.option(
SupportedArchitecture,
"cpu_arch",
"Specify the cpu architecture",
) orelse SupportedArchitecture.riscv64).toTargetCpuArch();
const target = b.resolveTargetQuery(.{
.cpu_arch = cpu_arch,
.os_tag = .freestanding,
.abi = .none,
} });
});
const kernel_module = b.addModule("kernel", .{ .optimize = optimize, .target = target, .pic = true, .red_zone = false, .code_model = .medium, .root_source_file = b.path("src/kernel.zig") });