Commit 87b9e744dd

Andrew Kelley <andrew@ziglang.org>
2020-02-25 09:43:21
update std lib to new Target API
1 parent d4f375c
lib/std/build/translate_c.zig
@@ -14,7 +14,7 @@ pub const TranslateCStep = struct {
     source: build.FileSource,
     output_dir: ?[]const u8,
     out_basename: []const u8,
-    target: std.Target = .Native,
+    target: build.Target = .Native,
 
     pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
         const self = builder.allocator.create(TranslateCStep) catch unreachable;
@@ -39,7 +39,7 @@ pub const TranslateCStep = struct {
         ) catch unreachable;
     }
 
-    pub fn setTarget(self: *TranslateCStep, target: std.Target) void {
+    pub fn setTarget(self: *TranslateCStep, target: build.Target) void {
         self.target = target;
     }
 
lib/std/fmt/parse_float.zig
@@ -382,7 +382,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
 }
 
 test "fmt.parseFloat" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/io/test.zig
@@ -544,7 +544,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
 }
 
 test "Serializer/Deserializer generic" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/math/fabs.zig
@@ -95,7 +95,7 @@ test "math.fabs64.special" {
 }
 
 test "math.fabs128.special" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/math/isinf.zig
@@ -74,7 +74,7 @@ pub fn isNegativeInf(x: var) bool {
 }
 
 test "math.isInf" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -97,7 +97,7 @@ test "math.isInf" {
 }
 
 test "math.isPositiveInf" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -120,7 +120,7 @@ test "math.isPositiveInf" {
 }
 
 test "math.isNegativeInf" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/math/isnan.zig
@@ -16,7 +16,7 @@ pub fn isSignalNan(x: var) bool {
 }
 
 test "math.isNan" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/addXf3_test.zig
@@ -31,7 +31,7 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
 }
 
 test "addtf3" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -75,7 +75,7 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
 }
 
 test "subtf3" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixtfdi_test.zig
@@ -11,7 +11,7 @@ fn test__fixtfdi(a: f128, expected: i64) void {
 }
 
 test "fixtfdi" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixtfsi_test.zig
@@ -11,7 +11,7 @@ fn test__fixtfsi(a: f128, expected: i32) void {
 }
 
 test "fixtfsi" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixtfti_test.zig
@@ -11,7 +11,7 @@ fn test__fixtfti(a: f128, expected: i128) void {
 }
 
 test "fixtfti" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixunstfdi_test.zig
@@ -7,7 +7,7 @@ fn test__fixunstfdi(a: f128, expected: u64) void {
 }
 
 test "fixunstfdi" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixunstfsi_test.zig
