Commit cf233bad58
Changed files (2)
lib
std
src-self-hosted
lib/std/zig/cross_target.zig
@@ -177,6 +177,9 @@ pub const CrossTarget = struct {
/// If the architecture was determined, this will be populated.
arch: ?Target.Cpu.Arch = null,
+ /// If the OS name was determined, this will be populated.
+ os_name: ?[]const u8 = null,
+
/// If the OS tag was determined, this will be populated.
os_tag: ?Target.Os.Tag = null,
@@ -219,6 +222,7 @@ pub const CrossTarget = struct {
var abi_it = mem.separate(abi_text, ".");
const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
return error.UnknownApplicationBinaryInterface;
+ result.abi = abi;
diags.abi = abi;
const abi_ver_text = abi_it.rest();
@@ -614,6 +618,7 @@ pub const CrossTarget = struct {
fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
var it = mem.separate(text, ".");
const os_name = it.next().?;
+ diags.os_name = os_name;
const os_is_native = mem.eql(u8, os_name, "native");
if (!os_is_native) {
result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
@@ -702,6 +707,16 @@ pub const CrossTarget = struct {
};
test "CrossTarget.parse" {
+ {
+ const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
+
+ std.testing.expect(cross_target.cpu_arch == null);
+ std.testing.expect(cross_target.isNative());
+
+ const text = try cross_target.zigTriple(std.testing.allocator);
+ defer std.testing.allocator.free(text);
+ std.testing.expectEqualSlices(u8, "native", text);
+ }
{
const cross_target = try CrossTarget.parse(.{
.arch_os_abi = "x86_64-linux-gnu",
src-self-hosted/stage2.zig
@@ -679,7 +679,7 @@ fn stage2TargetParse(
) !void {
const target: CrossTarget = if (zig_triple_oz) |zig_triple_z| blk: {
const zig_triple = mem.toSliceConst(u8, zig_triple_z);
- const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else "baseline";
+ const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null;
var diags: CrossTarget.ParseOptions.Diagnostics = .{};
break :blk CrossTarget.parse(.{
.arch_os_abi = zig_triple,