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 {
525525 pub const StandardTargetOptionsArgs = struct {
526526 whitelist: ?[]const CrossTarget = null,
527527
528 default_target: CrossTarget = .{},
528 default_target: CrossTarget = CrossTarget{},
529529 };
530530
531531 /// Exposes standard `zig build` options for choosing a target.
......@@ -533,12 +533,12 @@ pub const Builder = struct {
533533 const triple = self.option(
534534 []const u8,
535535 "target",
536 "The Arch, OS, and ABI to build for.",
536 "The CPU architecture, OS, and ABI to build for.",
537537 ) orelse return args.default_target;
538538
539539 // 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 = .{};
542542 const selected_target = CrossTarget.parse(.{
543543 .arch_os_abi = triple,
544544 .diagnostics = &diags,
......@@ -567,7 +567,21 @@ pub const Builder = struct {
567567 }
568568 process.exit(1);
569569 },
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 },
571585 };
572586
573587 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable;
......@@ -585,7 +599,7 @@ pub const Builder = struct {
585599 });
586600 for (list) |t| {
587601 const t_triple = t.zigTriple(self.allocator) catch unreachable;
588 std.debug.warn(" {}\n", t_triple);
602 std.debug.warn(" {}\n", .{t_triple});
589603 }
590604 // TODO instead of process exit, return error and have a zig build flag implemented by
591605 // the build runner that turns process exits into error return traces
lib/std/special/init-exe/build.zig+10
......@@ -1,8 +1,18 @@
11const Builder = @import("std").build.Builder;
22
33pub 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.
412 const mode = b.standardReleaseOptions();
13
514 const exe = b.addExecutable("$", "src/main.zig");
15 exe.setTarget(target);
616 exe.setBuildMode(mode);
717 exe.install();
818