@@ -9,7 +9,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void {
 const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
 
 test "fixunstfsi" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/fixunstfti_test.zig
@@ -9,7 +9,7 @@ fn test__fixunstfti(a: f128, expected: u128) void {
 const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
 
 test "fixunstfti" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/floattitf_test.zig
@@ -7,7 +7,7 @@ fn test__floattitf(a: i128, expected: f128) void {
 }
 
 test "floattitf" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/floatuntitf_test.zig
@@ -7,7 +7,7 @@ fn test__floatuntitf(a: u128, expected: f128) void {
 }
 
 test "floatuntitf" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/mulXf3_test.zig
@@ -44,7 +44,7 @@ fn makeNaN128(rand: u64) f128 {
     return float_result;
 }
 test "multf3" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/special/compiler_rt/truncXfYf2_test.zig
@@ -151,7 +151,7 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
 }
 
 test "trunctfsf2" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -190,7 +190,7 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
 }
 
 test "trunctfdf2" {
-    if (@import("std").Target.current.isWindows()) {
+    if (@import("std").Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
lib/std/build.zig
@@ -971,7 +971,7 @@ pub const Builder = struct {
 };
 
 test "builder.findProgram compiles" {
-    var buf: [1000]u8 = undefined;
+    var buf: [50000]u8 = undefined;
     var fba = std.heap.FixedBufferAllocator.init(&buf);
     const builder = try Builder.create(&fba.allocator, "zig", "zig-cache", "zig-cache");
     defer builder.destroy();
@@ -1011,6 +1011,77 @@ pub const Target = union(enum) {
     pub fn getArch(self: Target) std.Target.Cpu.Arch {
         return self.getCpu().arch;
     }
+
+    pub fn isFreeBSD(self: Target) bool {
+        return self.getTarget().os.tag == .freebsd;
+    }
+
+    pub fn isDarwin(self: Target) bool {
+        return self.getTarget().os.tag.isDarwin();
+    }
+
+    pub fn isNetBSD(self: Target) bool {
+        return self.getTarget().os.tag == .netbsd;
+    }
+
+    pub fn isUefi(self: Target) bool {
+        return self.getTarget().os.tag == .uefi;
+    }
+
+    pub fn isDragonFlyBSD(self: Target) bool {
+        return self.getTarget().os.tag == .dragonfly;
+    }
+
+    pub fn isLinux(self: Target) bool {
+        return self.getTarget().os.tag == .linux;
+    }
+
+    pub fn isWindows(self: Target) bool {
+        return self.getTarget().os.tag == .windows;
+    }
+
+    pub fn oFileExt(self: Target) []const u8 {
+        return self.getTarget().oFileExt();
+    }
+
+    pub fn exeFileExt(self: Target) []const u8 {
+        return self.getTarget().exeFileExt();
+    }
+
+    pub fn staticLibSuffix(self: Target) []const u8 {
+        return self.getTarget().staticLibSuffix();
+    }
+
+    pub fn libPrefix(self: Target) []const u8 {
+        return self.getTarget().libPrefix();
+    }
+
+    pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
+        return self.getTarget().zigTriple(allocator);
+    }
+
+    pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
+        return self.getTarget().linuxTriple(allocator);
+    }
+
+    pub fn wantSharedLibSymLinks(self: Target) bool {
+        return self.getTarget().wantSharedLibSymLinks();
+    }
+
+    pub fn vcpkgTriplet(self: Target, allocator: *mem.Allocator, linkage: std.build.VcpkgLinkage) ![]const u8 {
+        return self.getTarget().vcpkgTriplet(allocator, linkage);
+    }
+
+    pub fn getExternalExecutor(self: Target) std.Target.Executor {
+        switch (self) {
+            .Native => return .native,
+            .Cross => |t| return t.getExternalExecutor(),
+        }
+    }
+
+    pub fn isGnuLibC(self: Target) bool {
+        return self.getTarget().isGnuLibC();
+    }
 };
 
 pub const Pkg = struct {
@@ -1718,7 +1789,7 @@ pub const LibExeObjStep = struct {
             .NotFound => return error.VcpkgNotFound,
             .Found => |root| {
                 const allocator = self.builder.allocator;
-                const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
+                const triplet = try self.target.vcpkgTriplet(allocator, linkage);
                 defer self.builder.allocator.free(triplet);
 
                 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
@@ -1944,7 +2015,7 @@ pub const LibExeObjStep = struct {
                 if (populated_cpu_features.eql(cross.cpu.features)) {
                     // The CPU name alone is sufficient.
                     // If it is the baseline CPU, no command line args are required.
-                    if (cross.cpu.model != Target.Cpu.baseline(self.target.getArch()).model) {
+                    if (cross.cpu.model != std.Target.Cpu.baseline(self.target.getArch()).model) {
                         try zig_args.append("-mcpu");
                         try zig_args.append(cross.cpu.model.name);
                     }
@@ -1953,7 +2024,7 @@ pub const LibExeObjStep = struct {
                     try mcpu_buffer.append(cross.cpu.model.name);
 
                     for (all_features) |feature, i_usize| {
-                        const i = @intCast(Target.Cpu.Feature.Set.Index, i_usize);
+                        const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
                         const in_cpu_set = populated_cpu_features.isEnabled(i);
                         const in_actual_set = cross.cpu.features.isEnabled(i);
                         if (in_cpu_set and !in_actual_set) {
@@ -2001,7 +2072,7 @@ pub const LibExeObjStep = struct {
         } else switch (self.target.getExternalExecutor()) {
             .native, .unavailable => {},
             .qemu => |bin_name| if (self.enable_qemu) qemu: {
-                const need_cross_glibc = self.target.isGnu() and self.target.isLinux() and self.is_linking_libc;
+                const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc;
                 const glibc_dir_arg = if (need_cross_glibc)
                     self.glibc_multi_install_dir orelse break :qemu
                 else
lib/std/os.zig
@@ -650,7 +650,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!void {
 /// On Windows, if the application has a global event loop enabled, I/O Completion Ports are
 /// used to perform the I/O. `error.WouldBlock` is not possible on Windows.
 pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) WriteError!void {
-    if (comptime std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         return windows.WriteFile(fd, bytes, offset);
     }
 
@@ -739,7 +739,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void
         }
     }
 
-    if (comptime std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         var off = offset;
         for (iov) |item| {
             try pwrite(fd, item.iov_base[0..item.iov_len], off);
lib/std/target.zig
@@ -53,6 +53,13 @@ pub const Target = struct {
             emscripten,
             uefi,
             other,
+
+            pub fn isDarwin(tag: Tag) bool {
+                return switch (tag) {
+                    .ios, .macosx, .watchos, .tvos => true,
+                    else => false,
+                };
+            }
         };
 
         /// Based on NTDDI version constants from
@@ -921,7 +928,7 @@ pub const Target = struct {
     }
 
     /// Returned slice must be freed by the caller.
-    pub fn vcpkgTriplet(allocator: *mem.Allocator, target: Target, linkage: std.build.VcpkgLinkage) ![]const u8 {
+    pub fn vcpkgTriplet(target: Target, allocator: *mem.Allocator, linkage: std.build.VcpkgLinkage) ![]const u8 {
         const arch = switch (target.cpu.arch) {
             .i386 => "x86",
             .x86_64 => "x64",
@@ -960,14 +967,6 @@ pub const Target = struct {
         return self.zigTriple(allocator);
     }
 
-    pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {
-        return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
-            @tagName(self.cpu.arch),
-            @tagName(self.os.tag),
-            @tagName(self.abi),
-        });
-    }
-
     pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
         return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
             @tagName(self.cpu.arch),
@@ -1111,11 +1110,11 @@ pub const Target = struct {
     }
 
     pub fn exeFileExt(self: Target) []const u8 {
-        if (self.isWindows()) {
+        if (self.os.tag == .windows) {
             return ".exe";
-        } else if (self.isUefi()) {
+        } else if (self.os.tag == .uefi) {
             return ".efi";
-        } else if (self.isWasm()) {
+        } else if (self.cpu.arch.isWasm()) {
             return ".wasm";
         } else {
             return "";
@@ -1123,7 +1122,7 @@ pub const Target = struct {
     }
 
     pub fn staticLibSuffix(self: Target) []const u8 {
-        if (self.isWasm()) {
+        if (self.cpu.arch.isWasm()) {
             return ".wasm";
         }
         switch (self.abi) {
@@ -1143,7 +1142,7 @@ pub const Target = struct {
     }
 
     pub fn libPrefix(self: Target) []const u8 {
-        if (self.isWasm()) {
+        if (self.cpu.arch.isWasm()) {
             return "";
         }
         switch (self.abi) {
@@ -1153,19 +1152,19 @@ pub const Target = struct {
     }
 
     pub fn getObjectFormat(self: Target) ObjectFormat {
-        if (self.isWindows() or self.isUefi()) {
+        if (self.os.tag == .windows or self.os.tag == .uefi) {
             return .coff;
         } else if (self.isDarwin()) {
             return .macho;
         }
-        if (self.isWasm()) {
+        if (self.cpu.arch.isWasm()) {
             return .wasm;
         }
         return .elf;
     }
 
     pub fn isMinGW(self: Target) bool {
-        return self.isWindows() and self.isGnu();
+        return self.os.tag == .windows and self.isGnu();
     }
 
     pub fn isGnu(self: Target) bool {
@@ -1176,27 +1175,6 @@ pub const Target = struct {
         return self.abi.isMusl();
     }
 
-    pub fn isDarwin(self: Target) bool {
-        return switch (self.os.tag) {
-            .ios, .macosx, .watchos, .tvos => true,
-            else => false,
-        };
-    }
-
-    pub fn isWindows(self: Target) bool {
-        return switch (self.os.tag) {
-            .windows => true,
-            else => false,
-        };
-    }
-
-    pub fn isLinux(self: Target) bool {
-        return switch (self.os.tag) {
-            .linux => true,
-            else => false,
-        };
-    }
-
     pub fn isAndroid(self: Target) bool {
         return switch (self.abi) {
             .android => true,
@@ -1204,36 +1182,12 @@ pub const Target = struct {
         };
     }
 
-    pub fn isDragonFlyBSD(self: Target) bool {
-        return switch (self.os.tag) {
-            .dragonfly => true,
-            else => false,
-        };
-    }
-
-    pub fn isUefi(self: Target) bool {
-        return switch (self.os.tag) {
-            .uefi => true,
-            else => false,
-        };
-    }
-
     pub fn isWasm(self: Target) bool {
         return self.cpu.arch.isWasm();
     }
 
-    pub fn isFreeBSD(self: Target) bool {
-        return switch (self.os.tag) {
-            .freebsd => true,
-            else => false,
-        };
-    }
-
-    pub fn isNetBSD(self: Target) bool {
-        return switch (self.os.tag) {
-            .netbsd => true,
-            else => false,
-        };
+    pub fn isDarwin(self: Target) bool {
+        return self.os.tag.isDarwin();
     }
 
     pub fn isGnuLibC(self: Target) bool {
@@ -1241,11 +1195,11 @@ pub const Target = struct {
     }
 
     pub fn wantSharedLibSymLinks(self: Target) bool {
-        return !self.isWindows();
+        return self.os.tag != .windows;
     }
 
     pub fn osRequiresLibC(self: Target) bool {
-        return self.isDarwin() or self.isFreeBSD() or self.isNetBSD();
+        return self.isDarwin() or self.os.tag == .freebsd or self.os.tag == .netbsd;
     }
 
     pub fn getArchPtrBitWidth(self: Target) u32 {
@@ -1309,7 +1263,7 @@ pub const Target = struct {
     }
 
     pub fn supportsNewStackCall(self: Target) bool {
-        return !self.isWasm();
+        return !self.cpu.arch.isWasm();
     }
 
     pub const Executor = union(enum) {
@@ -1321,8 +1275,6 @@ pub const Target = struct {
     };
 
     pub fn getExternalExecutor(self: Target) Executor {
-        if (@as(@TagType(Target), self) == .Native) return .native;
-
         // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
         if (self.os.tag == builtin.os.tag) {
             return switch (self.cpu.arch) {
@@ -1347,22 +1299,18 @@ pub const Target = struct {
             };
         }
 
-        if (self.isWindows()) {
-            switch (self.getArchPtrBitWidth()) {
+        switch (self.os.tag) {
+            .windows => switch (self.getArchPtrBitWidth()) {
                 32 => return Executor{ .wine = "wine" },
                 64 => return Executor{ .wine = "wine64" },
                 else => return .unavailable,
-            }
-        }
-
-        if (self.os == .wasi) {
-            switch (self.getArchPtrBitWidth()) {
+            },
+            .wasi => switch (self.getArchPtrBitWidth()) {
                 32 => return Executor{ .wasmtime = "wasmtime" },
                 else => return .unavailable,
-            }
+            },
+            else => return .unavailable,
         }
-
-        return .unavailable;
     }
 
     pub const FloatAbi = enum {
@@ -1566,12 +1514,12 @@ test "Target.parse" {
 
         std.testing.expect(target.cpu.arch == .aarch64);
         std.testing.expect(target.os.tag == .linux);
-        std.testing.expect(target.os.version_range.linux.min.major == 3);
-        std.testing.expect(target.os.version_range.linux.min.minor == 10);
-        std.testing.expect(target.os.version_range.linux.min.patch == 0);
-        std.testing.expect(target.os.version_range.linux.max.major == 4);
-        std.testing.expect(target.os.version_range.linux.max.minor == 4);
-        std.testing.expect(target.os.version_range.linux.max.patch == 1);
+        std.testing.expect(target.os.version_range.linux.range.min.major == 3);
+        std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
+        std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
+        std.testing.expect(target.os.version_range.linux.range.max.major == 4);
+        std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
+        std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
         std.testing.expect(target.os.version_range.linux.glibc.major == 2);
         std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
         std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
src-self-hosted/libc_installation.zig
@@ -7,11 +7,7 @@ const Allocator = std.mem.Allocator;
 const Batch = std.event.Batch;
 
 const is_darwin = Target.current.isDarwin();
-const is_windows = Target.current.isWindows();
-const is_freebsd = Target.current.isFreeBSD();
-const is_netbsd = Target.current.isNetBSD();
-const is_linux = Target.current.isLinux();
-const is_dragonfly = Target.current.isDragonFlyBSD();
+const is_windows = Target.current.os.tag == .windows;
 const is_gnu = Target.current.isGnu();
 
 usingnamespace @import("windows_sdk.zig");
@@ -216,10 +212,10 @@ pub const LibCInstallation = struct {
                 var batch = Batch(FindError!void, 2, .auto_async).init();
                 errdefer batch.wait() catch {};
                 batch.add(&async self.findNativeIncludeDirPosix(args));
-                if (is_freebsd or is_netbsd) {
-                    self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib");
-                } else if (is_linux or is_dragonfly) {
-                    batch.add(&async self.findNativeCrtDirPosix(args));
+                switch (Target.current.os.tag) {
+                    .freebsd, .netbsd => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),
+                    .linux, .dragonfly => batch.add(&async self.findNativeCrtDirPosix(args)),
+                    else => {},
                 }
                 break :blk batch.wait();
             };
test/src/translate_c.zig
@@ -19,7 +19,7 @@ pub const TranslateCContext = struct {
         sources: ArrayList(SourceFile),
         expected_lines: ArrayList([]const u8),
         allow_warnings: bool,
-        target: std.Target = .Native,
+        target: build.Target = .Native,
 
         const SourceFile = struct {
             filename: []const u8,
@@ -75,7 +75,7 @@ pub const TranslateCContext = struct {
     pub fn addWithTarget(
         self: *TranslateCContext,
         name: []const u8,
-        target: std.Target,
+        target: build.Target,
         source: []const u8,
         expected_lines: []const []const u8,
     ) void {
test/stage1/behavior/math.zig
@@ -529,7 +529,7 @@ test "comptime_int xor" {
 }
 
 test "f128" {
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -631,7 +631,7 @@ test "NaN comparison" {
         // TODO: https://github.com/ziglang/zig/issues/3338
         return error.SkipZigTest;
     }
-    if (std.Target.current.isWindows()) {
+    if (std.Target.current.os.tag == .windows) {
         // TODO https://github.com/ziglang/zig/issues/508
         return error.SkipZigTest;
     }
@@ -666,14 +666,14 @@ test "128-bit multiplication" {
 test "vector comparison" {
     const S = struct {
         fn doTheTest() void {
-            var a: @Vector(6, i32) = [_]i32{1, 3, -1, 5, 7, 9};
-            var b: @Vector(6, i32) = [_]i32{-1, 3, 0, 6, 10, -10};
-            expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{false, false, true, true, true, false}));
-            expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{false, true, true, true, true, false}));
-            expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{false, true, false, false, false, false}));
-            expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{true, false, true, true, true, true}));
-            expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{true, false, false, false, false, true}));
-            expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{true, true, false, false, false, true}));
+            var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
+            var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
+            expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
+            expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
+            expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
+            expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
+            expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
+            expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
         }
     };
     S.doTheTest();
test/assemble_and_link.zig
@@ -1,8 +1,8 @@
-const builtin = @import("builtin");
+const std = @import("std");
 const tests = @import("tests.zig");
 
 pub fn addCases(cases: *tests.CompareOutputContext) void {
-    if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
+    if (std.Target.current.os.tag == .linux and std.Target.current.cpu.arch == .x86_64) {
         cases.addAsm("hello world linux x86_64",
             \\.text
             \\.globl _start
test/compile_errors.zig
@@ -1,5 +1,4 @@
 const tests = @import("tests.zig");
-const builtin = @import("builtin");
 const Target = @import("std").Target;
 
 pub fn addCases(cases: *tests.CompileErrorContext) void {
@@ -387,10 +386,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         , &[_][]const u8{
             "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
         });
-        tc.target = Target{
+        tc.target = tests.Target{
             .Cross = .{
                 .cpu = Target.Cpu.baseline(.wasm32),
-                .os = .wasi,
+                .os = Target.Os.defaultVersionRange(.wasi),
                 .abi = .none,
             },
         };
@@ -788,10 +787,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         , &[_][]const u8{
             "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
         });
-        tc.target = Target{
+        tc.target = tests.Target{
             .Cross = .{
                 .cpu = Target.Cpu.baseline(.x86_64),
-                .os = .linux,
+                .os = Target.Os.defaultVersionRange(.linux),
                 .abi = .gnu,
             },
         };
@@ -1453,7 +1452,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
     });
 
-    if (builtin.os == builtin.Os.linux) {
+    if (Target.current.os.tag == .linux) {
         cases.addTest("implicit dependency on libc",
             \\extern "c" fn exit(u8) void;
             \\export fn entry() void {
test/stack_traces.zig
@@ -1,4 +1,3 @@
-const builtin = @import("builtin");
 const std = @import("std");
 const os = std.os;
 const tests = @import("tests.zig");
@@ -43,32 +42,32 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
         \\}
     ;
 
-    switch (builtin.os) {
+    switch (builtin.os.tag) {
         .freebsd => {
             cases.addCase(
                 "return",
                 source_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in main (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in std.start.main (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -77,7 +76,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_try_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in foo (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -87,7 +86,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in std.start.main (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -97,11 +96,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -110,7 +109,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_try_try_return_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:12:5: [address] in make_error (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -126,7 +125,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:12:5: [address] in std.start.main (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -142,11 +141,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -157,25 +156,25 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in main (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -184,7 +183,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_try_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in foo (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -194,7 +193,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -204,11 +203,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -217,7 +216,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_try_try_return_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:12:5: [address] in make_error (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -233,7 +232,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-safe
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -249,11 +248,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -278,11 +277,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -311,11 +310,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -356,11 +355,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                     \\
                 ,
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -371,7 +370,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 source_return,
                 [_][]const u8{
                 // debug
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\source.zig:4:5: [address] in main (test.obj)
                     \\    return error.TheSkyIsFalling;
                     \\    ^
@@ -381,11 +380,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 // --disabled-- results in segmenetation fault
                 "",
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -407,11 +406,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 // --disabled-- results in segmenetation fault
                 "",
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
@@ -439,11 +438,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
                 // --disabled-- results in segmenetation fault
                 "",
                 // release-fast
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 ,
                 // release-small
-                    \\error: TheSkyIsFalling
+                \\error: TheSkyIsFalling
                     \\
                 },
             );
test/standalone.zig
@@ -18,10 +18,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
     cases.addBuildFile("test/standalone/use_alias/build.zig");
     cases.addBuildFile("test/standalone/brace_expansion/build.zig");
     cases.addBuildFile("test/standalone/empty_env/build.zig");
-    if (std.Target.current.getOs() != .wasi) {
+    if (std.Target.current.os.tag != .wasi) {
         cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");
     }
-    if (std.Target.current.getArch() == .x86_64) { // TODO add C ABI support for other architectures
+    if (std.Target.current.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures
         cases.addBuildFile("test/stage1/c_abi/build.zig");
     }
 }
test/tests.zig
@@ -1,16 +1,15 @@
 const std = @import("std");
+const builtin = std.builtin;
 const debug = std.debug;
 const warn = debug.warn;
 const build = std.build;
 pub const Target = build.Target;
-pub const CrossTarget = build.CrossTarget;
 const Buffer = std.Buffer;
 const io = std.io;
 const fs = std.fs;
 const mem = std.mem;
 const fmt = std.fmt;
 const ArrayList = std.ArrayList;
-const builtin = @import("builtin");
 const Mode = builtin.Mode;
 const LibExeObjStep = build.LibExeObjStep;
 
@@ -54,18 +53,18 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .none,
                 },
             },
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .gnu,
                 },
             },
@@ -73,9 +72,9 @@ const test_targets = blk: {
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .musl,
                 },
             },
@@ -84,18 +83,18 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.i386),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.i386),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .none,
                 },
             },
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.i386),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.i386),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .musl,
                 },
             },
@@ -104,18 +103,18 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.aarch64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.aarch64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .none,
                 },
             },
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.aarch64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.aarch64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .musl,
                 },
             },
@@ -123,9 +122,9 @@ const test_targets = blk: {
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.aarch64),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.aarch64),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .gnu,
                 },
             },
@@ -133,21 +132,25 @@ const test_targets = blk: {
         },
 
         TestTarget{
-            .target = Target.parse(.{
-                .arch_os_abi = "arm-linux-none",
-                .cpu_features = "generic+v8a",
-            }) catch unreachable,
+            .target = .{
+                .Cross = std.Target.parse(.{
+                    .arch_os_abi = "arm-linux-none",
+                    .cpu_features = "generic+v8a",
+                }) catch unreachable,
+            },
         },
         TestTarget{
-            .target = Target.parse(.{
-                .arch_os_abi = "arm-linux-musleabihf",
-                .cpu_features = "generic+v8a",
-            }) catch unreachable,
+            .target = .{
+                .Cross = std.Target.parse(.{
+                    .arch_os_abi = "arm-linux-musleabihf",
+                    .cpu_features = "generic+v8a",
+                }) catch unreachable,
+            },
             .link_libc = true,
         },
         // TODO https://github.com/ziglang/zig/issues/3287
         //TestTarget{
-        //    .target = Target.parse(.{
+        //    .target = std.Target.parse(.{
         //        .arch_os_abi = "arm-linux-gnueabihf",
         //        .cpu_features = "generic+v8a",
         //    }) catch unreachable,
@@ -156,18 +159,18 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.mipsel),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.mipsel),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .none,
                 },
             },
         },
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.mipsel),
-                    .os = Target.Os.defaultVersionRange(.linux),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.mipsel),
+                    .os = std.Target.Os.defaultVersionRange(.linux),
                     .abi = .musl,
                 },
             },
@@ -176,9 +179,9 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.macosx),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.macosx),
                     .abi = .gnu,
                 },
             },
@@ -188,9 +191,9 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.i386),
-                    .os = Target.Os.defaultVersionRange(.windows),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.i386),
+                    .os = std.Target.Os.defaultVersionRange(.windows),
                     .abi = .msvc,
                 },
             },
@@ -198,9 +201,9 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.windows),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.windows),
                     .abi = .msvc,
                 },
             },
@@ -208,9 +211,9 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.i386),
-                    .os = Target.Os.defaultVersionRange(.windows),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.i386),
+                    .os = std.Target.Os.defaultVersionRange(.windows),
                     .abi = .gnu,
                 },
             },
@@ -219,9 +222,9 @@ const test_targets = blk: {
 
         TestTarget{
             .target = Target{
-                .Cross = CrossTarget{
-                    .cpu = Target.Cpu.baseline(.x86_64),
-                    .os = Target.Os.defaultVersionRange(.windows),
+                .Cross = .{
+                    .cpu = std.Target.Cpu.baseline(.x86_64),
+                    .os = std.Target.Os.defaultVersionRange(.windows),
                     .abi = .gnu,
                 },
             },
@@ -438,7 +441,7 @@ pub fn addPkgTests(
         if (skip_libc and test_target.link_libc)
             continue;
 
-        if (test_target.link_libc and test_target.target.osRequiresLibC()) {
+        if (test_target.link_libc and test_target.target.getTarget().osRequiresLibC()) {
             // This would be a redundant test.
             continue;
         }
@@ -448,8 +451,8 @@ pub fn addPkgTests(
 
         const ArchTag = @TagType(builtin.Arch);
         if (test_target.disable_native and
-            test_target.target.getOs() == builtin.os and
-            test_target.target.getArch() == builtin.arch)
+            test_target.target.getOs() == std.Target.current.os.tag and
+            test_target.target.getArch() == std.Target.current.cpu.arch)
         {
             continue;
         }
@@ -459,7 +462,7 @@ pub fn addPkgTests(
         } else false;
         if (!want_this_mode) continue;
 
-        const libc_prefix = if (test_target.target.osRequiresLibC())
+        const libc_prefix = if (test_target.target.getTarget().osRequiresLibC())
             ""
         else if (test_target.link_libc)
             "c"
@@ -469,7 +472,7 @@ pub fn addPkgTests(
         const triple_prefix = if (test_target.target == .Native)
             @as([]const u8, "native")
         else
-            test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
+            test_target.target.zigTriple(b.allocator) catch unreachable;
 
         const these_tests = b.addTest(root_src);
         const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
@@ -660,7 +663,7 @@ pub const StackTracesContext = struct {
                     const delims = [_][]const u8{ ":", ":", ":", " in " };
                     var marks = [_]usize{0} ** 4;
                     // offset search past `[drive]:` on windows
-                    var pos: usize = if (builtin.os == .windows) 2 else 0;
+                    var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0;
                     for (delims) |delim, i| {
                         marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
                             try buf.append(line);
test/translate_c.zig
@@ -1,6 +1,6 @@
 const tests = @import("tests.zig");
-const builtin = @import("builtin");
-const Target = @import("std").Target;
+const std = @import("std");
+const Target = std.Target;
 
 pub fn addCases(cases: *tests.TranslateCContext) void {
     cases.add("macro line continuation",
@@ -665,7 +665,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\}
     });
 
-    if (builtin.os != builtin.Os.windows) {
+    if (Target.current.os.tag != .windows) {
         // Windows treats this as an enum with type c_int
         cases.add("big negative enum init values when C ABI supports long long enums",
             \\enum EnumWithInits {
@@ -1064,7 +1064,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\}
     });
 
-    if (builtin.os != builtin.Os.windows) {
+    if (Target.current.os.tag != .windows) {
         // sysv_abi not currently supported on windows
         cases.add("Macro qualified functions",
             \\void __attribute__((sysv_abi)) foo(void);
@@ -1093,10 +1093,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\pub const fn1 = ?fn (u8) callconv(.C) void;
     });
 
-    cases.addWithTarget("Calling convention", tests.Target{
+    cases.addWithTarget("Calling convention", .{
         .Cross = .{
             .cpu = Target.Cpu.baseline(.i386),
-            .os = .linux,
+            .os = Target.Os.defaultVersionRange(.linux),
             .abi = .none,
         },
     },
@@ -1113,10 +1113,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\pub fn foo5(a: [*c]f32) callconv(.Thiscall) void;
     });
 
-    cases.addWithTarget("Calling convention", Target.parse(.{
-        .arch_os_abi = "arm-linux-none",
-        .cpu_features = "generic+v8_5a",
-    }) catch unreachable,
+    cases.addWithTarget("Calling convention", .{
+        .Cross = Target.parse(.{
+            .arch_os_abi = "arm-linux-none",
+            .cpu_features = "generic+v8_5a",
+        }) catch unreachable,
+    },
         \\void __attribute__((pcs("aapcs"))) foo1(float *a);
         \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
     , &[_][]const u8{
@@ -1124,10 +1126,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\pub fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
     });
 
-    cases.addWithTarget("Calling convention", Target.parse(.{
-        .arch_os_abi = "aarch64-linux-none",
-        .cpu_features = "generic+v8_5a",
-    }) catch unreachable,
+    cases.addWithTarget("Calling convention", .{
+        .Cross = Target.parse(.{
+            .arch_os_abi = "aarch64-linux-none",
+            .cpu_features = "generic+v8_5a",
+        }) catch unreachable,
+    },
         \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
     , &[_][]const u8{
         \\pub fn foo1(a: [*c]f32) callconv(.Vectorcall) void;
@@ -1596,7 +1600,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\}
     });
 
-    if (builtin.os != .windows) {
+    if (Target.current.os.tag != .windows) {
         // When clang uses the <arch>-windows-none triple it behaves as MSVC and
         // interprets the inner `struct Bar` as an anonymous structure
         cases.add("type referenced struct",