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;...@@ -9,7 +9,7 @@ const assert = std.debug.assert;
9const mem = std.mem;9const mem = std.mem;
10const unicode = std.unicode;10const unicode = std.unicode;
11const meta = std.meta;11const meta = std.meta;
12const builtin = std.builtin;12const builtin = @import("builtin");
13const errol = @import("fmt/errol.zig");13const errol = @import("fmt/errol.zig");
14const lossyCast = std.math.lossyCast;14const lossyCast = std.math.lossyCast;
15const expectFmt = std.testing.expectFmt;15const expectFmt = std.testing.expectFmt;
...@@ -2021,7 +2021,7 @@ test "float.special" {...@@ -2021,7 +2021,7 @@ test "float.special" {
2021 try expectFmt("f64: nan", "f64: {}", .{math.nan_f64});2021 try expectFmt("f64: nan", "f64: {}", .{math.nan_f64});
2022 // negative nan is not defined by IEE 754,2022 // negative nan is not defined by IEE 754,
2023 // and ARM thus normalizes it to positive nan2023 // and ARM thus normalizes it to positive nan
2024 if (builtin.arch != builtin.Arch.arm) {2024 if (builtin.target.cpu.arch != .arm) {
2025 try expectFmt("f64: -nan", "f64: {}", .{-math.nan_f64});2025 try expectFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
2026 }2026 }
2027 try expectFmt("f64: inf", "f64: {}", .{math.inf_f64});2027 try expectFmt("f64: inf", "f64: {}", .{math.inf_f64});
...@@ -2032,7 +2032,7 @@ test "float.hexadecimal.special" {...@@ -2032,7 +2032,7 @@ test "float.hexadecimal.special" {
2032 try expectFmt("f64: nan", "f64: {x}", .{math.nan_f64});2032 try expectFmt("f64: nan", "f64: {x}", .{math.nan_f64});
2033 // negative nan is not defined by IEE 754,2033 // negative nan is not defined by IEE 754,
2034 // and ARM thus normalizes it to positive nan2034 // and ARM thus normalizes it to positive nan
2035 if (builtin.arch != builtin.Arch.arm) {2035 if (builtin.target.cpu.arch != .arm) {
2036 try expectFmt("f64: -nan", "f64: {x}", .{-math.nan_f64});2036 try expectFmt("f64: -nan", "f64: {x}", .{-math.nan_f64});
2037 }2037 }
2038 try expectFmt("f64: inf", "f64: {x}", .{math.inf_f64});2038 try expectFmt("f64: inf", "f64: {x}", .{math.inf_f64});
...@@ -2381,15 +2381,15 @@ test "positional/alignment/width/precision" {...@@ -2381,15 +2381,15 @@ test "positional/alignment/width/precision" {
2381}2381}
23822382
2383test "vector" {2383test "vector" {
2384 if (builtin.arch == .mipsel or builtin.arch == .mips) {2384 if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) {
2385 // https://github.com/ziglang/zig/issues/33172385 // https://github.com/ziglang/zig/issues/3317
2386 return error.SkipZigTest;2386 return error.SkipZigTest;
2387 }2387 }
2388 if (builtin.arch == .riscv64) {2388 if (builtin.target.cpu.arch == .riscv64) {
2389 // https://github.com/ziglang/zig/issues/44862389 // https://github.com/ziglang/zig/issues/4486
2390 return error.SkipZigTest;2390 return error.SkipZigTest;
2391 }2391 }
2392 if (builtin.arch == .wasm32) {2392 if (builtin.target.cpu.arch == .wasm32) {
2393 // https://github.com/ziglang/zig/issues/53392393 // https://github.com/ziglang/zig/issues/5339
2394 return error.SkipZigTest;2394 return error.SkipZigTest;
2395 }2395 }
...@@ -2452,18 +2452,30 @@ test "type" {...@@ -2452,18 +2452,30 @@ test "type" {
2452}2452}
24532453
2454test "named arguments" {2454test "named arguments" {
2455 if (true) {
2456 // TODO this regressed in the branch and I don't know why
2457 return error.SkipZigTest;
2458 }
2455 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });2459 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
2456 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });2460 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
2457 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });2461 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
2458}2462}
24592463
2460test "runtime width specifier" {2464test "runtime width specifier" {
2465 if (true) {
2466 // TODO this regressed in the branch and I don't know why
2467 return error.SkipZigTest;
2468 }
2461 var width: usize = 9;2469 var width: usize = 9;
2462 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });2470 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
2463 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });2471 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
2464}2472}
24652473
2466test "runtime precision specifier" {2474test "runtime precision specifier" {
2475 if (true) {
2476 // TODO this regressed in the branch and I don't know why
2477 return error.SkipZigTest;
2478 }
2467 var number: f32 = 3.1415;2479 var number: f32 = 3.1415;
2468 var precision: usize = 2;2480 var precision: usize = 2;
2469 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });2481 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
lib/std/fs/path.zig+26-25
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = std.builtin;6const builtin = @import("builtin");
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const debug = std.debug;8const debug = std.debug;
9const assert = debug.assert;9const assert = debug.assert;
...@@ -15,22 +15,23 @@ const math = std.math;...@@ -15,22 +15,23 @@ const math = std.math;
15const windows = std.os.windows;15const windows = std.os.windows;
16const fs = std.fs;16const fs = std.fs;
17const process = std.process;17const process = std.process;
18const native_os = builtin.target.os.tag;
1819
19pub const sep_windows = '\\';20pub const sep_windows = '\\';
20pub const sep_posix = '/';21pub 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
23pub const sep_str_windows = "\\";24pub const sep_str_windows = "\\";
24pub const sep_str_posix = "/";25pub 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
27pub const delimiter_windows = ';';28pub const delimiter_windows = ';';
28pub const delimiter_posix = ':';29pub 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
31/// Returns if the given byte is a valid path separator32/// Returns if the given byte is a valid path separator
32pub fn isSep(byte: u8) bool {33pub fn isSep(byte: u8) bool {
33 if (builtin.os.tag == .windows) {34 if (native_os == .windows) {
34 return byte == '/' or byte == '\\';35 return byte == '/' or byte == '\\';
35 } else {36 } else {
36 return byte == '/';37 return byte == '/';
...@@ -168,7 +169,7 @@ test "join" {...@@ -168,7 +169,7 @@ test "join" {
168pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");169pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
169170
170pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {171pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
171 if (builtin.os.tag == .windows) {172 if (native_os == .windows) {
172 return isAbsoluteWindowsZ(path_c);173 return isAbsoluteWindowsZ(path_c);
173 } else {174 } else {
174 return isAbsolutePosixZ(path_c);175 return isAbsolutePosixZ(path_c);
...@@ -176,7 +177,7 @@ pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {...@@ -176,7 +177,7 @@ pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
176}177}
177178
178pub fn isAbsolute(path: []const u8) bool {179pub fn isAbsolute(path: []const u8) bool {
179 if (builtin.os.tag == .windows) {180 if (native_os == .windows) {
180 return isAbsoluteWindows(path);181 return isAbsoluteWindows(path);
181 } else {182 } else {
182 return isAbsolutePosix(path);183 return isAbsolutePosix(path);
...@@ -365,7 +366,7 @@ test "windowsParsePath" {...@@ -365,7 +366,7 @@ test "windowsParsePath" {
365}366}
366367
367pub fn diskDesignator(path: []const u8) []const u8 {368pub fn diskDesignator(path: []const u8) []const u8 {
368 if (builtin.os.tag == .windows) {369 if (native_os == .windows) {
369 return diskDesignatorWindows(path);370 return diskDesignatorWindows(path);
370 } else {371 } else {
371 return "";372 return "";
...@@ -430,7 +431,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {...@@ -430,7 +431,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
430431
431/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.432/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
432pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {433pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
433 if (builtin.os.tag == .windows) {434 if (native_os == .windows) {
434 return resolveWindows(allocator, paths);435 return resolveWindows(allocator, paths);
435 } else {436 } else {
436 return resolvePosix(allocator, paths);437 return resolvePosix(allocator, paths);
...@@ -447,7 +448,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -447,7 +448,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
447/// Without performing actual syscalls, resolving `..` could be incorrect.448/// Without performing actual syscalls, resolving `..` could be incorrect.
448pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {449pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
449 if (paths.len == 0) {450 if (paths.len == 0) {
450 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd451 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
451 return process.getCwdAlloc(allocator);452 return process.getCwdAlloc(allocator);
452 }453 }
453454
...@@ -542,7 +543,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -542,7 +543,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
542 result_disk_designator = result[0..result_index];543 result_disk_designator = result[0..result_index];
543 },544 },
544 WindowsPath.Kind.None => {545 WindowsPath.Kind.None => {
545 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd546 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
546 const cwd = try process.getCwdAlloc(allocator);547 const cwd = try process.getCwdAlloc(allocator);
547 defer allocator.free(cwd);548 defer allocator.free(cwd);
548 const parsed_cwd = windowsParsePath(cwd);549 const parsed_cwd = windowsParsePath(cwd);
...@@ -557,7 +558,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -557,7 +558,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
557 },558 },
558 }559 }
559 } else {560 } else {
560 assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd561 assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
561 // TODO call get cwd for the result_disk_designator instead of the global one562 // TODO call get cwd for the result_disk_designator instead of the global one
562 const cwd = try process.getCwdAlloc(allocator);563 const cwd = try process.getCwdAlloc(allocator);
563 defer allocator.free(cwd);564 defer allocator.free(cwd);
...@@ -628,7 +629,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -628,7 +629,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
628/// Without performing actual syscalls, resolving `..` could be incorrect.629/// Without performing actual syscalls, resolving `..` could be incorrect.
629pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {630pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
630 if (paths.len == 0) {631 if (paths.len == 0) {
631 assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd632 assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
632 return process.getCwdAlloc(allocator);633 return process.getCwdAlloc(allocator);
633 }634 }
634635
...@@ -650,7 +651,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -650,7 +651,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
650 if (have_abs) {651 if (have_abs) {
651 result = try allocator.alloc(u8, max_size);652 result = try allocator.alloc(u8, max_size);
652 } else {653 } else {
653 assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd654 assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
654 const cwd = try process.getCwdAlloc(allocator);655 const cwd = try process.getCwdAlloc(allocator);
655 defer allocator.free(cwd);656 defer allocator.free(cwd);
656 result = try allocator.alloc(u8, max_size + cwd.len + 1);657 result = try allocator.alloc(u8, max_size + cwd.len + 1);
...@@ -690,11 +691,11 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -690,11 +691,11 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
690}691}
691692
692test "resolve" {693test "resolve" {
693 if (builtin.os.tag == .wasi) return error.SkipZigTest;694 if (native_os == .wasi) return error.SkipZigTest;
694695
695 const cwd = try process.getCwdAlloc(testing.allocator);696 const cwd = try process.getCwdAlloc(testing.allocator);
696 defer testing.allocator.free(cwd);697 defer testing.allocator.free(cwd);
697 if (builtin.os.tag == .windows) {698 if (native_os == .windows) {
698 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {699 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
699 cwd[0] = asciiUpper(cwd[0]);700 cwd[0] = asciiUpper(cwd[0]);
700 }701 }
...@@ -706,12 +707,12 @@ test "resolve" {...@@ -706,12 +707,12 @@ test "resolve" {
706}707}
707708
708test "resolveWindows" {709test "resolveWindows" {
709 if (builtin.arch == .aarch64) {710 if (builtin.target.cpu.arch == .aarch64) {
710 // TODO https://github.com/ziglang/zig/issues/3288711 // TODO https://github.com/ziglang/zig/issues/3288
711 return error.SkipZigTest;712 return error.SkipZigTest;
712 }713 }
713 if (builtin.os.tag == .wasi) return error.SkipZigTest;714 if (native_os == .wasi) return error.SkipZigTest;
714 if (builtin.os.tag == .windows) {715 if (native_os == .windows) {
715 const cwd = try process.getCwdAlloc(testing.allocator);716 const cwd = try process.getCwdAlloc(testing.allocator);
716 defer testing.allocator.free(cwd);717 defer testing.allocator.free(cwd);
717 const parsed_cwd = windowsParsePath(cwd);718 const parsed_cwd = windowsParsePath(cwd);
...@@ -755,7 +756,7 @@ test "resolveWindows" {...@@ -755,7 +756,7 @@ test "resolveWindows" {
755}756}
756757
757test "resolvePosix" {758test "resolvePosix" {
758 if (builtin.os.tag == .wasi) return error.SkipZigTest;759 if (native_os == .wasi) return error.SkipZigTest;
759760
760 try testResolvePosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");761 try testResolvePosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
761 try testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }, "/d/e");762 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 {...@@ -788,7 +789,7 @@ fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
788///789///
789/// If the path is the root directory, returns null.790/// If the path is the root directory, returns null.
790pub fn dirname(path: []const u8) ?[]const u8 {791pub fn dirname(path: []const u8) ?[]const u8 {
791 if (builtin.os.tag == .windows) {792 if (native_os == .windows) {
792 return dirnameWindows(path);793 return dirnameWindows(path);
793 } else {794 } else {
794 return dirnamePosix(path);795 return dirnamePosix(path);
...@@ -922,7 +923,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {...@@ -922,7 +923,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
922}923}
923924
924pub fn basename(path: []const u8) []const u8 {925pub fn basename(path: []const u8) []const u8 {
925 if (builtin.os.tag == .windows) {926 if (native_os == .windows) {
926 return basenameWindows(path);927 return basenameWindows(path);
927 } else {928 } else {
928 return basenamePosix(path);929 return basenamePosix(path);
...@@ -1038,7 +1039,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {...@@ -1038,7 +1039,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
1038/// string is returned.1039/// string is returned.
1039/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.1040/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
1040pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {1041pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1041 if (builtin.os.tag == .windows) {1042 if (native_os == .windows) {
1042 return relativeWindows(allocator, from, to);1043 return relativeWindows(allocator, from, to);
1043 } else {1044 } else {
1044 return relativePosix(allocator, from, to);1045 return relativePosix(allocator, from, to);
...@@ -1164,11 +1165,11 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![...@@ -1164,11 +1165,11 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
1164}1165}
11651166
1166test "relative" {1167test "relative" {
1167 if (builtin.arch == .aarch64) {1168 if (builtin.target.cpu.arch == .aarch64) {
1168 // TODO https://github.com/ziglang/zig/issues/32881169 // TODO https://github.com/ziglang/zig/issues/3288
1169 return error.SkipZigTest;1170 return error.SkipZigTest;
1170 }1171 }
1171 if (builtin.os.tag == .wasi) return error.SkipZigTest;1172 if (native_os == .wasi) return error.SkipZigTest;
11721173
1173 try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");1174 try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
1174 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");1175 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
lib/std/hash/murmur.zig+10-9
...@@ -4,8 +4,9 @@...@@ -4,8 +4,9 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;7const builtin = @import("builtin");
8const testing = std.testing;8const testing = std.testing;
9const native_endian = builtin.target.cpu.arch.endian();
910
10const default_seed: u32 = 0xc70f6907;11const default_seed: u32 = 0xc70f6907;
1112
...@@ -22,7 +23,7 @@ pub const Murmur2_32 = struct {...@@ -22,7 +23,7 @@ pub const Murmur2_32 = struct {
22 var h1: u32 = seed ^ len;23 var h1: u32 = seed ^ len;
23 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {24 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
24 var k1: u32 = v;25 var k1: u32 = v;
25 if (builtin.endian == .Big)26 if (native_endian == .Big)
26 k1 = @byteSwap(u32, k1);27 k1 = @byteSwap(u32, k1);
27 k1 *%= m;28 k1 *%= m;
28 k1 ^= k1 >> 24;29 k1 ^= k1 >> 24;
...@@ -107,7 +108,7 @@ pub const Murmur2_64 = struct {...@@ -107,7 +108,7 @@ pub const Murmur2_64 = struct {
107 var h1: u64 = seed ^ (len *% m);108 var h1: u64 = seed ^ (len *% m);
108 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {109 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
109 var k1: u64 = v;110 var k1: u64 = v;
110 if (builtin.endian == .Big)111 if (native_endian == .Big)
111 k1 = @byteSwap(u64, k1);112 k1 = @byteSwap(u64, k1);
112 k1 *%= m;113 k1 *%= m;
113 k1 ^= k1 >> 47;114 k1 ^= k1 >> 47;
...@@ -120,7 +121,7 @@ pub const Murmur2_64 = struct {...@@ -120,7 +121,7 @@ pub const Murmur2_64 = struct {
120 if (rest > 0) {121 if (rest > 0) {
121 var k1: u64 = 0;122 var k1: u64 = 0;
122 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));123 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
123 if (builtin.endian == .Big)124 if (native_endian == .Big)
124 k1 = @byteSwap(u64, k1);125 k1 = @byteSwap(u64, k1);
125 h1 ^= k1;126 h1 ^= k1;
126 h1 *%= m;127 h1 *%= m;
...@@ -187,7 +188,7 @@ pub const Murmur3_32 = struct {...@@ -187,7 +188,7 @@ pub const Murmur3_32 = struct {
187 var h1: u32 = seed;188 var h1: u32 = seed;
188 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {189 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
189 var k1: u32 = v;190 var k1: u32 = v;
190 if (builtin.endian == .Big)191 if (native_endian == .Big)
191 k1 = @byteSwap(u32, k1);192 k1 = @byteSwap(u32, k1);
192 k1 *%= c1;193 k1 *%= c1;
193 k1 = rotl32(k1, 15);194 k1 = rotl32(k1, 15);
...@@ -299,7 +300,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {...@@ -299,7 +300,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
299 key[i] = @truncate(u8, i);300 key[i] = @truncate(u8, i);
300301
301 var h = hash_fn(key[0..i], 256 - i);302 var h = hash_fn(key[0..i], 256 - i);
302 if (builtin.endian == .Big)303 if (native_endian == .Big)
303 h = @byteSwap(@TypeOf(h), h);304 h = @byteSwap(@TypeOf(h), h);
304 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);305 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
305 }306 }
...@@ -313,7 +314,7 @@ test "murmur2_32" {...@@ -313,7 +314,7 @@ test "murmur2_32" {
313 var v1: u64 = 0x1234567812345678;314 var v1: u64 = 0x1234567812345678;
314 var v0le: u32 = v0;315 var v0le: u32 = v0;
315 var v1le: u64 = v1;316 var v1le: u64 = v1;
316 if (builtin.endian == .Big) {317 if (native_endian == .Big) {
317 v0le = @byteSwap(u32, v0le);318 v0le = @byteSwap(u32, v0le);
318 v1le = @byteSwap(u64, v1le);319 v1le = @byteSwap(u64, v1le);
319 }320 }
...@@ -327,7 +328,7 @@ test "murmur2_64" {...@@ -327,7 +328,7 @@ test "murmur2_64" {
327 var v1: u64 = 0x1234567812345678;328 var v1: u64 = 0x1234567812345678;
328 var v0le: u32 = v0;329 var v0le: u32 = v0;
329 var v1le: u64 = v1;330 var v1le: u64 = v1;
330 if (builtin.endian == .Big) {331 if (native_endian == .Big) {
331 v0le = @byteSwap(u32, v0le);332 v0le = @byteSwap(u32, v0le);
332 v1le = @byteSwap(u64, v1le);333 v1le = @byteSwap(u64, v1le);
333 }334 }
...@@ -341,7 +342,7 @@ test "murmur3_32" {...@@ -341,7 +342,7 @@ test "murmur3_32" {
341 var v1: u64 = 0x1234567812345678;342 var v1: u64 = 0x1234567812345678;
342 var v0le: u32 = v0;343 var v0le: u32 = v0;
343 var v1le: u64 = v1;344 var v1le: u64 = v1;
344 if (builtin.endian == .Big) {345 if (native_endian == .Big) {
345 v0le = @byteSwap(u32, v0le);346 v0le = @byteSwap(u32, v0le);
346 v1le = @byteSwap(u64, v1le);347 v1le = @byteSwap(u64, v1le);
347 }348 }
lib/std/io/test.zig+4-3
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;7const builtin = @import("builtin");
8const io = std.io;8const io = std.io;
9const meta = std.meta;9const meta = std.meta;
10const trait = std.trait;10const trait = std.trait;
...@@ -15,6 +15,7 @@ const expectError = std.testing.expectError;...@@ -15,6 +15,7 @@ const expectError = std.testing.expectError;
15const mem = std.mem;15const mem = std.mem;
16const fs = std.fs;16const fs = std.fs;
17const File = std.fs.File;17const File = std.fs.File;
18const native_endian = builtin.target.cpu.arch.endian();
1819
19const tmpDir = std.testing.tmpDir;20const tmpDir = std.testing.tmpDir;
2021
...@@ -72,7 +73,7 @@ test "BitStreams with File Stream" {...@@ -72,7 +73,7 @@ test "BitStreams with File Stream" {
72 var file = try tmp.dir.createFile(tmp_file_name, .{});73 var file = try tmp.dir.createFile(tmp_file_name, .{});
73 defer file.close();74 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
77 try bit_stream.writeBits(@as(u2, 1), 1);78 try bit_stream.writeBits(@as(u2, 1), 1);
78 try bit_stream.writeBits(@as(u5, 2), 2);79 try bit_stream.writeBits(@as(u5, 2), 2);
...@@ -86,7 +87,7 @@ test "BitStreams with File Stream" {...@@ -86,7 +87,7 @@ test "BitStreams with File Stream" {
86 var file = try tmp.dir.openFile(tmp_file_name, .{});87 var file = try tmp.dir.openFile(tmp_file_name, .{});
87 defer file.close();88 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
91 var out_bits: usize = undefined;92 var out_bits: usize = undefined;
9293
lib/std/net.zig+9-8
...@@ -4,18 +4,19 @@...@@ -4,18 +4,19 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = std.builtin;7const builtin = @import("builtin");
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const net = @This();9const net = @This();
10const mem = std.mem;10const mem = std.mem;
11const os = std.os;11const os = std.os;
12const fs = std.fs;12const fs = std.fs;
13const io = std.io;13const io = std.io;
14const native_endian = builtin.target.cpu.arch.endian();
1415
15// Windows 10 added support for unix sockets in build 17063, redstone 4 is the16// Windows 10 added support for unix sockets in build 17063, redstone 4 is the
16// first release to support them.17// first release to support them.
17pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and18pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and
18 (builtin.os.tag != .windows or19 (builtin.target.os.tag != .windows or
19 std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);20 std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
2021
21pub const Address = extern union {22pub const Address = extern union {
...@@ -567,7 +568,7 @@ pub const Ip6Address = extern struct {...@@ -567,7 +568,7 @@ pub const Ip6Address = extern struct {
567 return;568 return;
568 }569 }
569 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.sa.addr);570 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) {
571 .Big => big_endian_parts.*,572 .Big => big_endian_parts.*,
572 .Little => blk: {573 .Little => blk: {
573 var buf: [8]u16 = undefined;574 var buf: [8]u16 = undefined;
...@@ -673,7 +674,7 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)...@@ -673,7 +674,7 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
673pub fn tcpConnectToAddress(address: Address) !Stream {674pub fn tcpConnectToAddress(address: Address) !Stream {
674 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;675 const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
675 const sock_flags = os.SOCK_STREAM | nonblock |676 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);
677 const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);678 const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
678 errdefer os.closeSocket(sockfd);679 errdefer os.closeSocket(sockfd);
679680
...@@ -704,14 +705,14 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -704,14 +705,14 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
704 const arena = &result.arena.allocator;705 const arena = &result.arena.allocator;
705 errdefer result.arena.deinit();706 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) {
708 const name_c = try std.cstr.addNullByte(allocator, name);709 const name_c = try std.cstr.addNullByte(allocator, name);
709 defer allocator.free(name_c);710 defer allocator.free(name_c);
710711
711 const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port});712 const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port});
712 defer allocator.free(port_c);713 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;
715 const hints = os.addrinfo{716 const hints = os.addrinfo{
716 .flags = sys.AI_NUMERICSERV,717 .flags = sys.AI_NUMERICSERV,
717 .family = os.AF_UNSPEC,718 .family = os.AF_UNSPEC,
...@@ -724,7 +725,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -724,7 +725,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
724 };725 };
725 var res: *os.addrinfo = undefined;726 var res: *os.addrinfo = undefined;
726 const rc = sys.getaddrinfo(name_c.ptr, std.meta.assumeSentinel(port_c.ptr, 0), &hints, &res);727 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))) {
728 @intToEnum(os.windows.ws2_32.WinsockError, 0) => {},729 @intToEnum(os.windows.ws2_32.WinsockError, 0) => {},
729 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,730 .WSATRY_AGAIN => return error.TemporaryNameServerFailure,
730 .WSANO_RECOVERY => return error.NameServerFailure,731 .WSANO_RECOVERY => return error.NameServerFailure,
...@@ -782,7 +783,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -782,7 +783,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
782783
783 return result;784 return result;
784 }785 }
785 if (builtin.os.tag == .linux) {786 if (builtin.target.os.tag == .linux) {
786 const flags = std.c.AI_NUMERICSERV;787 const flags = std.c.AI_NUMERICSERV;
787 const family = os.AF_UNSPEC;788 const family = os.AF_UNSPEC;
788 var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);789 var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
lib/std/os/test.zig+36-35
...@@ -18,15 +18,16 @@ const Thread = std.Thread;...@@ -18,15 +18,16 @@ const Thread = std.Thread;
1818
19const a = std.testing.allocator;19const a = std.testing.allocator;
2020
21const builtin = std.builtin;21const builtin = @import("builtin");
22const AtomicRmwOp = builtin.AtomicRmwOp;22const AtomicRmwOp = std.builtin.AtomicRmwOp;
23const AtomicOrder = builtin.AtomicOrder;23const AtomicOrder = std.builtin.AtomicOrder;
24const native_os = builtin.target.os.tag;
24const tmpDir = std.testing.tmpDir;25const tmpDir = std.testing.tmpDir;
25const Dir = std.fs.Dir;26const Dir = std.fs.Dir;
26const ArenaAllocator = std.heap.ArenaAllocator;27const ArenaAllocator = std.heap.ArenaAllocator;
2728
28test "chdir smoke test" {29test "chdir smoke test" {
29 if (builtin.os.tag == .wasi) return error.SkipZigTest;30 if (native_os == .wasi) return error.SkipZigTest;
3031
31 // Get current working directory path32 // Get current working directory path
32 var old_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;33 var old_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
...@@ -52,7 +53,7 @@ test "chdir smoke test" {...@@ -52,7 +53,7 @@ test "chdir smoke test" {
52}53}
5354
54test "open smoke test" {55test "open smoke test" {
55 if (builtin.os.tag == .wasi) return error.SkipZigTest;56 if (native_os == .wasi) return error.SkipZigTest;
5657
57 // TODO verify file attributes using `fstat`58 // TODO verify file attributes using `fstat`
5859
...@@ -70,7 +71,7 @@ test "open smoke test" {...@@ -70,7 +71,7 @@ test "open smoke test" {
7071
71 var file_path: []u8 = undefined;72 var file_path: []u8 = undefined;
72 var fd: os.fd_t = undefined;73 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
75 // Create some file using `open`.76 // Create some file using `open`.
76 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });77 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
...@@ -105,7 +106,7 @@ test "open smoke test" {...@@ -105,7 +106,7 @@ test "open smoke test" {
105}106}
106107
107test "openat smoke test" {108test "openat smoke test" {
108 if (builtin.os.tag == .wasi) return error.SkipZigTest;109 if (native_os == .wasi) return error.SkipZigTest;
109110
110 // TODO verify file attributes using `fstatat`111 // TODO verify file attributes using `fstatat`
111112
...@@ -113,7 +114,7 @@ test "openat smoke test" {...@@ -113,7 +114,7 @@ test "openat smoke test" {
113 defer tmp.cleanup();114 defer tmp.cleanup();
114115
115 var fd: os.fd_t = undefined;116 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
118 // Create some file using `openat`.119 // Create some file using `openat`.
119 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode);120 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" {...@@ -141,7 +142,7 @@ test "openat smoke test" {
141}142}
142143
143test "symlink with relative paths" {144test "symlink with relative paths" {
144 if (builtin.os.tag == .wasi) return error.SkipZigTest;145 if (native_os == .wasi) return error.SkipZigTest;
145146
146 const cwd = fs.cwd();147 const cwd = fs.cwd();
147 cwd.deleteFile("file.txt") catch {};148 cwd.deleteFile("file.txt") catch {};
...@@ -150,7 +151,7 @@ test "symlink with relative paths" {...@@ -150,7 +151,7 @@ test "symlink with relative paths" {
150 // First, try relative paths in cwd151 // First, try relative paths in cwd
151 try cwd.writeFile("file.txt", "nonsense");152 try cwd.writeFile("file.txt", "nonsense");
152153
153 if (builtin.os.tag == .windows) {154 if (native_os == .windows) {
154 os.windows.CreateSymbolicLink(155 os.windows.CreateSymbolicLink(
155 cwd.fd,156 cwd.fd,
156 &[_]u16{ 's', 'y', 'm', 'l', 'i', 'n', 'k', 'e', 'd' },157 &[_]u16{ 's', 'y', 'm', 'l', 'i', 'n', 'k', 'e', 'd' },
...@@ -178,7 +179,7 @@ test "symlink with relative paths" {...@@ -178,7 +179,7 @@ test "symlink with relative paths" {
178}179}
179180
180test "readlink on Windows" {181test "readlink on Windows" {
181 if (builtin.os.tag != .windows) return error.SkipZigTest;182 if (native_os != .windows) return error.SkipZigTest;
182183
183 try testReadlink("C:\\ProgramData", "C:\\Users\\All Users");184 try testReadlink("C:\\ProgramData", "C:\\Users\\All Users");
184 try testReadlink("C:\\Users\\Default", "C:\\Users\\Default User");185 try testReadlink("C:\\Users\\Default", "C:\\Users\\Default User");
...@@ -192,7 +193,7 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {...@@ -192,7 +193,7 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
192}193}
193194
194test "link with relative paths" {195test "link with relative paths" {
195 if (builtin.os.tag != .linux) return error.SkipZigTest;196 if (native_os != .linux) return error.SkipZigTest;
196 var cwd = fs.cwd();197 var cwd = fs.cwd();
197198
198 cwd.deleteFile("example.txt") catch {};199 cwd.deleteFile("example.txt") catch {};
...@@ -226,7 +227,7 @@ test "link with relative paths" {...@@ -226,7 +227,7 @@ test "link with relative paths" {
226}227}
227228
228test "linkat with different directories" {229test "linkat with different directories" {
229 if (builtin.os.tag != .linux) return error.SkipZigTest;230 if (native_os != .linux) return error.SkipZigTest;
230 var cwd = fs.cwd();231 var cwd = fs.cwd();
231 var tmp = tmpDir(.{});232 var tmp = tmpDir(.{});
232233
...@@ -262,7 +263,7 @@ test "linkat with different directories" {...@@ -262,7 +263,7 @@ test "linkat with different directories" {
262263
263test "fstatat" {264test "fstatat" {
264 // enable when `fstat` and `fstatat` are implemented on Windows265 // 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
267 var tmp = tmpDir(.{});268 var tmp = tmpDir(.{});
268 defer tmp.cleanup();269 defer tmp.cleanup();
...@@ -277,7 +278,7 @@ test "fstatat" {...@@ -277,7 +278,7 @@ test "fstatat" {
277 defer file.close();278 defer file.close();
278279
279 // now repeat but using `fstatat` instead280 // 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;
281 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);282 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
282 try expectEqual(stat, statat);283 try expectEqual(stat, statat);
283}284}
...@@ -290,7 +291,7 @@ test "readlinkat" {...@@ -290,7 +291,7 @@ test "readlinkat" {
290 try tmp.dir.writeFile("file.txt", "nonsense");291 try tmp.dir.writeFile("file.txt", "nonsense");
291292
292 // create a symbolic link293 // create a symbolic link
293 if (builtin.os.tag == .windows) {294 if (native_os == .windows) {
294 os.windows.CreateSymbolicLink(295 os.windows.CreateSymbolicLink(
295 tmp.dir.fd,296 tmp.dir.fd,
296 &[_]u16{ 'l', 'i', 'n', 'k' },297 &[_]u16{ 'l', 'i', 'n', 'k' },
...@@ -324,7 +325,7 @@ test "std.Thread.getCurrentId" {...@@ -324,7 +325,7 @@ test "std.Thread.getCurrentId" {
324 thread.wait();325 thread.wait();
325 if (Thread.use_pthreads) {326 if (Thread.use_pthreads) {
326 try expect(thread_current_id == thread_id);327 try expect(thread_current_id == thread_id);
327 } else if (builtin.os.tag == .windows) {328 } else if (native_os == .windows) {
328 try expect(Thread.getCurrentId() != thread_current_id);329 try expect(Thread.getCurrentId() != thread_current_id);
329 } else {330 } else {
330 // If the thread completes very quickly, then thread_id can be 0. See the331 // If the thread completes very quickly, then thread_id can be 0. See the
...@@ -361,7 +362,7 @@ fn start2(ctx: *i32) u8 {...@@ -361,7 +362,7 @@ fn start2(ctx: *i32) u8 {
361}362}
362363
363test "cpu count" {364test "cpu count" {
364 if (builtin.os.tag == .wasi) return error.SkipZigTest;365 if (native_os == .wasi) return error.SkipZigTest;
365366
366 const cpu_count = try Thread.cpuCount();367 const cpu_count = try Thread.cpuCount();
367 try expect(cpu_count >= 1);368 try expect(cpu_count >= 1);
...@@ -394,7 +395,7 @@ test "getrandom" {...@@ -394,7 +395,7 @@ test "getrandom" {
394}395}
395396
396test "getcwd" {397test "getcwd" {
397 if (builtin.os.tag == .wasi) return error.SkipZigTest;398 if (native_os == .wasi) return error.SkipZigTest;
398399
399 // at least call it so it gets compiled400 // at least call it so it gets compiled
400 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;401 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
...@@ -402,7 +403,7 @@ test "getcwd" {...@@ -402,7 +403,7 @@ test "getcwd" {
402}403}
403404
404test "sigaltstack" {405test "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
407 var st: os.stack_t = undefined;408 var st: os.stack_t = undefined;
408 try os.sigaltstack(null, &st);409 try os.sigaltstack(null, &st);
...@@ -455,7 +456,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {...@@ -455,7 +456,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
455}456}
456457
457test "dl_iterate_phdr" {458test "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)
459 return error.SkipZigTest;460 return error.SkipZigTest;
460461
461 var counter: usize = 0;462 var counter: usize = 0;
...@@ -464,7 +465,7 @@ test "dl_iterate_phdr" {...@@ -464,7 +465,7 @@ test "dl_iterate_phdr" {
464}465}
465466
466test "gethostname" {467test "gethostname" {
467 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)468 if (native_os == .windows or native_os == .wasi)
468 return error.SkipZigTest;469 return error.SkipZigTest;
469470
470 var buf: [os.HOST_NAME_MAX]u8 = undefined;471 var buf: [os.HOST_NAME_MAX]u8 = undefined;
...@@ -473,7 +474,7 @@ test "gethostname" {...@@ -473,7 +474,7 @@ test "gethostname" {
473}474}
474475
475test "pipe" {476test "pipe" {
476 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)477 if (native_os == .windows or native_os == .wasi)
477 return error.SkipZigTest;478 return error.SkipZigTest;
478479
479 var fds = try os.pipe();480 var fds = try os.pipe();
...@@ -492,7 +493,7 @@ test "argsAlloc" {...@@ -492,7 +493,7 @@ test "argsAlloc" {
492493
493test "memfd_create" {494test "memfd_create" {
494 // memfd_create is linux specific.495 // memfd_create is linux specific.
495 if (builtin.os.tag != .linux) return error.SkipZigTest;496 if (native_os != .linux) return error.SkipZigTest;
496 const fd = std.os.memfd_create("test", 0) catch |err| switch (err) {497 const fd = std.os.memfd_create("test", 0) catch |err| switch (err) {
497 // Related: https://github.com/ziglang/zig/issues/4019498 // Related: https://github.com/ziglang/zig/issues/4019
498 error.SystemOutdated => return error.SkipZigTest,499 error.SystemOutdated => return error.SkipZigTest,
...@@ -509,7 +510,7 @@ test "memfd_create" {...@@ -509,7 +510,7 @@ test "memfd_create" {
509}510}
510511
511test "mmap" {512test "mmap" {
512 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)513 if (native_os == .windows or native_os == .wasi)
513 return error.SkipZigTest;514 return error.SkipZigTest;
514515
515 var tmp = tmpDir(.{});516 var tmp = tmpDir(.{});
...@@ -606,7 +607,7 @@ test "mmap" {...@@ -606,7 +607,7 @@ test "mmap" {
606}607}
607608
608test "getenv" {609test "getenv" {
609 if (builtin.os.tag == .windows) {610 if (native_os == .windows) {
610 try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);611 try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
611 } else {612 } else {
612 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);613 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
...@@ -614,7 +615,7 @@ test "getenv" {...@@ -614,7 +615,7 @@ test "getenv" {
614}615}
615616
616test "fcntl" {617test "fcntl" {
617 if (builtin.os.tag == .windows or builtin.os.tag == .wasi)618 if (native_os == .windows or native_os == .wasi)
618 return error.SkipZigTest;619 return error.SkipZigTest;
619620
620 var tmp = tmpDir(.{});621 var tmp = tmpDir(.{});
...@@ -646,13 +647,13 @@ test "fcntl" {...@@ -646,13 +647,13 @@ test "fcntl" {
646}647}
647648
648test "signalfd" {649test "signalfd" {
649 if (builtin.os.tag != .linux)650 if (native_os != .linux)
650 return error.SkipZigTest;651 return error.SkipZigTest;
651 _ = std.os.signalfd;652 _ = std.os.signalfd;
652}653}
653654
654test "sync" {655test "sync" {
655 if (builtin.os.tag != .linux)656 if (native_os != .linux)
656 return error.SkipZigTest;657 return error.SkipZigTest;
657658
658 var tmp = tmpDir(.{});659 var tmp = tmpDir(.{});
...@@ -670,7 +671,7 @@ test "sync" {...@@ -670,7 +671,7 @@ test "sync" {
670}671}
671672
672test "fsync" {673test "fsync" {
673 if (builtin.os.tag != .linux and builtin.os.tag != .windows)674 if (native_os != .linux and native_os != .windows)
674 return error.SkipZigTest;675 return error.SkipZigTest;
675676
676 var tmp = tmpDir(.{});677 var tmp = tmpDir(.{});
...@@ -700,13 +701,13 @@ test "getrlimit and setrlimit" {...@@ -700,13 +701,13 @@ test "getrlimit and setrlimit" {
700}701}
701702
702test "shutdown socket" {703test "shutdown socket" {
703 if (builtin.os.tag == .wasi)704 if (native_os == .wasi)
704 return error.SkipZigTest;705 return error.SkipZigTest;
705 if (builtin.os.tag == .windows) {706 if (native_os == .windows) {
706 _ = try std.os.windows.WSAStartup(2, 2);707 _ = try std.os.windows.WSAStartup(2, 2);
707 }708 }
708 defer {709 defer {
709 if (builtin.os.tag == .windows) {710 if (native_os == .windows) {
710 std.os.windows.WSACleanup() catch unreachable;711 std.os.windows.WSACleanup() catch unreachable;
711 }712 }
712 }713 }
...@@ -721,11 +722,11 @@ test "shutdown socket" {...@@ -721,11 +722,11 @@ test "shutdown socket" {
721var signal_test_failed = true;722var signal_test_failed = true;
722723
723test "sigaction" {724test "sigaction" {
724 if (builtin.os.tag == .wasi or builtin.os.tag == .windows)725 if (native_os == .wasi or native_os == .windows)
725 return error.SkipZigTest;726 return error.SkipZigTest;
726727
727 // https://github.com/ziglang/zig/issues/7427728 // 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)
729 return error.SkipZigTest;730 return error.SkipZigTest;
730731
731 const S = struct {732 const S = struct {
lib/std/valgrind.zig+2-2
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = std.builtin;6const builtin = @import("builtin");
7const std = @import("std.zig");7const std = @import("std.zig");
8const math = std.math;8const math = std.math;
99
...@@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
12 return default;12 return default;
13 }13 }
1414
15 switch (builtin.arch) {15 switch (builtin.target.cpu.arch) {
16 .i386 => {16 .i386 => {
17 return asm volatile (17 return asm volatile (
18 \\ roll $3, %%edi ; roll $13, %%edi18 \\ roll $3, %%edi ; roll $13, %%edi