From 78e88c2e81d4be363c1152d16df6a631c9d02521 Mon Sep 17 00:00:00 2001 From: Eugene Rossokha Date: Mon, 17 Mar 2025 19:47:15 +0200 Subject: [PATCH] Restrict the target to .freestanding/.none/supported cpu --- build.zig | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 9c3835c..423c0f9 100644 --- a/build.zig +++ b/build.zig @@ -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") }); -- 2.53.0