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.
This commit is contained in:
Andrew Kelley 2021-05-17 16:08:09 -07:00
parent 8cfa231104
commit 83677074f9
7 changed files with 105 additions and 88 deletions

View File

@ -9,7 +9,7 @@ const assert = std.debug.assert;
const mem = std.mem;
const unicode = std.unicode;
const meta = std.meta;
const builtin = std.builtin;
const builtin = @import("builtin");
const errol = @import("fmt/errol.zig");
const lossyCast = std.math.lossyCast;
const expectFmt = std.testing.expectFmt;
@ -2021,7 +2021,7 @@ test "float.special" {
try expectFmt("f64: nan", "f64: {}", .{math.nan_f64});
// negative nan is not defined by IEE 754,
// and ARM thus normalizes it to positive nan
if (builtin.arch != builtin.Arch.arm) {
if (builtin.target.cpu.arch != .arm) {
try expectFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
}
try expectFmt("f64: inf", "f64: {}", .{math.inf_f64});
@ -2032,7 +2032,7 @@ test "float.hexadecimal.special" {
try expectFmt("f64: nan", "f64: {x}", .{math.nan_f64});
// negative nan is not defined by IEE 754,
// and ARM thus normalizes it to positive nan
if (builtin.arch != builtin.Arch.arm) {
if (builtin.target.cpu.arch != .arm) {
try expectFmt("f64: -nan", "f64: {x}", .{-math.nan_f64});
}
try expectFmt("f64: inf", "f64: {x}", .{math.inf_f64});
@ -2381,15 +2381,15 @@ test "positional/alignment/width/precision" {
}
test "vector" {
if (builtin.arch == .mipsel or builtin.arch == .mips) {
if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) {
// https://github.com/ziglang/zig/issues/3317
return error.SkipZigTest;
}
if (builtin.arch == .riscv64) {
if (builtin.target.cpu.arch == .riscv64) {
// https://github.com/ziglang/zig/issues/4486
return error.SkipZigTest;
}
if (builtin.arch == .wasm32) {
if (builtin.target.cpu.arch == .wasm32) {
// https://github.com/ziglang/zig/issues/5339
return error.SkipZigTest;
}
@ -2452,18 +2452,30 @@ test "type" {
}
test "named arguments" {
if (true) {
// TODO this regressed in the branch and I don't know why
return error.SkipZigTest;
}
try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
}
test "runtime width specifier" {
if (true) {
// TODO this regressed in the branch and I don't know why
return error.SkipZigTest;
}
var width: usize = 9;
try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
}
test "runtime precision specifier" {
if (true) {
// TODO this regressed in the branch and I don't know why
return error.SkipZigTest;
}
var number: f32 = 3.1415;
var precision: usize = 2;
try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });

View File

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const builtin = std.builtin;
const builtin = @import("builtin");
const std = @import("../std.zig");
const debug = std.debug;
const assert = debug.assert;
@ -15,22 +15,23 @@ const math = std.math;
const windows = std.os.windows;
const fs = std.fs;
const process = std.process;
const native_os = builtin.target.os.tag;
pub const sep_windows = '\\';
pub const sep_posix = '/';
pub const sep = if (builtin.os.tag == .windows) sep_windows else sep_posix;
pub const sep = if (native_os == .windows) sep_windows else sep_posix;
pub const sep_str_windows = "\\";
pub const sep_str_posix = "/";
pub const sep_str = if (builtin.os.tag == .windows) sep_str_windows else sep_str_posix;
pub const sep_str = if (native_os == .windows) sep_str_windows else sep_str_posix;
pub const delimiter_windows = ';';
pub const delimiter_posix = ':';
pub const delimiter = if (builtin.os.tag == .windows) delimiter_windows else delimiter_posix;
pub const delimiter = if (native_os == .windows) delimiter_windows else delimiter_posix;
/// Returns if the given byte is a valid path separator
pub fn isSep(byte: u8) bool {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return byte == '/' or byte == '\\';
} else {
return byte == '/';
@ -168,7 +169,7 @@ test "join" {
pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return isAbsoluteWindowsZ(path_c);
} else {
return isAbsolutePosixZ(path_c);
@ -176,7 +177,7 @@ pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
}
pub fn isAbsolute(path: []const u8) bool {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return isAbsoluteWindows(path);
} else {
return isAbsolutePosix(path);
@ -365,7 +366,7 @@ test "windowsParsePath" {
}
pub fn diskDesignator(path: []const u8) []const u8 {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return diskDesignatorWindows(path);
} else {
return "";
@ -430,7 +431,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return resolveWindows(allocator, paths);
} else {
return resolvePosix(allocator, paths);
@ -447,7 +448,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
/// Without performing actual syscalls, resolving `..` could be incorrect.
pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
if (paths.len == 0) {
assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
return process.getCwdAlloc(allocator);
}
@ -542,7 +543,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
result_disk_designator = result[0..result_index];
},
WindowsPath.Kind.None => {
assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
const cwd = try process.getCwdAlloc(allocator);
defer allocator.free(cwd);
const parsed_cwd = windowsParsePath(cwd);
@ -557,7 +558,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
},
}
} else {
assert(builtin.os.tag == .windows); // resolveWindows called on non windows can't use getCwd
assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd
// TODO call get cwd for the result_disk_designator instead of the global one
const cwd = try process.getCwdAlloc(allocator);
defer allocator.free(cwd);
@ -628,7 +629,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
/// Without performing actual syscalls, resolving `..` could be incorrect.
pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
if (paths.len == 0) {
assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd
assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
return process.getCwdAlloc(allocator);
}
@ -650,7 +651,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
if (have_abs) {
result = try allocator.alloc(u8, max_size);
} else {
assert(builtin.os.tag != .windows); // resolvePosix called on windows can't use getCwd
assert(native_os != .windows); // resolvePosix called on windows can't use getCwd
const cwd = try process.getCwdAlloc(allocator);
defer allocator.free(cwd);
result = try allocator.alloc(u8, max_size + cwd.len + 1);
@ -690,11 +691,11 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
}
test "resolve" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
const cwd = try process.getCwdAlloc(testing.allocator);
defer testing.allocator.free(cwd);
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
cwd[0] = asciiUpper(cwd[0]);
}
@ -706,12 +707,12 @@ test "resolve" {
}
test "resolveWindows" {
if (builtin.arch == .aarch64) {
if (builtin.target.cpu.arch == .aarch64) {
// TODO https://github.com/ziglang/zig/issues/3288
return error.SkipZigTest;
}
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (builtin.os.tag == .windows) {
if (native_os == .wasi) return error.SkipZigTest;
if (native_os == .windows) {
const cwd = try process.getCwdAlloc(testing.allocator);
defer testing.allocator.free(cwd);
const parsed_cwd = windowsParsePath(cwd);
@ -755,7 +756,7 @@ test "resolveWindows" {
}
test "resolvePosix" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
try testResolvePosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
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 {
///
/// If the path is the root directory, returns null.
pub fn dirname(path: []const u8) ?[]const u8 {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return dirnameWindows(path);
} else {
return dirnamePosix(path);
@ -922,7 +923,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
}
pub fn basename(path: []const u8) []const u8 {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return basenameWindows(path);
} else {
return basenamePosix(path);
@ -1038,7 +1039,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
/// string is returned.
/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
return relativeWindows(allocator, from, to);
} else {
return relativePosix(allocator, from, to);
@ -1164,11 +1165,11 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
}
test "relative" {
if (builtin.arch == .aarch64) {
if (builtin.target.cpu.arch == .aarch64) {
// TODO https://github.com/ziglang/zig/issues/3288
return error.SkipZigTest;
}
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");

View File

@ -4,8 +4,9 @@
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const builtin = @import("builtin");
const testing = std.testing;
const native_endian = builtin.target.cpu.arch.endian();
const default_seed: u32 = 0xc70f6907;
@ -22,7 +23,7 @@ pub const Murmur2_32 = struct {
var h1: u32 = seed ^ len;
for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
var k1: u32 = v;
if (builtin.endian == .Big)
if (native_endian == .Big)
k1 = @byteSwap(u32, k1);
k1 *%= m;
k1 ^= k1 >> 24;
@ -107,7 +108,7 @@ pub const Murmur2_64 = struct {
var h1: u64 = seed ^ (len *% m);
for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
var k1: u64 = v;
if (builtin.endian == .Big)
if (native_endian == .Big)
k1 = @byteSwap(u64, k1);
k1 *%= m;
k1 ^= k1 >> 47;
@ -120,7 +121,7 @@ pub const Murmur2_64 = struct {
if (rest > 0) {
var k1: u64 = 0;
@memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
if (builtin.endian == .Big)
if (native_endian == .Big)
k1 = @byteSwap(u64, k1);
h1 ^= k1;
h1 *%= m;
@ -187,7 +188,7 @@ pub const Murmur3_32 = struct {
var h1: u32 = seed;
for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
var k1: u32 = v;
if (builtin.endian == .Big)
if (native_endian == .Big)
k1 = @byteSwap(u32, k1);
k1 *%= c1;
k1 = rotl32(k1, 15);
@ -299,7 +300,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
key[i] = @truncate(u8, i);
var h = hash_fn(key[0..i], 256 - i);
if (builtin.endian == .Big)
if (native_endian == .Big)
h = @byteSwap(@TypeOf(h), h);
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
}
@ -313,7 +314,7 @@ test "murmur2_32" {
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
var v1le: u64 = v1;
if (builtin.endian == .Big) {
if (native_endian == .Big) {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
@ -327,7 +328,7 @@ test "murmur2_64" {
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
var v1le: u64 = v1;
if (builtin.endian == .Big) {
if (native_endian == .Big) {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
@ -341,7 +342,7 @@ test "murmur3_32" {
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
var v1le: u64 = v1;
if (builtin.endian == .Big) {
if (native_endian == .Big) {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}

View File

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const std = @import("std");
const builtin = std.builtin;
const builtin = @import("builtin");
const io = std.io;
const meta = std.meta;
const trait = std.trait;
@ -15,6 +15,7 @@ const expectError = std.testing.expectError;
const mem = std.mem;
const fs = std.fs;
const File = std.fs.File;
const native_endian = builtin.target.cpu.arch.endian();
const tmpDir = std.testing.tmpDir;
@ -72,7 +73,7 @@ test "BitStreams with File Stream" {
var file = try tmp.dir.createFile(tmp_file_name, .{});
defer file.close();
var bit_stream = io.bitWriter(builtin.endian, file.writer());
var bit_stream = io.bitWriter(native_endian, file.writer());
try bit_stream.writeBits(@as(u2, 1), 1);
try bit_stream.writeBits(@as(u5, 2), 2);
@ -86,7 +87,7 @@ test "BitStreams with File Stream" {
var file = try tmp.dir.openFile(tmp_file_name, .{});
defer file.close();
var bit_stream = io.bitReader(builtin.endian, file.reader());
var bit_stream = io.bitReader(native_endian, file.reader());
var out_bits: usize = undefined;

View File

@ -4,18 +4,19 @@
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const std = @import("std.zig");
const builtin = std.builtin;
const builtin = @import("builtin");
const assert = std.debug.assert;
const net = @This();
const mem = std.mem;
const os = std.os;
const fs = std.fs;
const io = std.io;
const native_endian = builtin.target.cpu.arch.endian();
// Windows 10 added support for unix sockets in build 17063, redstone 4 is the
// first release to support them.
pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and
(builtin.os.tag != .windows or
(builtin.target.os.tag != .windows or
std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
pub const Address = extern union {
@ -567,7 +568,7 @@ pub const Ip6Address = extern struct {
return;
}
const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.sa.addr);
const native_endian_parts = switch (builtin.endian) {
const native_endian_parts = switch (native_endian) {
.Big => big_endian_parts.*,
.Little => blk: {
var buf: [8]u16 = undefined;
@ -673,7 +674,7 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
pub fn tcpConnectToAddress(address: Address) !Stream {
const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
const sock_flags = os.SOCK_STREAM | nonblock |
(if (builtin.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
(if (builtin.target.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
errdefer os.closeSocket(sockfd);
@ -704,14 +705,14 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
const arena = &result.arena.allocator;
errdefer result.arena.deinit();
if (builtin.os.tag == .windows or builtin.link_libc) {
if (builtin.target.os.tag == .windows or builtin.link_libc) {
const name_c = try std.cstr.addNullByte(allocator, name);
defer allocator.free(name_c);
const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port});
defer allocator.free(port_c);
const sys = if (builtin.os.tag == .windows) os.windows.ws2_32 else os.system;
const sys = if (builtin.target.os.tag == .windows) os.windows.ws2_32 else os.system;
const hints = os.addrinfo{
.flags = sys.AI_NUMERICSERV,
.family = os.AF_UNSPEC,
@ -724,7 +725,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
};
var res: *os.addrinfo = undefined;
const rc = sys.getaddrinfo(name_c.ptr, std.meta.assumeSentinel(port_c.ptr, 0), &hints, &res);
if (builtin.os.tag == .windows) switch (@intToEnum(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {
if (builtin.target.os.tag == .windows) switch (@intToEnum(os.windows.ws2_32.WinsockError, @intCast(u16, rc))) {
@intToEnum(os.windows.ws2_32.WinsockError, 0) => {},
.WSATRY_AGAIN => return error.TemporaryNameServerFailure,
.WSANO_RECOVERY => return error.NameServerFailure,
@ -782,7 +783,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
return result;
}
if (builtin.os.tag == .linux) {
if (builtin.target.os.tag == .linux) {
const flags = std.c.AI_NUMERICSERV;
const family = os.AF_UNSPEC;
var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);

View File

@ -18,15 +18,16 @@ const Thread = std.Thread;
const a = std.testing.allocator;
const builtin = std.builtin;
const AtomicRmwOp = builtin.AtomicRmwOp;
const AtomicOrder = builtin.AtomicOrder;
const builtin = @import("builtin");
const AtomicRmwOp = std.builtin.AtomicRmwOp;
const AtomicOrder = std.builtin.AtomicOrder;
const native_os = builtin.target.os.tag;
const tmpDir = std.testing.tmpDir;
const Dir = std.fs.Dir;
const ArenaAllocator = std.heap.ArenaAllocator;
test "chdir smoke test" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
// Get current working directory path
var old_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
@ -52,7 +53,7 @@ test "chdir smoke test" {
}
test "open smoke test" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
// TODO verify file attributes using `fstat`
@ -70,7 +71,7 @@ test "open smoke test" {
var file_path: []u8 = undefined;
var fd: os.fd_t = undefined;
const mode: os.mode_t = if (builtin.os.tag == .windows) 0 else 0o666;
const mode: os.mode_t = if (native_os == .windows) 0 else 0o666;
// Create some file using `open`.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
@ -105,7 +106,7 @@ test "open smoke test" {
}
test "openat smoke test" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
// TODO verify file attributes using `fstatat`
@ -113,7 +114,7 @@ test "openat smoke test" {
defer tmp.cleanup();
var fd: os.fd_t = undefined;
const mode: os.mode_t = if (builtin.os.tag == .windows) 0 else 0o666;
const mode: os.mode_t = if (native_os == .windows) 0 else 0o666;
// Create some file using `openat`.
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" {
}
test "symlink with relative paths" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
const cwd = fs.cwd();
cwd.deleteFile("file.txt") catch {};
@ -150,7 +151,7 @@ test "symlink with relative paths" {
// First, try relative paths in cwd
try cwd.writeFile("file.txt", "nonsense");
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
os.windows.CreateSymbolicLink(
cwd.fd,
&[_]u16{ 's', 'y', 'm', 'l', 'i', 'n', 'k', 'e', 'd' },
@ -178,7 +179,7 @@ test "symlink with relative paths" {
}
test "readlink on Windows" {
if (builtin.os.tag != .windows) return error.SkipZigTest;
if (native_os != .windows) return error.SkipZigTest;
try testReadlink("C:\\ProgramData", "C:\\Users\\All Users");
try testReadlink("C:\\Users\\Default", "C:\\Users\\Default User");
@ -192,7 +193,7 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
}
test "link with relative paths" {
if (builtin.os.tag != .linux) return error.SkipZigTest;
if (native_os != .linux) return error.SkipZigTest;
var cwd = fs.cwd();
cwd.deleteFile("example.txt") catch {};
@ -226,7 +227,7 @@ test "link with relative paths" {
}
test "linkat with different directories" {
if (builtin.os.tag != .linux) return error.SkipZigTest;
if (native_os != .linux) return error.SkipZigTest;
var cwd = fs.cwd();
var tmp = tmpDir(.{});
@ -262,7 +263,7 @@ test "linkat with different directories" {
test "fstatat" {
// enable when `fstat` and `fstatat` are implemented on Windows
if (builtin.os.tag == .windows) return error.SkipZigTest;
if (native_os == .windows) return error.SkipZigTest;
var tmp = tmpDir(.{});
defer tmp.cleanup();
@ -277,7 +278,7 @@ test "fstatat" {
defer file.close();
// now repeat but using `fstatat` instead
const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
const flags = if (native_os == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
try expectEqual(stat, statat);
}
@ -290,7 +291,7 @@ test "readlinkat" {
try tmp.dir.writeFile("file.txt", "nonsense");
// create a symbolic link
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
os.windows.CreateSymbolicLink(
tmp.dir.fd,
&[_]u16{ 'l', 'i', 'n', 'k' },
@ -324,7 +325,7 @@ test "std.Thread.getCurrentId" {
thread.wait();
if (Thread.use_pthreads) {
try expect(thread_current_id == thread_id);
} else if (builtin.os.tag == .windows) {
} else if (native_os == .windows) {
try expect(Thread.getCurrentId() != thread_current_id);
} else {
// If the thread completes very quickly, then thread_id can be 0. See the
@ -361,7 +362,7 @@ fn start2(ctx: *i32) u8 {
}
test "cpu count" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
const cpu_count = try Thread.cpuCount();
try expect(cpu_count >= 1);
@ -394,7 +395,7 @@ test "getrandom" {
}
test "getcwd" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .wasi) return error.SkipZigTest;
// at least call it so it gets compiled
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
@ -402,7 +403,7 @@ test "getcwd" {
}
test "sigaltstack" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest;
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
var st: os.stack_t = undefined;
try os.sigaltstack(null, &st);
@ -455,7 +456,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
}
test "dl_iterate_phdr" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi or builtin.os.tag == .macos)
if (native_os == .windows or native_os == .wasi or native_os == .macos)
return error.SkipZigTest;
var counter: usize = 0;
@ -464,7 +465,7 @@ test "dl_iterate_phdr" {
}
test "gethostname" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
if (native_os == .windows or native_os == .wasi)
return error.SkipZigTest;
var buf: [os.HOST_NAME_MAX]u8 = undefined;
@ -473,7 +474,7 @@ test "gethostname" {
}
test "pipe" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
if (native_os == .windows or native_os == .wasi)
return error.SkipZigTest;
var fds = try os.pipe();
@ -492,7 +493,7 @@ test "argsAlloc" {
test "memfd_create" {
// memfd_create is linux specific.
if (builtin.os.tag != .linux) return error.SkipZigTest;
if (native_os != .linux) return error.SkipZigTest;
const fd = std.os.memfd_create("test", 0) catch |err| switch (err) {
// Related: https://github.com/ziglang/zig/issues/4019
error.SystemOutdated => return error.SkipZigTest,
@ -509,7 +510,7 @@ test "memfd_create" {
}
test "mmap" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
if (native_os == .windows or native_os == .wasi)
return error.SkipZigTest;
var tmp = tmpDir(.{});
@ -606,7 +607,7 @@ test "mmap" {
}
test "getenv" {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
} else {
try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
@ -614,7 +615,7 @@ test "getenv" {
}
test "fcntl" {
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
if (native_os == .windows or native_os == .wasi)
return error.SkipZigTest;
var tmp = tmpDir(.{});
@ -646,13 +647,13 @@ test "fcntl" {
}
test "signalfd" {
if (builtin.os.tag != .linux)
if (native_os != .linux)
return error.SkipZigTest;
_ = std.os.signalfd;
}
test "sync" {
if (builtin.os.tag != .linux)
if (native_os != .linux)
return error.SkipZigTest;
var tmp = tmpDir(.{});
@ -670,7 +671,7 @@ test "sync" {
}
test "fsync" {
if (builtin.os.tag != .linux and builtin.os.tag != .windows)
if (native_os != .linux and native_os != .windows)
return error.SkipZigTest;
var tmp = tmpDir(.{});
@ -700,13 +701,13 @@ test "getrlimit and setrlimit" {
}
test "shutdown socket" {
if (builtin.os.tag == .wasi)
if (native_os == .wasi)
return error.SkipZigTest;
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
_ = try std.os.windows.WSAStartup(2, 2);
}
defer {
if (builtin.os.tag == .windows) {
if (native_os == .windows) {
std.os.windows.WSACleanup() catch unreachable;
}
}
@ -721,11 +722,11 @@ test "shutdown socket" {
var signal_test_failed = true;
test "sigaction" {
if (builtin.os.tag == .wasi or builtin.os.tag == .windows)
if (native_os == .wasi or native_os == .windows)
return error.SkipZigTest;
// https://github.com/ziglang/zig/issues/7427
if (builtin.os.tag == .linux and builtin.arch == .i386)
if (native_os == .linux and builtin.target.cpu.arch == .i386)
return error.SkipZigTest;
const S = struct {

View File

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const builtin = std.builtin;
const builtin = @import("builtin");
const std = @import("std.zig");
const math = std.math;
@ -12,7 +12,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
return default;
}
switch (builtin.arch) {
switch (builtin.target.cpu.arch) {
.i386 => {
return asm volatile (
\\ roll $3, %%edi ; roll $13, %%edi