diff options
| -rw-r--r-- | lib/std/build.zig | 24 | ||||
| -rw-r--r-- | lib/std/special/init-exe/build.zig | 10 |
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index 92b06a0261..792781df85 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -525,7 +525,7 @@ pub const Builder = struct { pub const StandardTargetOptionsArgs = struct { whitelist: ?[]const CrossTarget = null, - default_target: CrossTarget = .{}, + default_target: CrossTarget = CrossTarget{}, }; /// Exposes standard `zig build` options for choosing a target. @@ -533,12 +533,12 @@ pub const Builder = struct { const triple = self.option( []const u8, "target", - "The Arch, OS, and ABI to build for.", + "The CPU architecture, OS, and ABI to build for.", ) orelse return args.default_target; // TODO add cpu and features as part of the target triple - var diags: std.Target.ParseOptions.Diagnostics = .{}; + var diags: CrossTarget.ParseOptions.Diagnostics = .{}; const selected_target = CrossTarget.parse(.{ .arch_os_abi = triple, .diagnostics = &diags, @@ -567,7 +567,21 @@ pub const Builder = struct { } process.exit(1); }, - else => |e| return e, + error.UnknownOperatingSystem => { + std.debug.warn( + \\Unknown OS: '{}' + \\Available operating systems: + \\ + , .{diags.os_name}); + inline for (std.meta.fields(std.Target.Os.Tag)) |field| { + std.debug.warn(" {}\n", .{field.name}); + } + process.exit(1); + }, + else => |e| { + std.debug.warn("Unable to parse target '{}': {}\n", .{ triple, @errorName(e) }); + process.exit(1); + }, }; const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable; @@ -585,7 +599,7 @@ pub const Builder = struct { }); for (list) |t| { const t_triple = t.zigTriple(self.allocator) catch unreachable; - std.debug.warn(" {}\n", t_triple); + std.debug.warn(" {}\n", .{t_triple}); } // TODO instead of process exit, return error and have a zig build flag implemented by // the build runner that turns process exits into error return traces diff --git a/lib/std/special/init-exe/build.zig b/lib/std/special/init-exe/build.zig index 0b7410f2ad..fd71588c5f 100644 --- a/lib/std/special/init-exe/build.zig +++ b/lib/std/special/init-exe/build.zig @@ -1,8 +1,18 @@ const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. const mode = b.standardReleaseOptions(); + const exe = b.addExecutable("$", "src/main.zig"); + exe.setTarget(target); exe.setBuildMode(mode); exe.install(); |
