authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-25 03:43:21-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 14:51:54-05:00
log87b9e744dda465ecf7663e2463066ea26a44e63a
treee3c09dca4b8a06656029b1034da24ed9b7507299
parentd4f375c46be2e509ee9161b0577d8a25d6620b3e
signature Commit is signed but in an unrecognized format.

update std lib to new Target API


29 files changed, 281 insertions(+), 261 deletions(-)

lib/std/build.zig+76-5
......@@ -971,7 +971,7 @@ pub const Builder = struct {
971971};
972972
973973test "builder.findProgram compiles" {
974 var buf: [1000]u8 = undefined;
974 var buf: [50000]u8 = undefined;
975975 var fba = std.heap.FixedBufferAllocator.init(&buf);
976976 const builder = try Builder.create(&fba.allocator, "zig", "zig-cache", "zig-cache");
977977 defer builder.destroy();
......@@ -1011,6 +1011,77 @@ pub const Target = union(enum) {
10111011 pub fn getArch(self: Target) std.Target.Cpu.Arch {
10121012 return self.getCpu().arch;
10131013 }
1014
1015 pub fn isFreeBSD(self: Target) bool {
1016 return self.getTarget().os.tag == .freebsd;
1017 }
1018
1019 pub fn isDarwin(self: Target) bool {
1020 return self.getTarget().os.tag.isDarwin();
1021 }
1022
1023 pub fn isNetBSD(self: Target) bool {
1024 return self.getTarget().os.tag == .netbsd;
1025 }
1026
1027 pub fn isUefi(self: Target) bool {
1028 return self.getTarget().os.tag == .uefi;
1029 }
1030
1031 pub fn isDragonFlyBSD(self: Target) bool {
1032 return self.getTarget().os.tag == .dragonfly;
1033 }
1034
1035 pub fn isLinux(self: Target) bool {
1036 return self.getTarget().os.tag == .linux;
1037 }
1038
1039 pub fn isWindows(self: Target) bool {
1040 return self.getTarget().os.tag == .windows;
1041 }
1042
1043 pub fn oFileExt(self: Target) []const u8 {
1044 return self.getTarget().oFileExt();
1045 }
1046
1047 pub fn exeFileExt(self: Target) []const u8 {
1048 return self.getTarget().exeFileExt();
1049 }
1050
1051 pub fn staticLibSuffix(self: Target) []const u8 {
1052 return self.getTarget().staticLibSuffix();
1053 }
1054
1055 pub fn libPrefix(self: Target) []const u8 {
1056 return self.getTarget().libPrefix();
1057 }
1058
1059 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
1060 return self.getTarget().zigTriple(allocator);
1061 }
1062
1063 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
1064 return self.getTarget().linuxTriple(allocator);
1065 }
1066
1067 pub fn wantSharedLibSymLinks(self: Target) bool {
1068 return self.getTarget().wantSharedLibSymLinks();
1069 }
1070
1071 pub fn vcpkgTriplet(self: Target, allocator: *mem.Allocator, linkage: std.build.VcpkgLinkage) ![]const u8 {
1072 return self.getTarget().vcpkgTriplet(allocator, linkage);
1073 }
1074
1075 pub fn getExternalExecutor(self: Target) std.Target.Executor {
1076 switch (self) {
1077 .Native => return .native,
1078 .Cross => |t| return t.getExternalExecutor(),
1079 }
1080 }
1081
1082 pub fn isGnuLibC(self: Target) bool {
1083 return self.getTarget().isGnuLibC();
1084 }
10141085};
10151086
10161087pub const Pkg = struct {
......@@ -1718,7 +1789,7 @@ pub const LibExeObjStep = struct {
17181789 .NotFound => return error.VcpkgNotFound,
17191790 .Found => |root| {
17201791 const allocator = self.builder.allocator;
1721 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
1792 const triplet = try self.target.vcpkgTriplet(allocator, linkage);
17221793 defer self.builder.allocator.free(triplet);
17231794
17241795 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
......@@ -1944,7 +2015,7 @@ pub const LibExeObjStep = struct {
19442015 if (populated_cpu_features.eql(cross.cpu.features)) {
19452016 // The CPU name alone is sufficient.
19462017 // If it is the baseline CPU, no command line args are required.
1947 if (cross.cpu.model != Target.Cpu.baseline(self.target.getArch()).model) {
2018 if (cross.cpu.model != std.Target.Cpu.baseline(self.target.getArch()).model) {
19482019 try zig_args.append("-mcpu");
19492020 try zig_args.append(cross.cpu.model.name);
19502021 }
......@@ -1953,7 +2024,7 @@ pub const LibExeObjStep = struct {
19532024 try mcpu_buffer.append(cross.cpu.model.name);
19542025
19552026 for (all_features) |feature, i_usize| {
1956 const i = @intCast(Target.Cpu.Feature.Set.Index, i_usize);
2027 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
19572028 const in_cpu_set = populated_cpu_features.isEnabled(i);
19582029 const in_actual_set = cross.cpu.features.isEnabled(i);
19592030 if (in_cpu_set and !in_actual_set) {
......@@ -2001,7 +2072,7 @@ pub const LibExeObjStep = struct {
20012072 } else switch (self.target.getExternalExecutor()) {
20022073 .native, .unavailable => {},
20032074 .qemu => |bin_name| if (self.enable_qemu) qemu: {
2004 const need_cross_glibc = self.target.isGnu() and self.target.isLinux() and self.is_linking_libc;
2075 const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc;
20052076 const glibc_dir_arg = if (need_cross_glibc)
20062077 self.glibc_multi_install_dir orelse break :qemu
20072078 else
lib/std/build/translate_c.zig+2-2
......@@ -14,7 +14,7 @@ pub const TranslateCStep = struct {
1414 source: build.FileSource,
1515 output_dir: ?[]const u8,
1616 out_basename: []const u8,
17 target: std.Target = .Native,
17 target: build.Target = .Native,
1818
1919 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2020 const self = builder.allocator.create(TranslateCStep) catch unreachable;
......@@ -39,7 +39,7 @@ pub const TranslateCStep = struct {
3939 ) catch unreachable;
4040 }
4141
42 pub fn setTarget(self: *TranslateCStep, target: std.Target) void {
42 pub fn setTarget(self: *TranslateCStep, target: build.Target) void {
4343 self.target = target;
4444 }
4545
lib/std/fmt/parse_float.zig+1-1
......@@ -382,7 +382,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
382382}
383383
384384test "fmt.parseFloat" {
385 if (std.Target.current.isWindows()) {
385 if (std.Target.current.os.tag == .windows) {
386386 // TODO https://github.com/ziglang/zig/issues/508
387387 return error.SkipZigTest;
388388 }
lib/std/io/test.zig+1-1
......@@ -544,7 +544,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
544544}
545545
546546test "Serializer/Deserializer generic" {
547 if (std.Target.current.isWindows()) {
547 if (std.Target.current.os.tag == .windows) {
548548 // TODO https://github.com/ziglang/zig/issues/508
549549 return error.SkipZigTest;
550550 }
lib/std/math/fabs.zig+1-1
......@@ -95,7 +95,7 @@ test "math.fabs64.special" {
9595}
9696
9797test "math.fabs128.special" {
98 if (std.Target.current.isWindows()) {
98 if (std.Target.current.os.tag == .windows) {
9999 // TODO https://github.com/ziglang/zig/issues/508
100100 return error.SkipZigTest;
101101 }
lib/std/math/isinf.zig+3-3
......@@ -74,7 +74,7 @@ pub fn isNegativeInf(x: var) bool {
7474}
7575
7676test "math.isInf" {
77 if (std.Target.current.isWindows()) {
77 if (std.Target.current.os.tag == .windows) {
7878 // TODO https://github.com/ziglang/zig/issues/508
7979 return error.SkipZigTest;
8080 }
......@@ -97,7 +97,7 @@ test "math.isInf" {
9797}
9898
9999test "math.isPositiveInf" {
100 if (std.Target.current.isWindows()) {
100 if (std.Target.current.os.tag == .windows) {
101101 // TODO https://github.com/ziglang/zig/issues/508
102102 return error.SkipZigTest;
103103 }
......@@ -120,7 +120,7 @@ test "math.isPositiveInf" {
120120}
121121
122122test "math.isNegativeInf" {
123 if (std.Target.current.isWindows()) {
123 if (std.Target.current.os.tag == .windows) {
124124 // TODO https://github.com/ziglang/zig/issues/508
125125 return error.SkipZigTest;
126126 }
lib/std/math/isnan.zig+1-1
......@@ -16,7 +16,7 @@ pub fn isSignalNan(x: var) bool {
1616}
1717
1818test "math.isNan" {
19 if (std.Target.current.isWindows()) {
19 if (std.Target.current.os.tag == .windows) {
2020 // TODO https://github.com/ziglang/zig/issues/508
2121 return error.SkipZigTest;
2222 }
lib/std/os.zig+2-2
......@@ -650,7 +650,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!void {
650650/// On Windows, if the application has a global event loop enabled, I/O Completion Ports are
651651/// used to perform the I/O. `error.WouldBlock` is not possible on Windows.
652652pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) WriteError!void {
653 if (comptime std.Target.current.isWindows()) {
653 if (std.Target.current.os.tag == .windows) {
654654 return windows.WriteFile(fd, bytes, offset);
655655 }
656656
......@@ -739,7 +739,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void
739739 }
740740 }
741741
742 if (comptime std.Target.current.isWindows()) {
742 if (std.Target.current.os.tag == .windows) {
743743 var off = offset;
744744 for (iov) |item| {
745745 try pwrite(fd, item.iov_base[0..item.iov_len], off);
lib/std/special/compiler_rt/addXf3_test.zig+2-2
......@@ -31,7 +31,7 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
3131}
3232
3333test "addtf3" {
34 if (@import("std").Target.current.isWindows()) {
34 if (@import("std").Target.current.os.tag == .windows) {
3535 // TODO https://github.com/ziglang/zig/issues/508
3636 return error.SkipZigTest;
3737 }
......@@ -75,7 +75,7 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
7575}
7676
7777test "subtf3" {
78 if (@import("std").Target.current.isWindows()) {
78 if (@import("std").Target.current.os.tag == .windows) {
7979 // TODO https://github.com/ziglang/zig/issues/508
8080 return error.SkipZigTest;
8181 }
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
......@@ -11,7 +11,7 @@ fn test__fixtfdi(a: f128, expected: i64) void {
1111}
1212
1313test "fixtfdi" {
14 if (@import("std").Target.current.isWindows()) {
14 if (@import("std").Target.current.os.tag == .windows) {
1515 // TODO https://github.com/ziglang/zig/issues/508
1616 return error.SkipZigTest;
1717 }
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
......@@ -11,7 +11,7 @@ fn test__fixtfsi(a: f128, expected: i32) void {
1111}
1212
1313test "fixtfsi" {
14 if (@import("std").Target.current.isWindows()) {
14 if (@import("std").Target.current.os.tag == .windows) {
1515 // TODO https://github.com/ziglang/zig/issues/508
1616 return error.SkipZigTest;
1717 }
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
......@@ -11,7 +11,7 @@ fn test__fixtfti(a: f128, expected: i128) void {
1111}
1212
1313test "fixtfti" {
14 if (@import("std").Target.current.isWindows()) {
14 if (@import("std").Target.current.os.tag == .windows) {
1515 // TODO https://github.com/ziglang/zig/issues/508
1616 return error.SkipZigTest;
1717 }
lib/std/special/compiler_rt/fixunstfdi_test.zig+1-1
......@@ -7,7 +7,7 @@ fn test__fixunstfdi(a: f128, expected: u64) void {
77}
88
99test "fixunstfdi" {
10 if (@import("std").Target.current.isWindows()) {
10 if (@import("std").Target.current.os.tag == .windows) {
1111 // TODO https://github.com/ziglang/zig/issues/508
1212 return error.SkipZigTest;
1313 }
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1
......@@ -9,7 +9,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void {
99const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfsi" {
12 if (@import("std").Target.current.isWindows()) {
12 if (@import("std").Target.current.os.tag == .windows) {
1313 // TODO https://github.com/ziglang/zig/issues/508
1414 return error.SkipZigTest;
1515 }
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1
......@@ -9,7 +9,7 @@ fn test__fixunstfti(a: f128, expected: u128) void {
99const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
1111test "fixunstfti" {
12 if (@import("std").Target.current.isWindows()) {
12 if (@import("std").Target.current.os.tag == .windows) {
1313 // TODO https://github.com/ziglang/zig/issues/508
1414 return error.SkipZigTest;
1515 }
lib/std/special/compiler_rt/floattitf_test.zig+1-1
......@@ -7,7 +7,7 @@ fn test__floattitf(a: i128, expected: f128) void {
77}
88
99test "floattitf" {
10 if (@import("std").Target.current.isWindows()) {
10 if (@import("std").Target.current.os.tag == .windows) {
1111 // TODO https://github.com/ziglang/zig/issues/508
1212 return error.SkipZigTest;
1313 }
lib/std/special/compiler_rt/floatuntitf_test.zig+1-1
......@@ -7,7 +7,7 @@ fn test__floatuntitf(a: u128, expected: f128) void {
77}
88
99test "floatuntitf" {
10 if (@import("std").Target.current.isWindows()) {
10 if (@import("std").Target.current.os.tag == .windows) {
1111 // TODO https://github.com/ziglang/zig/issues/508
1212 return error.SkipZigTest;
1313 }
lib/std/special/compiler_rt/mulXf3_test.zig+1-1
......@@ -44,7 +44,7 @@ fn makeNaN128(rand: u64) f128 {
4444 return float_result;
4545}
4646test "multf3" {
47 if (@import("std").Target.current.isWindows()) {
47 if (@import("std").Target.current.os.tag == .windows) {
4848 // TODO https://github.com/ziglang/zig/issues/508
4949 return error.SkipZigTest;
5050 }
lib/std/special/compiler_rt/truncXfYf2_test.zig+2-2
......@@ -151,7 +151,7 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
151151}
152152
153153test "trunctfsf2" {
154 if (@import("std").Target.current.isWindows()) {
154 if (@import("std").Target.current.os.tag == .windows) {
155155 // TODO https://github.com/ziglang/zig/issues/508
156156 return error.SkipZigTest;
157157 }
......@@ -190,7 +190,7 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
190190}
191191
192192test "trunctfdf2" {
193 if (@import("std").Target.current.isWindows()) {
193 if (@import("std").Target.current.os.tag == .windows) {
194194 // TODO https://github.com/ziglang/zig/issues/508
195195 return error.SkipZigTest;
196196 }
lib/std/target.zig+33-85
......@@ -53,6 +53,13 @@ pub const Target = struct {
5353 emscripten,
5454 uefi,
5555 other,
56
57 pub fn isDarwin(tag: Tag) bool {
58 return switch (tag) {
59 .ios, .macosx, .watchos, .tvos => true,
60 else => false,
61 };
62 }
5663 };
5764
5865 /// Based on NTDDI version constants from
......@@ -921,7 +928,7 @@ pub const Target = struct {
921928 }
922929
923930 /// Returned slice must be freed by the caller.
924 pub fn vcpkgTriplet(allocator: *mem.Allocator, target: Target, linkage: std.build.VcpkgLinkage) ![]const u8 {
931 pub fn vcpkgTriplet(target: Target, allocator: *mem.Allocator, linkage: std.build.VcpkgLinkage) ![]const u8 {
925932 const arch = switch (target.cpu.arch) {
926933 .i386 => "x86",
927934 .x86_64 => "x64",
......@@ -960,14 +967,6 @@ pub const Target = struct {
960967 return self.zigTriple(allocator);
961968 }
962969
963 pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {
964 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
965 @tagName(self.cpu.arch),
966 @tagName(self.os.tag),
967 @tagName(self.abi),
968 });
969 }
970
971970 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
972971 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
973972 @tagName(self.cpu.arch),
......@@ -1111,11 +1110,11 @@ pub const Target = struct {
11111110 }
11121111
11131112 pub fn exeFileExt(self: Target) []const u8 {
1114 if (self.isWindows()) {
1113 if (self.os.tag == .windows) {
11151114 return ".exe";
1116 } else if (self.isUefi()) {
1115 } else if (self.os.tag == .uefi) {
11171116 return ".efi";
1118 } else if (self.isWasm()) {
1117 } else if (self.cpu.arch.isWasm()) {
11191118 return ".wasm";
11201119 } else {
11211120 return "";
......@@ -1123,7 +1122,7 @@ pub const Target = struct {
11231122 }
11241123
11251124 pub fn staticLibSuffix(self: Target) []const u8 {
1126 if (self.isWasm()) {
1125 if (self.cpu.arch.isWasm()) {
11271126 return ".wasm";
11281127 }
11291128 switch (self.abi) {
......@@ -1143,7 +1142,7 @@ pub const Target = struct {
11431142 }
11441143
11451144 pub fn libPrefix(self: Target) []const u8 {
1146 if (self.isWasm()) {
1145 if (self.cpu.arch.isWasm()) {
11471146 return "";
11481147 }
11491148 switch (self.abi) {
......@@ -1153,19 +1152,19 @@ pub const Target = struct {
11531152 }
11541153
11551154 pub fn getObjectFormat(self: Target) ObjectFormat {
1156 if (self.isWindows() or self.isUefi()) {
1155 if (self.os.tag == .windows or self.os.tag == .uefi) {
11571156 return .coff;
11581157 } else if (self.isDarwin()) {
11591158 return .macho;
11601159 }
1161 if (self.isWasm()) {
1160 if (self.cpu.arch.isWasm()) {
11621161 return .wasm;
11631162 }
11641163 return .elf;
11651164 }
11661165
11671166 pub fn isMinGW(self: Target) bool {
1168 return self.isWindows() and self.isGnu();
1167 return self.os.tag == .windows and self.isGnu();
11691168 }
11701169
11711170 pub fn isGnu(self: Target) bool {
......@@ -1176,27 +1175,6 @@ pub const Target = struct {
11761175 return self.abi.isMusl();
11771176 }
11781177
1179 pub fn isDarwin(self: Target) bool {
1180 return switch (self.os.tag) {
1181 .ios, .macosx, .watchos, .tvos => true,
1182 else => false,
1183 };
1184 }
1185
1186 pub fn isWindows(self: Target) bool {
1187 return switch (self.os.tag) {
1188 .windows => true,
1189 else => false,
1190 };
1191 }
1192
1193 pub fn isLinux(self: Target) bool {
1194 return switch (self.os.tag) {
1195 .linux => true,
1196 else => false,
1197 };
1198 }
1199
12001178 pub fn isAndroid(self: Target) bool {
12011179 return switch (self.abi) {
12021180 .android => true,
......@@ -1204,36 +1182,12 @@ pub const Target = struct {
12041182 };
12051183 }
12061184
1207 pub fn isDragonFlyBSD(self: Target) bool {
1208 return switch (self.os.tag) {
1209 .dragonfly => true,
1210 else => false,
1211 };
1212 }
1213
1214 pub fn isUefi(self: Target) bool {
1215 return switch (self.os.tag) {
1216 .uefi => true,
1217 else => false,
1218 };
1219 }
1220
12211185 pub fn isWasm(self: Target) bool {
12221186 return self.cpu.arch.isWasm();
12231187 }
12241188
1225 pub fn isFreeBSD(self: Target) bool {
1226 return switch (self.os.tag) {
1227 .freebsd => true,
1228 else => false,
1229 };
1230 }
1231
1232 pub fn isNetBSD(self: Target) bool {
1233 return switch (self.os.tag) {
1234 .netbsd => true,
1235 else => false,
1236 };
1189 pub fn isDarwin(self: Target) bool {
1190 return self.os.tag.isDarwin();
12371191 }
12381192
12391193 pub fn isGnuLibC(self: Target) bool {
......@@ -1241,11 +1195,11 @@ pub const Target = struct {
12411195 }
12421196
12431197 pub fn wantSharedLibSymLinks(self: Target) bool {
1244 return !self.isWindows();
1198 return self.os.tag != .windows;
12451199 }
12461200
12471201 pub fn osRequiresLibC(self: Target) bool {
1248 return self.isDarwin() or self.isFreeBSD() or self.isNetBSD();
1202 return self.isDarwin() or self.os.tag == .freebsd or self.os.tag == .netbsd;
12491203 }
12501204
12511205 pub fn getArchPtrBitWidth(self: Target) u32 {
......@@ -1309,7 +1263,7 @@ pub const Target = struct {
13091263 }
13101264
13111265 pub fn supportsNewStackCall(self: Target) bool {
1312 return !self.isWasm();
1266 return !self.cpu.arch.isWasm();
13131267 }
13141268
13151269 pub const Executor = union(enum) {
......@@ -1321,8 +1275,6 @@ pub const Target = struct {
13211275 };
13221276
13231277 pub fn getExternalExecutor(self: Target) Executor {
1324 if (@as(@TagType(Target), self) == .Native) return .native;
1325
13261278 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
13271279 if (self.os.tag == builtin.os.tag) {
13281280 return switch (self.cpu.arch) {
......@@ -1347,22 +1299,18 @@ pub const Target = struct {
13471299 };
13481300 }
13491301
1350 if (self.isWindows()) {
1351 switch (self.getArchPtrBitWidth()) {
1302 switch (self.os.tag) {
1303 .windows => switch (self.getArchPtrBitWidth()) {
13521304 32 => return Executor{ .wine = "wine" },
13531305 64 => return Executor{ .wine = "wine64" },
13541306 else => return .unavailable,
1355 }
1356 }
1357
1358 if (self.os == .wasi) {
1359 switch (self.getArchPtrBitWidth()) {
1307 },
1308 .wasi => switch (self.getArchPtrBitWidth()) {
13601309 32 => return Executor{ .wasmtime = "wasmtime" },
13611310 else => return .unavailable,
1362 }
1311 },
1312 else => return .unavailable,
13631313 }
1364
1365 return .unavailable;
13661314 }
13671315
13681316 pub const FloatAbi = enum {
......@@ -1566,12 +1514,12 @@ test "Target.parse" {
15661514
15671515 std.testing.expect(target.cpu.arch == .aarch64);
15681516 std.testing.expect(target.os.tag == .linux);
1569 std.testing.expect(target.os.version_range.linux.min.major == 3);
1570 std.testing.expect(target.os.version_range.linux.min.minor == 10);
1571 std.testing.expect(target.os.version_range.linux.min.patch == 0);
1572 std.testing.expect(target.os.version_range.linux.max.major == 4);
1573 std.testing.expect(target.os.version_range.linux.max.minor == 4);
1574 std.testing.expect(target.os.version_range.linux.max.patch == 1);
1517 std.testing.expect(target.os.version_range.linux.range.min.major == 3);
1518 std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
1519 std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
1520 std.testing.expect(target.os.version_range.linux.range.max.major == 4);
1521 std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
1522 std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
15751523 std.testing.expect(target.os.version_range.linux.glibc.major == 2);
15761524 std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
15771525 std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
src-self-hosted/libc_installation.zig+5-9
......@@ -7,11 +7,7 @@ const Allocator = std.mem.Allocator;
77const Batch = std.event.Batch;
88
99const is_darwin = Target.current.isDarwin();
10const is_windows = Target.current.isWindows();
11const is_freebsd = Target.current.isFreeBSD();
12const is_netbsd = Target.current.isNetBSD();
13const is_linux = Target.current.isLinux();
14const is_dragonfly = Target.current.isDragonFlyBSD();
10const is_windows = Target.current.os.tag == .windows;
1511const is_gnu = Target.current.isGnu();
1612
1713usingnamespace @import("windows_sdk.zig");
......@@ -216,10 +212,10 @@ pub const LibCInstallation = struct {
216212 var batch = Batch(FindError!void, 2, .auto_async).init();
217213 errdefer batch.wait() catch {};
218214 batch.add(&async self.findNativeIncludeDirPosix(args));
219 if (is_freebsd or is_netbsd) {
220 self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib");
221 } else if (is_linux or is_dragonfly) {
222 batch.add(&async self.findNativeCrtDirPosix(args));
215 switch (Target.current.os.tag) {
216 .freebsd, .netbsd => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),
217 .linux, .dragonfly => batch.add(&async self.findNativeCrtDirPosix(args)),
218 else => {},
223219 }
224220 break :blk batch.wait();
225221 };
test/assemble_and_link.zig+2-2
......@@ -1,8 +1,8 @@
1const builtin = @import("builtin");
1const std = @import("std");
22const tests = @import("tests.zig");
33
44pub fn addCases(cases: *tests.CompareOutputContext) void {
5 if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
5 if (std.Target.current.os.tag == .linux and std.Target.current.cpu.arch == .x86_64) {
66 cases.addAsm("hello world linux x86_64",
77 \\.text
88 \\.globl _start
test/compile_errors.zig+5-6
......@@ -1,5 +1,4 @@
11const tests = @import("tests.zig");
2const builtin = @import("builtin");
32const Target = @import("std").Target;
43
54pub fn addCases(cases: *tests.CompileErrorContext) void {
......@@ -387,10 +386,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
387386 , &[_][]const u8{
388387 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
389388 });
390 tc.target = Target{
389 tc.target = tests.Target{
391390 .Cross = .{
392391 .cpu = Target.Cpu.baseline(.wasm32),
393 .os = .wasi,
392 .os = Target.Os.defaultVersionRange(.wasi),
394393 .abi = .none,
395394 },
396395 };
......@@ -788,10 +787,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
788787 , &[_][]const u8{
789788 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
790789 });
791 tc.target = Target{
790 tc.target = tests.Target{
792791 .Cross = .{
793792 .cpu = Target.Cpu.baseline(.x86_64),
794 .os = .linux,
793 .os = Target.Os.defaultVersionRange(.linux),
795794 .abi = .gnu,
796795 },
797796 };
......@@ -1453,7 +1452,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14531452 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
14541453 });
14551454
1456 if (builtin.os == builtin.Os.linux) {
1455 if (Target.current.os.tag == .linux) {
14571456 cases.addTest("implicit dependency on libc",
14581457 \\extern "c" fn exit(u8) void;
14591458 \\export fn entry() void {
test/src/translate_c.zig+2-2
......@@ -19,7 +19,7 @@ pub const TranslateCContext = struct {
1919 sources: ArrayList(SourceFile),
2020 expected_lines: ArrayList([]const u8),
2121 allow_warnings: bool,
22 target: std.Target = .Native,
22 target: build.Target = .Native,
2323
2424 const SourceFile = struct {
2525 filename: []const u8,
......@@ -75,7 +75,7 @@ pub const TranslateCContext = struct {
7575 pub fn addWithTarget(
7676 self: *TranslateCContext,
7777 name: []const u8,
78 target: std.Target,
78 target: build.Target,
7979 source: []const u8,
8080 expected_lines: []const []const u8,
8181 ) void {
test/stack_traces.zig+38-39
......@@ -1,4 +1,3 @@
1const builtin = @import("builtin");
21const std = @import("std");
32const os = std.os;
43const tests = @import("tests.zig");
......@@ -43,32 +42,32 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
4342 \\}
4443 ;
4544
46 switch (builtin.os) {
45 switch (builtin.os.tag) {
4746 .freebsd => {
4847 cases.addCase(
4948 "return",
5049 source_return,
5150 [_][]const u8{
5251 // debug
53 \\error: TheSkyIsFalling
52 \\error: TheSkyIsFalling
5453 \\source.zig:4:5: [address] in main (test)
5554 \\ return error.TheSkyIsFalling;
5655 \\ ^
5756 \\
5857 ,
5958 // release-safe
60 \\error: TheSkyIsFalling
59 \\error: TheSkyIsFalling
6160 \\source.zig:4:5: [address] in std.start.main (test)
6261 \\ return error.TheSkyIsFalling;
6362 \\ ^
6463 \\
6564 ,
6665 // release-fast
67 \\error: TheSkyIsFalling
66 \\error: TheSkyIsFalling
6867 \\
6968 ,
7069 // release-small
71 \\error: TheSkyIsFalling
70 \\error: TheSkyIsFalling
7271 \\
7372 },
7473 );
......@@ -77,7 +76,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
7776 source_try_return,
7877 [_][]const u8{
7978 // debug
80 \\error: TheSkyIsFalling
79 \\error: TheSkyIsFalling
8180 \\source.zig:4:5: [address] in foo (test)
8281 \\ return error.TheSkyIsFalling;
8382 \\ ^
......@@ -87,7 +86,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
8786 \\
8887 ,
8988 // release-safe
90 \\error: TheSkyIsFalling
89 \\error: TheSkyIsFalling
9190 \\source.zig:4:5: [address] in std.start.main (test)
9291 \\ return error.TheSkyIsFalling;
9392 \\ ^
......@@ -97,11 +96,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
9796 \\
9897 ,
9998 // release-fast
100 \\error: TheSkyIsFalling
99 \\error: TheSkyIsFalling
101100 \\
102101 ,
103102 // release-small
104 \\error: TheSkyIsFalling
103 \\error: TheSkyIsFalling
105104 \\
106105 },
107106 );
......@@ -110,7 +109,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
110109 source_try_try_return_return,
111110 [_][]const u8{
112111 // debug
113 \\error: TheSkyIsFalling
112 \\error: TheSkyIsFalling
114113 \\source.zig:12:5: [address] in make_error (test)
115114 \\ return error.TheSkyIsFalling;
116115 \\ ^
......@@ -126,7 +125,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
126125 \\
127126 ,
128127 // release-safe
129 \\error: TheSkyIsFalling
128 \\error: TheSkyIsFalling
130129 \\source.zig:12:5: [address] in std.start.main (test)
131130 \\ return error.TheSkyIsFalling;
132131 \\ ^
......@@ -142,11 +141,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
142141 \\
143142 ,
144143 // release-fast
145 \\error: TheSkyIsFalling
144 \\error: TheSkyIsFalling
146145 \\
147146 ,
148147 // release-small
149 \\error: TheSkyIsFalling
148 \\error: TheSkyIsFalling
150149 \\
151150 },
152151 );
......@@ -157,25 +156,25 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
157156 source_return,
158157 [_][]const u8{
159158 // debug
160 \\error: TheSkyIsFalling
159 \\error: TheSkyIsFalling
161160 \\source.zig:4:5: [address] in main (test)
162161 \\ return error.TheSkyIsFalling;
163162 \\ ^
164163 \\
165164 ,
166165 // release-safe
167 \\error: TheSkyIsFalling
166 \\error: TheSkyIsFalling
168167 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
169168 \\ return error.TheSkyIsFalling;
170169 \\ ^
171170 \\
172171 ,
173172 // release-fast
174 \\error: TheSkyIsFalling
173 \\error: TheSkyIsFalling
175174 \\
176175 ,
177176 // release-small
178 \\error: TheSkyIsFalling
177 \\error: TheSkyIsFalling
179178 \\
180179 },
181180 );
......@@ -184,7 +183,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
184183 source_try_return,
185184 [_][]const u8{
186185 // debug
187 \\error: TheSkyIsFalling
186 \\error: TheSkyIsFalling
188187 \\source.zig:4:5: [address] in foo (test)
189188 \\ return error.TheSkyIsFalling;
190189 \\ ^
......@@ -194,7 +193,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
194193 \\
195194 ,
196195 // release-safe
197 \\error: TheSkyIsFalling
196 \\error: TheSkyIsFalling
198197 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
199198 \\ return error.TheSkyIsFalling;
200199 \\ ^
......@@ -204,11 +203,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
204203 \\
205204 ,
206205 // release-fast
207 \\error: TheSkyIsFalling
206 \\error: TheSkyIsFalling
208207 \\
209208 ,
210209 // release-small
211 \\error: TheSkyIsFalling
210 \\error: TheSkyIsFalling
212211 \\
213212 },
214213 );
......@@ -217,7 +216,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
217216 source_try_try_return_return,
218217 [_][]const u8{
219218 // debug
220 \\error: TheSkyIsFalling
219 \\error: TheSkyIsFalling
221220 \\source.zig:12:5: [address] in make_error (test)
222221 \\ return error.TheSkyIsFalling;
223222 \\ ^
......@@ -233,7 +232,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
233232 \\
234233 ,
235234 // release-safe
236 \\error: TheSkyIsFalling
235 \\error: TheSkyIsFalling
237236 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)
238237 \\ return error.TheSkyIsFalling;
239238 \\ ^
......@@ -249,11 +248,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
249248 \\
250249 ,
251250 // release-fast
252 \\error: TheSkyIsFalling
251 \\error: TheSkyIsFalling
253252 \\
254253 ,
255254 // release-small
256 \\error: TheSkyIsFalling
255 \\error: TheSkyIsFalling
257256 \\
258257 },
259258 );
......@@ -278,11 +277,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
278277 \\
279278 ,
280279 // release-fast
281 \\error: TheSkyIsFalling
280 \\error: TheSkyIsFalling
282281 \\
283282 ,
284283 // release-small
285 \\error: TheSkyIsFalling
284 \\error: TheSkyIsFalling
286285 \\
287286 },
288287 );
......@@ -311,11 +310,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
311310 \\
312311 ,
313312 // release-fast
314 \\error: TheSkyIsFalling
313 \\error: TheSkyIsFalling
315314 \\
316315 ,
317316 // release-small
318 \\error: TheSkyIsFalling
317 \\error: TheSkyIsFalling
319318 \\
320319 },
321320 );
......@@ -356,11 +355,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
356355 \\
357356 ,
358357 // release-fast
359 \\error: TheSkyIsFalling
358 \\error: TheSkyIsFalling
360359 \\
361360 ,
362361 // release-small
363 \\error: TheSkyIsFalling
362 \\error: TheSkyIsFalling
364363 \\
365364 },
366365 );
......@@ -371,7 +370,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
371370 source_return,
372371 [_][]const u8{
373372 // debug
374 \\error: TheSkyIsFalling
373 \\error: TheSkyIsFalling
375374 \\source.zig:4:5: [address] in main (test.obj)
376375 \\ return error.TheSkyIsFalling;
377376 \\ ^
......@@ -381,11 +380,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
381380 // --disabled-- results in segmenetation fault
382381 "",
383382 // release-fast
384 \\error: TheSkyIsFalling
383 \\error: TheSkyIsFalling
385384 \\
386385 ,
387386 // release-small
388 \\error: TheSkyIsFalling
387 \\error: TheSkyIsFalling
389388 \\
390389 },
391390 );
......@@ -407,11 +406,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
407406 // --disabled-- results in segmenetation fault
408407 "",
409408 // release-fast
410 \\error: TheSkyIsFalling
409 \\error: TheSkyIsFalling
411410 \\
412411 ,
413412 // release-small
414 \\error: TheSkyIsFalling
413 \\error: TheSkyIsFalling
415414 \\
416415 },
417416 );
......@@ -439,11 +438,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
439438 // --disabled-- results in segmenetation fault
440439 "",
441440 // release-fast
442 \\error: TheSkyIsFalling
441 \\error: TheSkyIsFalling
443442 \\
444443 ,
445444 // release-small
446 \\error: TheSkyIsFalling
445 \\error: TheSkyIsFalling
447446 \\
448447 },
449448 );
test/stage1/behavior/math.zig+10-10
......@@ -529,7 +529,7 @@ test "comptime_int xor" {
529529}
530530
531531test "f128" {
532 if (std.Target.current.isWindows()) {
532 if (std.Target.current.os.tag == .windows) {
533533 // TODO https://github.com/ziglang/zig/issues/508
534534 return error.SkipZigTest;
535535 }
......@@ -631,7 +631,7 @@ test "NaN comparison" {
631631 // TODO: https://github.com/ziglang/zig/issues/3338
632632 return error.SkipZigTest;
633633 }
634 if (std.Target.current.isWindows()) {
634 if (std.Target.current.os.tag == .windows) {
635635 // TODO https://github.com/ziglang/zig/issues/508
636636 return error.SkipZigTest;
637637 }
......@@ -666,14 +666,14 @@ test "128-bit multiplication" {
666666test "vector comparison" {
667667 const S = struct {
668668 fn doTheTest() void {
669 var a: @Vector(6, i32) = [_]i32{1, 3, -1, 5, 7, 9};
670 var b: @Vector(6, i32) = [_]i32{-1, 3, 0, 6, 10, -10};
671 expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{false, false, true, true, true, false}));
672 expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{false, true, true, true, true, false}));
673 expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{false, true, false, false, false, false}));
674 expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{true, false, true, true, true, true}));
675 expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{true, false, false, false, false, true}));
676 expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{true, true, false, false, false, true}));
669 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
670 var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
671 expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
672 expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
673 expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
674 expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
675 expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
676 expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
677677 }
678678 };
679679 S.doTheTest();
test/standalone.zig+2-2
......@@ -18,10 +18,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
1818 cases.addBuildFile("test/standalone/use_alias/build.zig");
1919 cases.addBuildFile("test/standalone/brace_expansion/build.zig");
2020 cases.addBuildFile("test/standalone/empty_env/build.zig");
21 if (std.Target.current.getOs() != .wasi) {
21 if (std.Target.current.os.tag != .wasi) {
2222 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");
2323 }
24 if (std.Target.current.getArch() == .x86_64) { // TODO add C ABI support for other architectures
24 if (std.Target.current.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures
2525 cases.addBuildFile("test/stage1/c_abi/build.zig");
2626 }
2727}
test/tests.zig+65-62
......@@ -1,16 +1,15 @@
11const std = @import("std");
2const builtin = std.builtin;
23const debug = std.debug;
34const warn = debug.warn;
45const build = std.build;
56pub const Target = build.Target;
6pub const CrossTarget = build.CrossTarget;
77const Buffer = std.Buffer;
88const io = std.io;
99const fs = std.fs;
1010const mem = std.mem;
1111const fmt = std.fmt;
1212const ArrayList = std.ArrayList;
13const builtin = @import("builtin");
1413const Mode = builtin.Mode;
1514const LibExeObjStep = build.LibExeObjStep;
1615
......@@ -54,18 +53,18 @@ const test_targets = blk: {
5453
5554 TestTarget{
5655 .target = Target{
57 .Cross = CrossTarget{
58 .cpu = Target.Cpu.baseline(.x86_64),
59 .os = Target.Os.defaultVersionRange(.linux),
56 .Cross = .{
57 .cpu = std.Target.Cpu.baseline(.x86_64),
58 .os = std.Target.Os.defaultVersionRange(.linux),
6059 .abi = .none,
6160 },
6261 },
6362 },
6463 TestTarget{
6564 .target = Target{
66 .Cross = CrossTarget{
67 .cpu = Target.Cpu.baseline(.x86_64),
68 .os = Target.Os.defaultVersionRange(.linux),
65 .Cross = .{
66 .cpu = std.Target.Cpu.baseline(.x86_64),
67 .os = std.Target.Os.defaultVersionRange(.linux),
6968 .abi = .gnu,
7069 },
7170 },
......@@ -73,9 +72,9 @@ const test_targets = blk: {
7372 },
7473 TestTarget{
7574 .target = Target{
76 .Cross = CrossTarget{
77 .cpu = Target.Cpu.baseline(.x86_64),
78 .os = Target.Os.defaultVersionRange(.linux),
75 .Cross = .{
76 .cpu = std.Target.Cpu.baseline(.x86_64),
77 .os = std.Target.Os.defaultVersionRange(.linux),
7978 .abi = .musl,
8079 },
8180 },
......@@ -84,18 +83,18 @@ const test_targets = blk: {
8483
8584 TestTarget{
8685 .target = Target{
87 .Cross = CrossTarget{
88 .cpu = Target.Cpu.baseline(.i386),
89 .os = Target.Os.defaultVersionRange(.linux),
86 .Cross = .{
87 .cpu = std.Target.Cpu.baseline(.i386),
88 .os = std.Target.Os.defaultVersionRange(.linux),
9089 .abi = .none,
9190 },
9291 },
9392 },
9493 TestTarget{
9594 .target = Target{
96 .Cross = CrossTarget{
97 .cpu = Target.Cpu.baseline(.i386),
98 .os = Target.Os.defaultVersionRange(.linux),
95 .Cross = .{
96 .cpu = std.Target.Cpu.baseline(.i386),
97 .os = std.Target.Os.defaultVersionRange(.linux),
9998 .abi = .musl,
10099 },
101100 },
......@@ -104,18 +103,18 @@ const test_targets = blk: {
104103
105104 TestTarget{
106105 .target = Target{
107 .Cross = CrossTarget{
108 .cpu = Target.Cpu.baseline(.aarch64),
109 .os = Target.Os.defaultVersionRange(.linux),
106 .Cross = .{
107 .cpu = std.Target.Cpu.baseline(.aarch64),
108 .os = std.Target.Os.defaultVersionRange(.linux),
110109 .abi = .none,
111110 },
112111 },
113112 },
114113 TestTarget{
115114 .target = Target{
116 .Cross = CrossTarget{
117 .cpu = Target.Cpu.baseline(.aarch64),
118 .os = Target.Os.defaultVersionRange(.linux),
115 .Cross = .{
116 .cpu = std.Target.Cpu.baseline(.aarch64),
117 .os = std.Target.Os.defaultVersionRange(.linux),
119118 .abi = .musl,
120119 },
121120 },
......@@ -123,9 +122,9 @@ const test_targets = blk: {
123122 },
124123 TestTarget{
125124 .target = Target{
126 .Cross = CrossTarget{
127 .cpu = Target.Cpu.baseline(.aarch64),
128 .os = Target.Os.defaultVersionRange(.linux),
125 .Cross = .{
126 .cpu = std.Target.Cpu.baseline(.aarch64),
127 .os = std.Target.Os.defaultVersionRange(.linux),
129128 .abi = .gnu,
130129 },
131130 },
......@@ -133,21 +132,25 @@ const test_targets = blk: {
133132 },
134133
135134 TestTarget{
136 .target = Target.parse(.{
137 .arch_os_abi = "arm-linux-none",
138 .cpu_features = "generic+v8a",
139 }) catch unreachable,
135 .target = .{
136 .Cross = std.Target.parse(.{
137 .arch_os_abi = "arm-linux-none",
138 .cpu_features = "generic+v8a",
139 }) catch unreachable,
140 },
140141 },
141142 TestTarget{
142 .target = Target.parse(.{
143 .arch_os_abi = "arm-linux-musleabihf",
144 .cpu_features = "generic+v8a",
145 }) catch unreachable,
143 .target = .{
144 .Cross = std.Target.parse(.{
145 .arch_os_abi = "arm-linux-musleabihf",
146 .cpu_features = "generic+v8a",
147 }) catch unreachable,
148 },
146149 .link_libc = true,
147150 },
148151 // TODO https://github.com/ziglang/zig/issues/3287
149152 //TestTarget{
150 // .target = Target.parse(.{
153 // .target = std.Target.parse(.{
151154 // .arch_os_abi = "arm-linux-gnueabihf",
152155 // .cpu_features = "generic+v8a",
153156 // }) catch unreachable,
......@@ -156,18 +159,18 @@ const test_targets = blk: {
156159
157160 TestTarget{
158161 .target = Target{
159 .Cross = CrossTarget{
160 .cpu = Target.Cpu.baseline(.mipsel),
161 .os = Target.Os.defaultVersionRange(.linux),
162 .Cross = .{
163 .cpu = std.Target.Cpu.baseline(.mipsel),
164 .os = std.Target.Os.defaultVersionRange(.linux),
162165 .abi = .none,
163166 },
164167 },
165168 },
166169 TestTarget{
167170 .target = Target{
168 .Cross = CrossTarget{
169 .cpu = Target.Cpu.baseline(.mipsel),
170 .os = Target.Os.defaultVersionRange(.linux),
171 .Cross = .{
172 .cpu = std.Target.Cpu.baseline(.mipsel),
173 .os = std.Target.Os.defaultVersionRange(.linux),
171174 .abi = .musl,
172175 },
173176 },
......@@ -176,9 +179,9 @@ const test_targets = blk: {
176179
177180 TestTarget{
178181 .target = Target{
179 .Cross = CrossTarget{
180 .cpu = Target.Cpu.baseline(.x86_64),
181 .os = Target.Os.defaultVersionRange(.macosx),
182 .Cross = .{
183 .cpu = std.Target.Cpu.baseline(.x86_64),
184 .os = std.Target.Os.defaultVersionRange(.macosx),
182185 .abi = .gnu,
183186 },
184187 },
......@@ -188,9 +191,9 @@ const test_targets = blk: {
188191
189192 TestTarget{
190193 .target = Target{
191 .Cross = CrossTarget{
192 .cpu = Target.Cpu.baseline(.i386),
193 .os = Target.Os.defaultVersionRange(.windows),
194 .Cross = .{
195 .cpu = std.Target.Cpu.baseline(.i386),
196 .os = std.Target.Os.defaultVersionRange(.windows),
194197 .abi = .msvc,
195198 },
196199 },
......@@ -198,9 +201,9 @@ const test_targets = blk: {
198201
199202 TestTarget{
200203 .target = Target{
201 .Cross = CrossTarget{
202 .cpu = Target.Cpu.baseline(.x86_64),
203 .os = Target.Os.defaultVersionRange(.windows),
204 .Cross = .{
205 .cpu = std.Target.Cpu.baseline(.x86_64),
206 .os = std.Target.Os.defaultVersionRange(.windows),
204207 .abi = .msvc,
205208 },
206209 },
......@@ -208,9 +211,9 @@ const test_targets = blk: {
208211
209212 TestTarget{
210213 .target = Target{
211 .Cross = CrossTarget{
212 .cpu = Target.Cpu.baseline(.i386),
213 .os = Target.Os.defaultVersionRange(.windows),
214 .Cross = .{
215 .cpu = std.Target.Cpu.baseline(.i386),
216 .os = std.Target.Os.defaultVersionRange(.windows),
214217 .abi = .gnu,
215218 },
216219 },
......@@ -219,9 +222,9 @@ const test_targets = blk: {
219222
220223 TestTarget{
221224 .target = Target{
222 .Cross = CrossTarget{
223 .cpu = Target.Cpu.baseline(.x86_64),
224 .os = Target.Os.defaultVersionRange(.windows),
225 .Cross = .{
226 .cpu = std.Target.Cpu.baseline(.x86_64),
227 .os = std.Target.Os.defaultVersionRange(.windows),
225228 .abi = .gnu,
226229 },
227230 },
......@@ -438,7 +441,7 @@ pub fn addPkgTests(
438441 if (skip_libc and test_target.link_libc)
439442 continue;
440443
441 if (test_target.link_libc and test_target.target.osRequiresLibC()) {
444 if (test_target.link_libc and test_target.target.getTarget().osRequiresLibC()) {
442445 // This would be a redundant test.
443446 continue;
444447 }
......@@ -448,8 +451,8 @@ pub fn addPkgTests(
448451
449452 const ArchTag = @TagType(builtin.Arch);
450453 if (test_target.disable_native and
451 test_target.target.getOs() == builtin.os and
452 test_target.target.getArch() == builtin.arch)
454 test_target.target.getOs() == std.Target.current.os.tag and
455 test_target.target.getArch() == std.Target.current.cpu.arch)
453456 {
454457 continue;
455458 }
......@@ -459,7 +462,7 @@ pub fn addPkgTests(
459462 } else false;
460463 if (!want_this_mode) continue;
461464
462 const libc_prefix = if (test_target.target.osRequiresLibC())
465 const libc_prefix = if (test_target.target.getTarget().osRequiresLibC())
463466 ""
464467 else if (test_target.link_libc)
465468 "c"
......@@ -469,7 +472,7 @@ pub fn addPkgTests(
469472 const triple_prefix = if (test_target.target == .Native)
470473 @as([]const u8, "native")
471474 else
472 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
475 test_target.target.zigTriple(b.allocator) catch unreachable;
473476
474477 const these_tests = b.addTest(root_src);
475478 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
......@@ -660,7 +663,7 @@ pub const StackTracesContext = struct {
660663 const delims = [_][]const u8{ ":", ":", ":", " in " };
661664 var marks = [_]usize{0} ** 4;
662665 // offset search past `[drive]:` on windows
663 var pos: usize = if (builtin.os == .windows) 2 else 0;
666 var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0;
664667 for (delims) |delim, i| {
665668 marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
666669 try buf.append(line);
test/translate_c.zig+19-15
......@@ -1,6 +1,6 @@
11const tests = @import("tests.zig");
2const builtin = @import("builtin");
3const Target = @import("std").Target;
2const std = @import("std");
3const Target = std.Target;
44
55pub fn addCases(cases: *tests.TranslateCContext) void {
66 cases.add("macro line continuation",
......@@ -665,7 +665,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
665665 \\}
666666 });
667667
668 if (builtin.os != builtin.Os.windows) {
668 if (Target.current.os.tag != .windows) {
669669 // Windows treats this as an enum with type c_int
670670 cases.add("big negative enum init values when C ABI supports long long enums",
671671 \\enum EnumWithInits {
......@@ -1064,7 +1064,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10641064 \\}
10651065 });
10661066
1067 if (builtin.os != builtin.Os.windows) {
1067 if (Target.current.os.tag != .windows) {
10681068 // sysv_abi not currently supported on windows
10691069 cases.add("Macro qualified functions",
10701070 \\void __attribute__((sysv_abi)) foo(void);
......@@ -1093,10 +1093,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10931093 \\pub const fn1 = ?fn (u8) callconv(.C) void;
10941094 });
10951095
1096 cases.addWithTarget("Calling convention", tests.Target{
1096 cases.addWithTarget("Calling convention", .{
10971097 .Cross = .{
10981098 .cpu = Target.Cpu.baseline(.i386),
1099 .os = .linux,
1099 .os = Target.Os.defaultVersionRange(.linux),
11001100 .abi = .none,
11011101 },
11021102 },
......@@ -1113,10 +1113,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11131113 \\pub fn foo5(a: [*c]f32) callconv(.Thiscall) void;
11141114 });
11151115
1116 cases.addWithTarget("Calling convention", Target.parse(.{
1117 .arch_os_abi = "arm-linux-none",
1118 .cpu_features = "generic+v8_5a",
1119 }) catch unreachable,
1116 cases.addWithTarget("Calling convention", .{
1117 .Cross = Target.parse(.{
1118 .arch_os_abi = "arm-linux-none",
1119 .cpu_features = "generic+v8_5a",
1120 }) catch unreachable,
1121 },
11201122 \\void __attribute__((pcs("aapcs"))) foo1(float *a);
11211123 \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
11221124 , &[_][]const u8{
......@@ -1124,10 +1126,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11241126 \\pub fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
11251127 });
11261128
1127 cases.addWithTarget("Calling convention", Target.parse(.{
1128 .arch_os_abi = "aarch64-linux-none",
1129 .cpu_features = "generic+v8_5a",
1130 }) catch unreachable,
1129 cases.addWithTarget("Calling convention", .{
1130 .Cross = Target.parse(.{
1131 .arch_os_abi = "aarch64-linux-none",
1132 .cpu_features = "generic+v8_5a",
1133 }) catch unreachable,
1134 },
11311135 \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
11321136 , &[_][]const u8{
11331137 \\pub fn foo1(a: [*c]f32) callconv(.Vectorcall) void;
......@@ -1596,7 +1600,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15961600 \\}
15971601 });
15981602
1599 if (builtin.os != .windows) {
1603 if (Target.current.os.tag != .windows) {
16001604 // When clang uses the <arch>-windows-none triple it behaves as MSVC and
16011605 // interprets the inner `struct Bar` as an anonymous structure
16021606 cases.add("type referenced struct",