authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-26 14:33:36-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 14:51:54-05:00
logcebcacd872a05d8ee3edaafe3eff5cc6e73657b7
tree3dec36b8ae09ca06bfe242edbcaf74d809d96120
parentcf233bad5884b9bd782256eb6808fcc6abda645c
signaturelock-open Commit is signed but in an unrecognized format.

fix standardTargetOptions and improve init-exe to use it


2 files changed, 29 insertions(+), 5 deletions(-)

lib/std/build.zig+19-5
...@@ -525,7 +525,7 @@ pub const Builder = struct {...@@ -525,7 +525,7 @@ pub const Builder = struct {
525 pub const StandardTargetOptionsArgs = struct {525 pub const StandardTargetOptionsArgs = struct {
526 whitelist: ?[]const CrossTarget = null,526 whitelist: ?[]const CrossTarget = null,
527527
528 default_target: CrossTarget = .{},528 default_target: CrossTarget = CrossTarget{},
529 };529 };
530530
531 /// Exposes standard `zig build` options for choosing a target.531 /// Exposes standard `zig build` options for choosing a target.
...@@ -533,12 +533,12 @@ pub const Builder = struct {...@@ -533,12 +533,12 @@ pub const Builder = struct {
533 const triple = self.option(533 const triple = self.option(
534 []const u8,534 []const u8,
535 "target",535 "target",
536 "The Arch, OS, and ABI to build for.",536 "The CPU architecture, OS, and ABI to build for.",
537 ) orelse return args.default_target;537 ) orelse return args.default_target;
538538
539 // TODO add cpu and features as part of the target triple539 // TODO add cpu and features as part of the target triple
540540
541 var diags: std.Target.ParseOptions.Diagnostics = .{};541 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
542 const selected_target = CrossTarget.parse(.{542 const selected_target = CrossTarget.parse(.{
543 .arch_os_abi = triple,543 .arch_os_abi = triple,
544 .diagnostics = &diags,544 .diagnostics = &diags,
...@@ -567,7 +567,21 @@ pub const Builder = struct {...@@ -567,7 +567,21 @@ pub const Builder = struct {
567 }567 }
568 process.exit(1);568 process.exit(1);
569 },569 },
570 else => |e| return e,570 error.UnknownOperatingSystem => {
571 std.debug.warn(
572 \\Unknown OS: '{}'
573 \\Available operating systems:
574 \\
575 , .{diags.os_name});
576 inline for (std.meta.fields(std.Target.Os.Tag)) |field| {
577 std.debug.warn(" {}\n", .{field.name});
578 }
579 process.exit(1);
580 },
581 else => |e| {
582 std.debug.warn("Unable to parse target '{}': {}\n", .{ triple, @errorName(e) });
583 process.exit(1);
584 },
571 };585 };
572586
573 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable;587 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable;
...@@ -585,7 +599,7 @@ pub const Builder = struct {...@@ -585,7 +599,7 @@ pub const Builder = struct {
585 });599 });
586 for (list) |t| {600 for (list) |t| {
587 const t_triple = t.zigTriple(self.allocator) catch unreachable;601 const t_triple = t.zigTriple(self.allocator) catch unreachable;
588 std.debug.warn(" {}\n", t_triple);602 std.debug.warn(" {}\n", .{t_triple});
589 }603 }
590 // TODO instead of process exit, return error and have a zig build flag implemented by604 // TODO instead of process exit, return error and have a zig build flag implemented by
591 // the build runner that turns process exits into error return traces605 // the build runner that turns process exits into error return traces
lib/std/special/init-exe/build.zig+10
...@@ -1,8 +1,18 @@...@@ -1,8 +1,18 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: *Builder) void {3pub fn build(b: *Builder) void {
4 // Standard target options allows the person running `zig build` to choose
5 // what target to build for. Here we do not override the defaults, which
6 // means any target is allowed, and the default is native. Other options
7 // for restricting supported target set are available.
8 const target = b.standardTargetOptions(.{});
9
10 // Standard release options allow the person running `zig build` to select
11 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
4 const mode = b.standardReleaseOptions();12 const mode = b.standardReleaseOptions();
13
5 const exe = b.addExecutable("$", "src/main.zig");14 const exe = b.addExecutable("$", "src/main.zig");
15 exe.setTarget(target);
6 exe.setBuildMode(mode);16 exe.setBuildMode(mode);
7 exe.install();17 exe.install();
818