authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 16:08:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 16:08:09-07:00
log83677074f95930d0fcb95a4eed276637d52afde7
tree9ca5af3f5723a9f721b3bc558ecbe5520740d83c
parent8cfa231104cc99c3a6c85a2ff691d89e6c856e89

std: update regarding std.builtin reorganization

There are also some regressed std.fmt tests here and I haven't figured out what's wrong yet.

7 files changed, 105 insertions(+), 88 deletions(-)

lib/std/fmt.zig+18-6
......@@ -9,7 +9,7 @@ const assert = std.debug.assert;
99const mem = std.mem;
1010const unicode = std.unicode;
1111const meta = std.meta;
12const builtin = std.builtin;
12const builtin = @import("builtin");
1313const errol = @import("fmt/errol.zig");
1414const lossyCast = std.math.lossyCast;
1515const expectFmt = std.testing.expectFmt;
......@@ -2021,7 +2021,7 @@ test "float.special" {
20212021 try expectFmt("f64: nan", "f64: {}", .{math.nan_f64});
20222022 // negative nan is not defined by IEE 754,
20232023 // and ARM thus normalizes it to positive nan
2024 if (builtin.arch != builtin.Arch.arm) {
2024 if (builtin.target.cpu.arch != .arm) {
20252025 try expectFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
20262026 }
20272027 try expectFmt("f64: inf", "f64: {}", .{math.inf_f64});
......@@ -2032,7 +2032,7 @@ test "float.hexadecimal.special" {
20322032 try expectFmt("f64: nan", "f64: {x}", .{math.nan_f64});
20332033 // negative nan is not defined by IEE 754,
20342034 // and ARM thus normalizes it to positive nan
2035 if (builtin.arch != builtin.Arch.arm) {
2035 if (builtin.target.cpu.arch != .arm) {
20362036 try expectFmt("f64: -nan", "f64: {x}", .{-math.nan_f64});
20372037 }
20382038 try expectFmt("f64: inf", "f64: {x}", .{math.inf_f64});
......@@ -2381,15 +2381,15 @@ test "positional/alignment/width/precision" {
23812381}
23822382
23832383test "vector" {
2384 if (builtin.arch == .mipsel or builtin.arch == .mips) {
2384 if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) {
23852385 // https://github.com/ziglang/zig/issues/3317
23862386 return error.SkipZigTest;
23872387 }
2388 if (builtin.arch == .riscv64) {
2388 if (builtin.target.cpu.arch == .riscv64) {
23892389 // https://github.com/ziglang/zig/issues/4486
23902390 return error.SkipZigTest;
23912391 }
2392 if (builtin.arch == .wasm32) {
2392 if (builtin.target.cpu.arch == .wasm32) {
23932393 // https://github.com/ziglang/zig/issues/5339
23942394 return error.SkipZigTest;
23952395 }
......@@ -2452,18 +2452,30 @@ test "type" {
24522452}
24532453
24542454test "named arguments" {
2455 if (true) {
2456 // TODO this regressed in the branch and I don't know why
2457 return error.SkipZigTest;
2458 }
24552459 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
24562460 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
24572461 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
24582462}
24592463
24602464test "runtime width specifier" {
2465 if (true) {
2466 // TODO this regressed in the branch and I don't know why
2467 return error.SkipZigTest;
2468 }
24612469 var width: usize = 9;
24622470 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
24632471 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
24642472}
24652473
24662474test "runtime precision specifier" {
2475 if (true) {
2476 // TODO this regressed in the branch and I don't know why
2477 return error.SkipZigTest;
2478 }
24672479 var number: f32 = 3.1415;
24682480 var precision: usize = 2;
24692481 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
lib/std/fs/path.zig+26-25
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = std.builtin;
6const builtin = @import("builtin");
77const std = @import("../std.zig");
88const debug = std.debug;
99const assert = debug.assert;
......@@ -15,22 +15,23 @@ const math = std.math;
1515const windows = std.os.windows;
1616const fs = std.fs;
1717const process = std.process;
18const native_os = builtin.target.os.tag;
1819
1920pub const sep_windows = '\\';
2021pub const sep_posix = '/';
21pub const sep = if (builtin.os.tag == .windows) sep_windows else sep_posix;
22pub const sep = if (native_os == .windows) sep_windows else sep_posix;
2223
2324pub const sep_str_windows = "\\";
2425pub const sep_str_posix = "/";
25pub const sep_str = if (builtin.os.tag == .windows) sep_str_windows else sep_str_posix;
26pub const sep_str = if (native_os == .windows) sep_str_windows else sep_str_posix;
2627
2728pub const delimiter_windows = ';';
2829pub const delimiter_posix = ':';
29pub const delimiter = if (builtin.os.tag == .windows) delimiter_windows else delimiter_posix;
30pub const delimiter = if (native_os == .windows) delimiter_windows else delimiter_posix;
3031
3132/// Returns if the given byte is a valid path separator
3233pub fn isSep(byte: u8) bool {
33 if (builtin.os.tag == .windows) {
34 if (native_os == .windows) {
3435 return byte == '/' or byte == '\\';
3536 } else {
3637 return byte == '/';
......@@ -168,7 +169,7 @@ test "join" {
168169pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
169170
170171pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
171 if (builtin.os.tag == .windows) {
172 if (native_os == .windows) {
172173 return isAbsoluteWindowsZ(path_c);
173174 } else {
174175 return isAbsolutePosixZ(path_c);
......@@ -176,7 +177,7 @@ pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
176177}
177178
178179pub fn isAbsolute(path: []const u8) bool {
179 if (builtin.os.tag == .windows) {
180 if (native_os == .windows) {
180181 return isAbsoluteWindows(path);
181182 } else {
182183 return isAbsolutePosix(path);
......@@ -365,7 +366,7 @@ test "windowsParsePath" {
365366}
366367
367368pub fn diskDesignator(path: []const u8) []const u8 {
368 if (builtin.os.tag == .windows) {
369 if (native_os == .windows) {
369370 return diskDesignatorWindows(path);
370371 } else {
371372 return "";
......@@ -430,7 +431,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
430431
431432/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
432433pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
433 if (builtin.os.tag == .windows) {
434 if (native_os == .windows) {
434435 return resolveWindows(allocator, paths);
435436 } else {
436437 return resolvePosix(allocator, paths);
......@@ -447,7 +448,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
447448/// Without performing actual syscalls, resolving `..` could be incorrect.
448449pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
449450 if (paths.len == 0) {
450 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
451 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
451452 return process.getCwdAlloc(allocator);
452453 }
453454
......@@ -542,7 +543,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
542543 result_disk_designator = result[0..result_index];
543544 },
544545 WindowsPath.Kind.None => {
545 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
546 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
546547 const cwd = try process.getCwdAlloc(allocator);
547548 defer allocator.free(cwd);
548549 const parsed_cwd = windowsParsePath(cwd);
......@@ -557,7 +558,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
557558 },
558559 }
559560 } else {
560 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
561 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
561562 // TODO call get cwd for the result_disk_designator instead of the global one
562563 const cwd = try process.getCwdAlloc(allocator);
563564 defer allocator.free(cwd);
......@@ -628,7 +629,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
628629/// Without performing actual syscalls, resolving `..` could be incorrect.
629630pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
630631 if (paths.len == 0) {
631 assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd
632 assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
632633 return process.getCwdAlloc(allocator);
633634 }
634635
......@@ -650,7 +651,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
650651 if (have_abs) {
651652 result = try allocator.alloc(u8, max_size);
652653 } else {
653 assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd
654 assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
654655 const cwd = try process.getCwdAlloc(allocator);
655656 defer allocator.free(cwd);
656657 result = try allocator.alloc(u8, max_size + cwd.len + 1);
......@@ -690,11 +691,11 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
690691}
691692
692693test "resolve" {
693 if (builtin.os.tag == .wasi) return error.SkipZigTest;
694 if (native_os == .wasi) return error.SkipZigTest;
694695
695696 const cwd = try process.getCwdAlloc(testing.allocator);
696697 defer testing.allocator.free(cwd);
697 if (builtin.os.tag == .windows) {
698 if (native_os == .windows) {
698699 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
699700 cwd[0] = asciiUpper(cwd[0]);
700701 }
......@@ -706,12 +707,12 @@ test "resolve" {
706707}
707708
708709test "resolveWindows" {
709 if (builtin.arch == .aarch64) {
710 if (builtin.target.cpu.arch == .aarch64) {
710711 // TODO https://github.com/ziglang/zig/issues/3288
711712 return error.SkipZigTest;
712713 }
713 if (builtin.os.tag == .wasi) return error.SkipZigTest;
714 if (builtin.os.tag == .windows) {
714 if (native_os == .wasi) return error.SkipZigTest;
715 if (native_os == .windows) {
715716 const cwd = try process.getCwdAlloc(testing.allocator);
716717 defer testing.allocator.free(cwd);
717718 const parsed_cwd = windowsParsePath(cwd);
......@@ -755,7 +756,7 @@ test "resolveWindows" {
755756}
756757
757758test "resolvePosix" {
758 if (builtin.os.tag == .wasi) return error.SkipZigTest;
759 if (native_os == .wasi) return error.SkipZigTest;
759760
760761 try testResolvePosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
761762 try testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }, "/d/e");
......@@ -788,7 +789,7 @@ fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
788789///
789790/// If the path is the root directory, returns null.
790791pub fn dirname(path: []const u8) ?[]const u8 {
791 if (builtin.os.tag == .windows) {
792 if (native_os == .windows) {
792793 return dirnameWindows(path);
793794 } else {
794795 return dirnamePosix(path);
......@@ -922,7 +923,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
922923}
923924
924925pub fn basename(path: []const u8) []const u8 {
925 if (builtin.os.tag == .windows) {
926 if (native_os == .windows) {
926927 return basenameWindows(path);
927928 } else {
928929 return basenamePosix(path);
......@@ -1038,7 +1039,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
10381039/// string is returned.
10391040/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
10401041pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1041 if (builtin.os.tag == .windows) {
1042 if (native_os == .windows) {
10421043 return relativeWindows(allocator, from, to);
10431044 } else {
10441045 return relativePosix(allocator, from, to);
......@@ -1164,11 +1165,11 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
11641165}
11651166
11661167test "relative" {
1167 if (builtin.arch == .aarch64) {
1168 if (builtin.target.cpu.arch == .aarch64) {
11681169 // TODO https://github.com/ziglang/zig/issues/3288
11691170 return error.SkipZigTest;
11701171 }
1171 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1172 if (native_os == .wasi) return error.SkipZigTest;
11721173
11731174 try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
11741175 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
lib/std/hash/murmur.zig+10-9
......@@ -4,8 +4,9 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = std.builtin;
7const builtin = @import("builtin");
88const testing = std.testing;
9const native_endian = builtin.target.cpu.arch.endian();
910
1011const default_seed: u32 = 0xc70f6907;
1112
......@@ -22,7 +23,7 @@ pub const Murmur2_32 = struct {
2223 var h1: u32 = seed ^ len;
2324 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
2425 var k1: u32 = v;
25 if (builtin.endian == .Big)
26 if (native_endian == .Big)
2627 k1 = @byteSwap(u32, k1);
2728 k1 *%= m;
2829 k1 ^= k1 >> 24;
......@@ -107,7 +108,7 @@ pub const Murmur2_64 = struct {
107108 var h1: u64 = seed ^ (len *% m);
108109 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
109110 var k1: u64 = v;
110 if (builtin.endian == .Big)
111 if (native_endian == .Big)
111112 k1 = @byteSwap(u64, k1);
112113 k1 *%= m;
113114 k1 ^= k1 >> 47;
......@@ -120,7 +121,7 @@ pub const Murmur2_64 = struct {
120121 if (rest > 0) {
121122 var k1: u64 = 0;
122123 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
123 if (builtin.endian == .Big)
124 if (native_endian == .Big)
124125 k1 = @byteSwap(u64, k1);
125126 h1 ^= k1;
126127 h1 *%= m;
......@@ -187,7 +188,7 @@ pub const Murmur3_32 = struct {
187188 var h1: u32 = seed;
188189 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
189190 var k1: u32 = v;
190 if (builtin.endian == .Big)
191 if (native_endian == .Big)
191192 k1 = @byteSwap(u32, k1);
192193 k1 *%= c1;
193194 k1 = rotl32(k1, 15);
......@@ -299,7 +300,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
299300 key[i] = @truncate(u8, i);
300301
301302 var h = hash_fn(key[0..i], 256 - i);
302 if (builtin.endian == .Big)
303 if (native_endian == .Big)
303304 h = @byteSwap(@TypeOf(h), h);
304305 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
305306 }
......@@ -313,7 +314,7 @@ test "murmur2_32" {
313314 var v1: u64 = 0x1234567812345678;
314315 var v0le: u32 = v0;
315316 var v1le: u64 = v1;
316 if (builtin.endian == .Big) {
317 if (native_endian == .Big) {
317318 v0le = @byteSwap(u32, v0le);
318319 v1le = @byteSwap(u64, v1le);
319320 }
......@@ -327,7 +328,7 @@ test "murmur2_64" {
327328 var v1: u64 = 0x1234567812345678;
328329 var v0le: u32 = v0;
329330 var v1le: u64 = v1;
330 if (builtin.endian == .Big) {
331 if (native_endian == .Big) {
331332 v0le = @byteSwap(u32, v0le);
332333 v1le = @byteSwap(u64, v1le);
333334 }
......@@ -341,7 +342,7 @@ test "murmur3_32" {
341342 var v1: u64 = 0x1234567812345678;
342343 var v0le: u32 = v0;
343344 var v1le: u64 = v1;
344 if (builtin.endian == .Big) {
345 if (native_endian == .Big) {
345346 v0le = @byteSwap(u32, v0le);
346347 v1le = @byteSwap(u64, v1le);
347348 }
lib/std/io/test.zig+4-3
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = std.builtin;
7const builtin = @import("builtin");
88const io = std.io;
99const meta = std.meta;
1010const trait = std.trait;
......@@ -15,6 +15,7 @@ const expectError = std.testing.expectError;
1515const mem = std.mem;
1616const fs = std.fs;
1717const File = std.fs.File;
18const native_endian = builtin.target.cpu.arch.endian();
1819
1920const tmpDir = std.testing.tmpDir;
2021
......@@ -72,7 +73,7 @@ test "BitStreams with File Stream" {
7273 var file = try tmp.dir.createFile(tmp_file_name, .{});
7374 defer file.close();
7475
75 var bit_stream = io.bitWriter(builtin.endian, file.writer());
76 var bit_stream = io.bitWriter(native_endian, file.writer());
7677
7778 try bit_stream.writeBits(@as(u2, 1), 1);
7879 try bit_stream.writeBits(@as(u5, 2), 2);
......@@ -86,7 +87,7 @@ test "BitStreams with File Stream" {
8687 var file = try tmp.dir.openFile(tmp_file_name, .{});
8788 defer file.close();
8889
89 var bit_stream = io.bitReader(builtin.endian, file.reader());
90 var bit_stream = io.bitReader(native_endian, file.reader());
9091
9192 var out_bits: usize = undefined;
9293
lib/std/net.zig+9-8
......@@ -4,18 +4,19 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = std.builtin;
7const builtin = @import("builtin");
88const assert = std.debug.assert;
99const net = @This();
1010const mem = std.mem;
1111const os = std.os;
1212const fs = std.fs;
1313const io = std.io;
14const native_endian = builtin.target.cpu.arch.endian();
1415
1516// Windows 10 added support for unix sockets in build 17063, redstone 4 is the
1617// first release to support them.
1718pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and
18 (builtin.os.tag != .windows or
19 (builtin.target.os.tag != .windows or
1920 std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
2021
2122pub const Address = extern union {
......@@ -567,7 +568,7 @@ pub const Ip6Address = extern struct {
567568 return;
568569 }
569570 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.sa.addr);
570 const native_endian_parts = switch (builtin.endian) {
571 const native_endian_parts = switch (native_endian) {
571572 .Big => big_endian_parts.*,
572573 .Little => blk: {
573574 var buf: [8]u16 = undefined;
......@@ -673,7 +674,7 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
673674pub fn tcpConnectToAddress(address: Address) !Stream {
674675 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
675676 const sock_flags = os.SOCK_STREAM | nonblock |
676 (if (builtin.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
677 (if (builtin.target.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
677678 const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
678679 errdefer os.closeSocket(sockfd);
679680
......@@ -704,14 +705,14 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
704705 const arena = &result.arena.allocator;
705706 errdefer result.arena.deinit();
706707
707 if (builtin.os.tag == .windows or builtin.link_libc) {
708 if (builtin.target.os.tag == .windows or builtin.link_libc) {
708709 const name_c = try std.cstr.addNullByte(allocator, name);
709710 defer allocator.free(name_c);
710711
711712 const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port});
712713 defer allocator.free(port_c);
713714
714 const sys = if (builtin.os.tag == .windows) os.windows.ws2_32 else os.system;
715 const sys = if (builtin.target.os.tag == .windows) os.windows.ws2_32 else os.system;
715716 const hints = os.addrinfo{
716717 .flags = sys.AI_NUMERICSERV,
717718 .family = os.AF_UNSPEC,
......@@ -724,7 +725,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
724725 };
725726 var res: *os.addrinfo = undefined;
726727 const rc = sys.getaddrinfo(name_c.ptr, std.meta.assumeSentinel(port_c.ptr, 0), &hints, &res);
727 if (builtin.os.tag == .windows) switch (@intToEnum(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {
728 if (builtin.target.os.tag == .windows) switch (@intToEnum(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {
728729 @intToEnum(os.windows.ws2_32.WinsockError, 0) => {},
729730 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,
730731 .WSANO_RECOVERY => return error.NameServerFailure,
......@@ -782,7 +783,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
782783
783784 return result;
784785 }
785 if (builtin.os.tag == .linux) {
786 if (builtin.target.os.tag == .linux) {
786787 const flags = std.c.AI_NUMERICSERV;
787788 const family = os.AF_UNSPEC;
788789 var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
lib/std/os/test.zig+36-35
......@@ -18,15 +18,16 @@ const Thread = std.Thread;
1818
1919const a = std.testing.allocator;
2020
21const builtin = std.builtin;
22const AtomicRmwOp = builtin.AtomicRmwOp;
23const AtomicOrder = builtin.AtomicOrder;
21const builtin = @import("builtin");
22const AtomicRmwOp = std.builtin.AtomicRmwOp;
23const AtomicOrder = std.builtin.AtomicOrder;
24const native_os = builtin.target.os.tag;
2425const tmpDir = std.testing.tmpDir;
2526const Dir = std.fs.Dir;
2627const ArenaAllocator = std.heap.ArenaAllocator;
2728
2829test "chdir smoke test" {
29 if (builtin.os.tag == .wasi) return error.SkipZigTest;
30 if (native_os == .wasi) return error.SkipZigTest;
3031
3132 // Get current working directory path
3233 var old_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
......@@ -52,7 +53,7 @@ test "chdir smoke test" {
5253}
5354
5455test "open smoke test" {
55 if (builtin.os.tag == .wasi) return error.SkipZigTest;
56 if (native_os == .wasi) return error.SkipZigTest;
5657
5758 // TODO verify file attributes using `fstat`
5859
......@@ -70,7 +71,7 @@ test "open smoke test" {
7071
7172 var file_path: []u8 = undefined;
7273 var fd: os.fd_t = undefined;
73 const mode: os.mode_t = if (builtin.os.tag == .windows) 0 else 0o666;
74 const mode: os.mode_t = if (native_os == .windows) 0 else 0o666;
7475
7576 // Create some file using `open`.
7677 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
......@@ -105,7 +106,7 @@ test "open smoke test" {
105106}
106107
107108test "openat smoke test" {
108 if (builtin.os.tag == .wasi) return error.SkipZigTest;
109 if (native_os == .wasi) return error.SkipZigTest;
109110
110111 // TODO verify file attributes using `fstatat`
111112
......@@ -113,7 +114,7 @@ test "openat smoke test" {
113114 defer tmp.cleanup();
114115
115116 var fd: os.fd_t = undefined;
116 const mode: os.mode_t = if (builtin.os.tag == .windows) 0 else 0o666;
117 const mode: os.mode_t = if (native_os == .windows) 0 else 0o666;
117118
118119 // Create some file using `openat`.
119120 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode);
......@@ -141,7 +142,7 @@ test "openat smoke test" {
141142}
142143
143144test "symlink with relative paths" {
144 if (builtin.os.tag == .wasi) return error.SkipZigTest;
145 if (native_os == .wasi) return error.SkipZigTest;
145146
146147 const cwd = fs.cwd();
147148 cwd.deleteFile("file.txt") catch {};
......@@ -150,7 +151,7 @@ test "symlink with relative paths" {
150151 // First, try relative paths in cwd
151152 try cwd.writeFile("file.txt", "nonsense");
152153
153 if (builtin.os.tag == .windows) {
154 if (native_os == .windows) {
154155 os.windows.CreateSymbolicLink(
155156 cwd.fd,
156157 &[_]u16{ 's', 'y', 'm', 'l', 'i', 'n', 'k', 'e', 'd' },
......@@ -178,7 +179,7 @@ test "symlink with relative paths" {
178179}
179180
180181test "readlink on Windows" {
181 if (builtin.os.tag != .windows) return error.SkipZigTest;
182 if (native_os != .windows) return error.SkipZigTest;
182183
183184 try testReadlink("C:\\ProgramData", "C:\\Users\\All Users");
184185 try testReadlink("C:\\Users\\Default", "C:\\Users\\Default User");
......@@ -192,7 +193,7 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
192193}
193194
194195test "link with relative paths" {
195 if (builtin.os.tag != .linux) return error.SkipZigTest;
196 if (native_os != .linux) return error.SkipZigTest;
196197 var cwd = fs.cwd();
197198
198199 cwd.deleteFile("example.txt") catch {};
......@@ -226,7 +227,7 @@ test "link with relative paths" {
226227}
227228
228229test "linkat with different directories" {
229 if (builtin.os.tag != .linux) return error.SkipZigTest;
230 if (native_os != .linux) return error.SkipZigTest;
230231 var cwd = fs.cwd();
231232 var tmp = tmpDir(.{});
232233
......@@ -262,7 +263,7 @@ test "linkat with different directories" {
262263
263264test "fstatat" {
264265 // enable when `fstat` and `fstatat` are implemented on Windows
265 if (builtin.os.tag == .windows) return error.SkipZigTest;
266 if (native_os == .windows) return error.SkipZigTest;
266267
267268 var tmp = tmpDir(.{});
268269 defer tmp.cleanup();
......@@ -277,7 +278,7 @@ test "fstatat" {
277278 defer file.close();
278279
279280 // now repeat but using `fstatat` instead
280 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
281 const flags = if (native_os == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
281282 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
282283 try expectEqual(stat, statat);
283284}
......@@ -290,7 +291,7 @@ test "readlinkat" {
290291 try tmp.dir.writeFile("file.txt", "nonsense");
291292
292293 // create a symbolic link
293 if (builtin.os.tag == .windows) {
294 if (native_os == .windows) {
294295 os.windows.CreateSymbolicLink(
295296 tmp.dir.fd,
296297 &[_]u16{ 'l', 'i', 'n', 'k' },
......@@ -324,7 +325,7 @@ test "std.Thread.getCurrentId" {
324325 thread.wait();
325326 if (Thread.use_pthreads) {
326327 try expect(thread_current_id == thread_id);
327 } else if (builtin.os.tag == .windows) {
328 } else if (native_os == .windows) {
328329 try expect(Thread.getCurrentId() != thread_current_id);
329330 } else {
330331 // If the thread completes very quickly, then thread_id can be 0. See the
......@@ -361,7 +362,7 @@ fn start2(ctx: *i32) u8 {
361362}
362363
363364test "cpu count" {
364 if (builtin.os.tag == .wasi) return error.SkipZigTest;
365 if (native_os == .wasi) return error.SkipZigTest;
365366
366367 const cpu_count = try Thread.cpuCount();
367368 try expect(cpu_count >= 1);
......@@ -394,7 +395,7 @@ test "getrandom" {
394395}
395396
396397test "getcwd" {
397 if (builtin.os.tag == .wasi) return error.SkipZigTest;
398 if (native_os == .wasi) return error.SkipZigTest;
398399
399400 // at least call it so it gets compiled
400401 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
......@@ -402,7 +403,7 @@ test "getcwd" {
402403}
403404
404405test "sigaltstack" {
405 if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest;
406 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
406407
407408 var st: os.stack_t = undefined;
408409 try os.sigaltstack(null, &st);
......@@ -455,7 +456,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
455456}
456457
457458test "dl_iterate_phdr" {
458 if (builtin.os.tag == .windows or builtin.os.tag == .wasi or builtin.os.tag == .macos)
459 if (native_os == .windows or native_os == .wasi or native_os == .macos)
459460 return error.SkipZigTest;
460461
461462 var counter: usize = 0;
......@@ -464,7 +465,7 @@ test "dl_iterate_phdr" {
464465}
465466
466467test "gethostname" {
467 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
468 if (native_os == .windows or native_os == .wasi)
468469 return error.SkipZigTest;
469470
470471 var buf: [os.HOST_NAME_MAX]u8 = undefined;
......@@ -473,7 +474,7 @@ test "gethostname" {
473474}
474475
475476test "pipe" {
476 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
477 if (native_os == .windows or native_os == .wasi)
477478 return error.SkipZigTest;
478479
479480 var fds = try os.pipe();
......@@ -492,7 +493,7 @@ test "argsAlloc" {
492493
493494test "memfd_create" {
494495 // memfd_create is linux specific.
495 if (builtin.os.tag != .linux) return error.SkipZigTest;
496 if (native_os != .linux) return error.SkipZigTest;
496497 const fd = std.os.memfd_create("test", 0) catch |err| switch (err) {
497498 // Related: https://github.com/ziglang/zig/issues/4019
498499 error.SystemOutdated => return error.SkipZigTest,
......@@ -509,7 +510,7 @@ test "memfd_create" {
509510}
510511
511512test "mmap" {
512 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
513 if (native_os == .windows or native_os == .wasi)
513514 return error.SkipZigTest;
514515
515516 var tmp = tmpDir(.{});
......@@ -606,7 +607,7 @@ test "mmap" {
606607}
607608
608609test "getenv" {
609 if (builtin.os.tag == .windows) {
610 if (native_os == .windows) {
610611 try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
611612 } else {
612613 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
......@@ -614,7 +615,7 @@ test "getenv" {
614615}
615616
616617test "fcntl" {
617 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
618 if (native_os == .windows or native_os == .wasi)
618619 return error.SkipZigTest;
619620
620621 var tmp = tmpDir(.{});
......@@ -646,13 +647,13 @@ test "fcntl" {
646647}
647648
648649test "signalfd" {
649 if (builtin.os.tag != .linux)
650 if (native_os != .linux)
650651 return error.SkipZigTest;
651652 _ = std.os.signalfd;
652653}
653654
654655test "sync" {
655 if (builtin.os.tag != .linux)
656 if (native_os != .linux)
656657 return error.SkipZigTest;
657658
658659 var tmp = tmpDir(.{});
......@@ -670,7 +671,7 @@ test "sync" {
670671}
671672
672673test "fsync" {
673 if (builtin.os.tag != .linux and builtin.os.tag != .windows)
674 if (native_os != .linux and native_os != .windows)
674675 return error.SkipZigTest;
675676
676677 var tmp = tmpDir(.{});
......@@ -700,13 +701,13 @@ test "getrlimit and setrlimit" {
700701}
701702
702703test "shutdown socket" {
703 if (builtin.os.tag == .wasi)
704 if (native_os == .wasi)
704705 return error.SkipZigTest;
705 if (builtin.os.tag == .windows) {
706 if (native_os == .windows) {
706707 _ = try std.os.windows.WSAStartup(2, 2);
707708 }
708709 defer {
709 if (builtin.os.tag == .windows) {
710 if (native_os == .windows) {
710711 std.os.windows.WSACleanup() catch unreachable;
711712 }
712713 }
......@@ -721,11 +722,11 @@ test "shutdown socket" {
721722var signal_test_failed = true;
722723
723724test "sigaction" {
724 if (builtin.os.tag == .wasi or builtin.os.tag == .windows)
725 if (native_os == .wasi or native_os == .windows)
725726 return error.SkipZigTest;
726727
727728 // https://github.com/ziglang/zig/issues/7427
728 if (builtin.os.tag == .linux and builtin.arch == .i386)
729 if (native_os == .linux and builtin.target.cpu.arch == .i386)
729730 return error.SkipZigTest;
730731
731732 const S = struct {
lib/std/valgrind.zig+2-2
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = std.builtin;
6const builtin = @import("builtin");
77const std = @import("std.zig");
88const math = std.math;
99
......@@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
1212 return default;
1313 }
1414
15 switch (builtin.arch) {
15 switch (builtin.target.cpu.arch) {
1616 .i386 => {
1717 return asm volatile (
1818 \\ roll $3, %%edi ; roll $13, %%edi