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

fix target parsing


2 files changed, 16 insertions(+), 1 deletions(-)

lib/std/zig/cross_target.zig+15
......@@ -177,6 +177,9 @@ pub const CrossTarget = struct {
177177 /// If the architecture was determined, this will be populated.
178178 arch: ?Target.Cpu.Arch = null,
179179
180 /// If the OS name was determined, this will be populated.
181 os_name: ?[]const u8 = null,
182
180183 /// If the OS tag was determined, this will be populated.
181184 os_tag: ?Target.Os.Tag = null,
182185
......@@ -219,6 +222,7 @@ pub const CrossTarget = struct {
219222 var abi_it = mem.separate(abi_text, ".");
220223 const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
221224 return error.UnknownApplicationBinaryInterface;
225 result.abi = abi;
222226 diags.abi = abi;
223227
224228 const abi_ver_text = abi_it.rest();
......@@ -614,6 +618,7 @@ pub const CrossTarget = struct {
614618 fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
615619 var it = mem.separate(text, ".");
616620 const os_name = it.next().?;
621 diags.os_name = os_name;
617622 const os_is_native = mem.eql(u8, os_name, "native");
618623 if (!os_is_native) {
619624 result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
......@@ -702,6 +707,16 @@ pub const CrossTarget = struct {
702707};
703708
704709test "CrossTarget.parse" {
710 {
711 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
712
713 std.testing.expect(cross_target.cpu_arch == null);
714 std.testing.expect(cross_target.isNative());
715
716 const text = try cross_target.zigTriple(std.testing.allocator);
717 defer std.testing.allocator.free(text);
718 std.testing.expectEqualSlices(u8, "native", text);
719 }
705720 {
706721 const cross_target = try CrossTarget.parse(.{
707722 .arch_os_abi = "x86_64-linux-gnu",
src-self-hosted/stage2.zig+1-1
......@@ -679,7 +679,7 @@ fn stage2TargetParse(
679679) !void {
680680 const target: CrossTarget = if (zig_triple_oz) |zig_triple_z| blk: {
681681 const zig_triple = mem.toSliceConst(u8, zig_triple_z);
682 const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else "baseline";
682 const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null;
683683 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
684684 break :blk CrossTarget.parse(.{
685685 .arch_os_abi = zig_triple,