std: change @import("builtin") to std.builtin

This commit is contained in:
Andrew Kelley 2021-04-12 16:43:50 -07:00
parent a4bb7c8bb1
commit 429cd2b5dd
86 changed files with 263 additions and 268 deletions

View file

@ -32,7 +32,7 @@
state: usize = UNSET, state: usize = UNSET,
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const testing = std.testing; const testing = std.testing;
const assert = std.debug.assert; const assert = std.debug.assert;
const StaticResetEvent = std.Thread.StaticResetEvent; const StaticResetEvent = std.Thread.StaticResetEvent;

View file

@ -14,7 +14,7 @@ const trait = meta.trait;
const autoHash = std.hash.autoHash; const autoHash = std.hash.autoHash;
const Wyhash = std.hash.Wyhash; const Wyhash = std.hash.Wyhash;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const builtin = @import("builtin"); const builtin = std.builtin;
const hash_map = @This(); const hash_map = @This();
pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type { pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const assert = std.debug.assert; const assert = std.debug.assert;
const builtin = @import("builtin"); const builtin = std.builtin;
const expect = std.testing.expect; const expect = std.testing.expect;
/// Many reader, many writer, non-allocating, thread-safe /// Many reader, many writer, non-allocating, thread-safe

View file

@ -1409,7 +1409,7 @@ pub const LibExeObjStep = struct {
red_zone: ?bool = null, red_zone: ?bool = null,
subsystem: ?builtin.SubSystem = null, subsystem: ?std.Target.SubSystem = null,
/// Overrides the default stack size /// Overrides the default stack size
stack_size: ?u64 = null, stack_size: ?u64 = null,
@ -1961,7 +1961,7 @@ pub const LibExeObjStep = struct {
}, },
std.builtin.Version => { std.builtin.Version => {
out.print( out.print(
\\pub const {}: @import("builtin").Version = .{{ \\pub const {}: @import("std").builtin.Version = .{{
\\ .major = {d}, \\ .major = {d},
\\ .minor = {d}, \\ .minor = {d},
\\ .patch = {d}, \\ .patch = {d},

View file

@ -3,39 +3,40 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
pub usingnamespace @import("builtin"); const builtin = @import("builtin");
/// Deprecated: use `std.Target`. // These are all deprecated.
pub const Target = std.Target; pub const zig_version = builtin.zig_version;
pub const zig_is_stage2 = builtin.zig_is_stage2;
/// Deprecated: use `std.Target.Os`. pub const output_mode = builtin.output_mode;
pub const Os = std.Target.Os; pub const link_mode = builtin.link_mode;
pub const is_test = builtin.is_test;
/// Deprecated: use `std.Target.Cpu.Arch`. pub const single_threaded = builtin.single_threaded;
pub const Arch = std.Target.Cpu.Arch; pub const abi = builtin.abi;
pub const cpu = builtin.cpu;
/// Deprecated: use `std.Target.Abi`. pub const os = builtin.os;
pub const Abi = std.Target.Abi; pub const target = builtin.target;
pub const object_format = builtin.object_format;
/// Deprecated: use `std.Target.ObjectFormat`. pub const mode = builtin.mode;
pub const ObjectFormat = std.Target.ObjectFormat; pub const link_libc = builtin.link_libc;
pub const link_libcpp = builtin.link_libcpp;
/// Deprecated: use `std.Target.SubSystem`. pub const have_error_return_tracing = builtin.have_error_return_tracing;
pub const SubSystem = std.Target.SubSystem; pub const valgrind_support = builtin.valgrind_support;
pub const position_independent_code = builtin.position_independent_code;
/// Deprecated: use `std.Target.Cpu`. pub const position_independent_executable = builtin.position_independent_executable;
pub const Cpu = std.Target.Cpu; pub const strip_debug_info = builtin.strip_debug_info;
pub const code_model = builtin.code_model;
/// `explicit_subsystem` is missing when the subsystem is automatically detected, /// `explicit_subsystem` is missing when the subsystem is automatically detected,
/// so Zig standard library has the subsystem detection logic here. This should generally be /// so Zig standard library has the subsystem detection logic here. This should generally be
/// used rather than `explicit_subsystem`. /// used rather than `explicit_subsystem`.
/// On non-Windows targets, this is `null`. /// On non-Windows targets, this is `null`.
pub const subsystem: ?SubSystem = blk: { pub const subsystem: ?std.Target.SubSystem = blk: {
if (@hasDecl(@This(), "explicit_subsystem")) break :blk explicit_subsystem; if (@hasDecl(builtin, "explicit_subsystem")) break :blk explicit_subsystem;
switch (os.tag) { switch (os.tag) {
.windows => { .windows => {
if (is_test) { if (is_test) {
break :blk SubSystem.Console; break :blk std.Target.SubSystem.Console;
} }
if (@hasDecl(root, "main") or if (@hasDecl(root, "main") or
@hasDecl(root, "WinMain") or @hasDecl(root, "WinMain") or
@ -43,9 +44,9 @@ pub const subsystem: ?SubSystem = blk: {
@hasDecl(root, "WinMainCRTStartup") or @hasDecl(root, "WinMainCRTStartup") or
@hasDecl(root, "wWinMainCRTStartup")) @hasDecl(root, "wWinMainCRTStartup"))
{ {
break :blk SubSystem.Windows; break :blk std.Target.SubSystem.Windows;
} else { } else {
break :blk SubSystem.Console; break :blk std.Target.SubSystem.Console;
} }
}, },
else => break :blk null, else => break :blk null,

View file

@ -3,12 +3,14 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const abi = std.Target.current.abi;
const arch = std.Target.current.cpu.arch;
const os_tag = std.Target.current.os.tag;
usingnamespace std.c; usingnamespace std.c;
pub const _errno = switch (builtin.abi) { pub const _errno = switch (abi) {
.android => struct { .android => struct {
extern "c" var __errno: c_int; extern "c" var __errno: c_int;
fn getErrno() *c_int { fn getErrno() *c_int {
@ -124,7 +126,7 @@ pub const pthread_mutex_t = extern struct {
pub const pthread_cond_t = extern struct { pub const pthread_cond_t = extern struct {
size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T, size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
}; };
pub const pthread_rwlock_t = switch (std.builtin.abi) { pub const pthread_rwlock_t = switch (abi) {
.android => switch (@sizeOf(usize)) { .android => switch (@sizeOf(usize)) {
4 => extern struct { 4 => extern struct {
lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER, lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
@ -155,11 +157,11 @@ pub const sem_t = extern struct {
}; };
const __SIZEOF_PTHREAD_COND_T = 48; const __SIZEOF_PTHREAD_COND_T = 48;
const __SIZEOF_PTHREAD_MUTEX_T = if (builtin.os.tag == .fuchsia) 40 else switch (builtin.abi) { const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
.musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.arch) { .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {
.aarch64 => 48, .aarch64 => 48,
.x86_64 => if (builtin.abi == .gnux32) 40 else 32, .x86_64 => if (abi == .gnux32) 40 else 32,
.mips64, .powerpc64, .powerpc64le, .sparcv9 => 40, .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
else => if (@sizeOf(usize) == 8) 40 else 24, else => if (@sizeOf(usize) == 8) 40 else 24,
}, },

View file

@ -15,7 +15,7 @@ const windows = os.windows;
const mem = std.mem; const mem = std.mem;
const debug = std.debug; const debug = std.debug;
const BufMap = std.BufMap; const BufMap = std.BufMap;
const builtin = @import("builtin"); const builtin = std.builtin;
const Os = builtin.Os; const Os = builtin.Os;
const TailQueue = std.TailQueue; const TailQueue = std.TailQueue;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std.zig"); const std = @import("std.zig");
const io = std.io; const io = std.io;
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const debug = std.debug; const debug = std.debug;
const mem = std.mem; const mem = std.mem;
const testing = std.testing; const testing = std.testing;

View file

@ -21,6 +21,9 @@ const root = @import("root");
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const File = std.fs.File; const File = std.fs.File;
const windows = std.os.windows; const windows = std.os.windows;
const native_arch = std.Target.current.cpu.arch;
const native_os = std.Target.current.os.tag;
const native_endian = native_arch.endian();
pub const runtime_safety = switch (builtin.mode) { pub const runtime_safety = switch (builtin.mode) {
.Debug, .ReleaseSafe => true, .Debug, .ReleaseSafe => true,
@ -90,7 +93,7 @@ pub fn detectTTYConfig() TTY.Config {
const stderr_file = io.getStdErr(); const stderr_file = io.getStdErr();
if (stderr_file.supportsAnsiEscapeCodes()) { if (stderr_file.supportsAnsiEscapeCodes()) {
return .escape_codes; return .escape_codes;
} else if (builtin.os.tag == .windows and stderr_file.isTty()) { } else if (native_os == .windows and stderr_file.isTty()) {
return .windows_api; return .windows_api;
} else { } else {
return .no_color; return .no_color;
@ -148,7 +151,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
/// chopping off the irrelevant frames and shifting so that the returned addresses pointer /// chopping off the irrelevant frames and shifting so that the returned addresses pointer
/// equals the passed in addresses pointer. /// equals the passed in addresses pointer.
pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void { pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
if (builtin.os.tag == .windows) { if (native_os == .windows) {
const addrs = stack_trace.instruction_addresses; const addrs = stack_trace.instruction_addresses;
const u32_addrs_len = @intCast(u32, addrs.len); const u32_addrs_len = @intCast(u32, addrs.len);
const first_addr = first_address orelse { const first_addr = first_address orelse {
@ -226,7 +229,7 @@ pub fn assert(ok: bool) void {
pub fn panic(comptime format: []const u8, args: anytype) noreturn { pub fn panic(comptime format: []const u8, args: anytype) noreturn {
@setCold(true); @setCold(true);
// TODO: remove conditional once wasi / LLVM defines __builtin_return_address // TODO: remove conditional once wasi / LLVM defines __builtin_return_address
const first_trace_addr = if (builtin.os.tag == .wasi) null else @returnAddress(); const first_trace_addr = if (native_os == .wasi) null else @returnAddress();
panicExtra(null, first_trace_addr, format, args); panicExtra(null, first_trace_addr, format, args);
} }
@ -343,25 +346,25 @@ pub const StackIterator = struct {
} }
// Offset of the saved BP wrt the frame pointer. // Offset of the saved BP wrt the frame pointer.
const fp_offset = if (builtin.arch.isRISCV()) const fp_offset = if (native_arch.isRISCV())
// On RISC-V the frame pointer points to the top of the saved register // On RISC-V the frame pointer points to the top of the saved register
// area, on pretty much every other architecture it points to the stack // area, on pretty much every other architecture it points to the stack
// slot where the previous frame pointer is saved. // slot where the previous frame pointer is saved.
2 * @sizeOf(usize) 2 * @sizeOf(usize)
else if (builtin.arch.isSPARC()) else if (native_arch.isSPARC())
// On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS. // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
14 * @sizeOf(usize) 14 * @sizeOf(usize)
else else
0; 0;
const fp_bias = if (builtin.arch.isSPARC()) const fp_bias = if (native_arch.isSPARC())
// On SPARC frame pointers are biased by a constant. // On SPARC frame pointers are biased by a constant.
2047 2047
else else
0; 0;
// Positive offset of the saved PC wrt the frame pointer. // Positive offset of the saved PC wrt the frame pointer.
const pc_offset = if (builtin.arch == .powerpc64le) const pc_offset = if (native_arch == .powerpc64le)
2 * @sizeOf(usize) 2 * @sizeOf(usize)
else else
@sizeOf(usize); @sizeOf(usize);
@ -380,7 +383,7 @@ pub const StackIterator = struct {
} }
fn next_internal(self: *StackIterator) ?usize { fn next_internal(self: *StackIterator) ?usize {
const fp = if (builtin.arch.isSPARC()) const fp = if (native_arch.isSPARC())
// On SPARC the offset is positive. (!) // On SPARC the offset is positive. (!)
math.add(usize, self.fp, fp_offset) catch return null math.add(usize, self.fp, fp_offset) catch return null
else else
@ -416,7 +419,7 @@ pub fn writeCurrentStackTrace(
tty_config: TTY.Config, tty_config: TTY.Config,
start_addr: ?usize, start_addr: ?usize,
) !void { ) !void {
if (builtin.os.tag == .windows) { if (native_os == .windows) {
return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr); return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr);
} }
var it = StackIterator.init(start_addr, null); var it = StackIterator.init(start_addr, null);
@ -473,7 +476,7 @@ pub const TTY = struct {
.Dim => out_stream.writeAll(DIM) catch return, .Dim => out_stream.writeAll(DIM) catch return,
.Reset => out_stream.writeAll(RESET) catch return, .Reset => out_stream.writeAll(RESET) catch return,
}, },
.windows_api => if (builtin.os.tag == .windows) { .windows_api => if (native_os == .windows) {
const stderr_file = io.getStdErr(); const stderr_file = io.getStdErr();
const S = struct { const S = struct {
var attrs: windows.WORD = undefined; var attrs: windows.WORD = undefined;
@ -675,7 +678,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) { if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
return root.os.debug.openSelfDebugInfo(allocator); return root.os.debug.openSelfDebugInfo(allocator);
} }
switch (builtin.os.tag) { switch (native_os) {
.linux, .linux,
.freebsd, .freebsd,
.netbsd, .netbsd,
@ -888,7 +891,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
elf.ELFDATA2MSB => .Big, elf.ELFDATA2MSB => .Big,
else => return error.InvalidElfEndian, else => return error.InvalidElfEndian,
}; };
assert(endian == std.builtin.endian); // this is our own debug info assert(endian == native_endian); // this is our own debug info
const shoff = hdr.e_shoff; const shoff = hdr.e_shoff;
const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx); const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
@ -1123,9 +1126,9 @@ pub const DebugInfo = struct {
pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo { pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
if (comptime std.Target.current.isDarwin()) { if (comptime std.Target.current.isDarwin()) {
return self.lookupModuleDyld(address); return self.lookupModuleDyld(address);
} else if (builtin.os.tag == .windows) { } else if (native_os == .windows) {
return self.lookupModuleWin32(address); return self.lookupModuleWin32(address);
} else if (builtin.os.tag == .haiku) { } else if (native_os == .haiku) {
return self.lookupModuleHaiku(address); return self.lookupModuleHaiku(address);
} else { } else {
return self.lookupModuleDl(address); return self.lookupModuleDl(address);
@ -1353,7 +1356,7 @@ const SymbolInfo = struct {
} }
}; };
pub const ModuleDebugInfo = switch (builtin.os.tag) { pub const ModuleDebugInfo = switch (native_os) {
.macos, .ios, .watchos, .tvos => struct { .macos, .ios, .watchos, .tvos => struct {
base_address: usize, base_address: usize,
mapped_memory: []const u8, mapped_memory: []const u8,
@ -1720,7 +1723,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
} }
/// Whether or not the current target can print useful debug information when a segfault occurs. /// Whether or not the current target can print useful debug information when a segfault occurs.
pub const have_segfault_handling_support = switch (builtin.os.tag) { pub const have_segfault_handling_support = switch (native_os) {
.linux, .netbsd => true, .linux, .netbsd => true,
.windows => true, .windows => true,
.freebsd, .openbsd => @hasDecl(os, "ucontext_t"), .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
@ -1744,7 +1747,7 @@ pub fn attachSegfaultHandler() void {
if (!have_segfault_handling_support) { if (!have_segfault_handling_support) {
@compileError("segfault handler not supported for this target"); @compileError("segfault handler not supported for this target");
} }
if (builtin.os.tag == .windows) { if (native_os == .windows) {
windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows); windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows);
return; return;
} }
@ -1760,7 +1763,7 @@ pub fn attachSegfaultHandler() void {
} }
fn resetSegfaultHandler() void { fn resetSegfaultHandler() void {
if (builtin.os.tag == .windows) { if (native_os == .windows) {
if (windows_segfault_handle) |handle| { if (windows_segfault_handle) |handle| {
assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0); assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
windows_segfault_handle = null; windows_segfault_handle = null;
@ -1783,7 +1786,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
// and the resulting segfault will crash the process rather than continually dump stack traces. // and the resulting segfault will crash the process rather than continually dump stack traces.
resetSegfaultHandler(); resetSegfaultHandler();
const addr = switch (builtin.os.tag) { const addr = switch (native_os) {
.linux => @ptrToInt(info.fields.sigfault.addr), .linux => @ptrToInt(info.fields.sigfault.addr),
.freebsd => @ptrToInt(info.addr), .freebsd => @ptrToInt(info.addr),
.netbsd => @ptrToInt(info.info.reason.fault.addr), .netbsd => @ptrToInt(info.info.reason.fault.addr),
@ -1802,7 +1805,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
} catch os.abort(); } catch os.abort();
} }
switch (builtin.arch) { switch (native_arch) {
.i386 => { .i386 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]); const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);
@ -1811,13 +1814,13 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
}, },
.x86_64 => { .x86_64 => {
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = switch (builtin.os.tag) { const ip = switch (native_os) {
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]), .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
.freebsd => @intCast(usize, ctx.mcontext.rip), .freebsd => @intCast(usize, ctx.mcontext.rip),
.openbsd => @intCast(usize, ctx.sc_rip), .openbsd => @intCast(usize, ctx.sc_rip),
else => unreachable, else => unreachable,
}; };
const bp = switch (builtin.os.tag) { const bp = switch (native_os) {
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]), .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
.openbsd => @intCast(usize, ctx.sc_rbp), .openbsd => @intCast(usize, ctx.sc_rbp),
.freebsd => @intCast(usize, ctx.mcontext.rbp), .freebsd => @intCast(usize, ctx.mcontext.rbp),

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const debug = std.debug; const debug = std.debug;
const fs = std.fs; const fs = std.fs;
const io = std.io; const io = std.io;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std.zig"); const std = @import("std.zig");
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const Loop = std.event.Loop; const Loop = std.event.Loop;

View file

@ -6,7 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const builtin = @import("builtin"); const builtin = std.builtin;
const Lock = std.event.Lock; const Lock = std.event.Lock;
/// This is a value that starts out unavailable, until resolve() is called /// This is a value that starts out unavailable, until resolve() is called

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const Lock = std.event.Lock; const Lock = std.event.Lock;
const testing = std.testing; const testing = std.testing;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const root = @import("root"); const root = @import("root");
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const Loop = std.event.Loop; const Loop = std.event.Loop;
/// A WaitGroup keeps track and waits for a group of async tasks to finish. /// A WaitGroup keeps track and waits for a group of async tasks to finish.

View file

@ -9,7 +9,7 @@ const assert = std.debug.assert;
const mem = std.mem; const mem = std.mem;
const unicode = std.unicode; const unicode = std.unicode;
const meta = std.meta; const meta = std.meta;
const builtin = @import("builtin"); const builtin = std.builtin;
const errol = @import("fmt/errol.zig"); const errol = @import("fmt/errol.zig");
const lossyCast = std.math.lossyCast; const lossyCast = std.math.lossyCast;
const expectFmt = std.testing.expectFmt; const expectFmt = std.testing.expectFmt;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std.zig"); const std = @import("std.zig");
const os = std.os; const os = std.os;
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const os = std.os; const os = std.os;
const io = std.io; const io = std.io;
const mem = std.mem; const mem = std.mem;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const unicode = std.unicode; const unicode = std.unicode;
const mem = std.mem; const mem = std.mem;
const fs = std.fs; const fs = std.fs;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("../std.zig"); const std = @import("../std.zig");
const debug = std.debug; const debug = std.debug;
const assert = debug.assert; const assert = debug.assert;

View file

@ -167,7 +167,7 @@ pub const PreopenList = struct {
}; };
test "extracting WASI preopens" { test "extracting WASI preopens" {
if (@import("builtin").os.tag != .wasi) return error.SkipZigTest; if (std.builtin.os.tag != .wasi) return error.SkipZigTest;
var preopens = PreopenList.init(std.testing.allocator); var preopens = PreopenList.init(std.testing.allocator);
defer preopens.deinit(); defer preopens.deinit();

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
const event = std.event; const event = std.event;
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;

View file

@ -4,10 +4,10 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert; const assert = std.debug.assert;
const mem = std.mem; const mem = std.mem;
const meta = std.meta; const meta = std.meta;
const builtin = std.builtin;
/// Describes how pointer types should be hashed. /// Describes how pointer types should be hashed.
pub const HashStrategy = enum { pub const HashStrategy = enum {
@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {
test "typeContainsSlice" { test "typeContainsSlice" {
comptime { comptime {
testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo))); testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));
testing.expect(typeContainsSlice([]const u8)); testing.expect(typeContainsSlice([]const u8));
testing.expect(!typeContainsSlice(u8)); testing.expect(!typeContainsSlice(u8));
@ -400,7 +400,7 @@ test "testHash union" {
test "testHash vector" { test "testHash vector" {
// Disabled because of #3317 // Disabled because of #3317
if (@import("builtin").arch == .mipsel or @import("builtin").arch == .mips) return error.SkipZigTest; if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) return error.SkipZigTest;
const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 }; const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 }; const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };

View file

@ -5,7 +5,7 @@
// and substantial portions of the software. // and substantial portions of the software.
// zig run benchmark.zig --release-fast --override-lib-dir .. // zig run benchmark.zig --release-fast --override-lib-dir ..
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std"); const std = @import("std");
const time = std.time; const time = std.time;
const Timer = time.Timer; const Timer = time.Timer;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 { fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 {
// ptr + offset doesn't work at comptime so we need this instead. // ptr + offset doesn't work at comptime so we need this instead.

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
const testing = std.testing; const testing = std.testing;
const default_seed: u32 = 0xc70f6907; const default_seed: u32 = 0xc70f6907;

View file

@ -4,7 +4,6 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin");
const assert = debug.assert; const assert = debug.assert;
const autoHash = std.hash.autoHash; const autoHash = std.hash.autoHash;
const debug = std.debug; const debug = std.debug;

View file

@ -10,7 +10,7 @@ const assert = debug.assert;
const testing = std.testing; const testing = std.testing;
const mem = std.mem; const mem = std.mem;
const os = std.os; const os = std.os;
const builtin = @import("builtin"); const builtin = std.builtin;
const c = std.c; const c = std.c;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const root = @import("root"); const root = @import("root");
const c = std.c; const c = std.c;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/acoshf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/acoshf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/acosh.c // https://git.musl-libc.org/cgit/musl/tree/src/math/acosh.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c // https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -10,7 +10,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/complex/catan.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/catan.c
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const builtin = @import("builtin");
const testing = std.testing; const testing = std.testing;
const math = std.math; const math = std.math;
const cmath = math.complex; const cmath = math.complex;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccoshf.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/ccoshf.c
// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccosh.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/ccosh.c
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const testing = std.testing; const testing = std.testing;
const math = std.math; const math = std.math;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexpf.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/cexpf.c
// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexp.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/cexp.c
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const testing = std.testing; const testing = std.testing;
const math = std.math; const math = std.math;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinhf.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/csinhf.c
// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinh.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/csinh.c
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const testing = std.testing; const testing = std.testing;
const math = std.math; const math = std.math;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanhf.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanhf.c
// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanh.c // https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanh.c
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const testing = std.testing; const testing = std.testing;
const math = std.math; const math = std.math;

View file

@ -8,7 +8,6 @@
// //
// https://golang.org/src/math/sin.go // https://golang.org/src/math/sin.go
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/coshf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/coshf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/cosh.c // https://git.musl-libc.org/cgit/musl/tree/src/math/cosh.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expo2 = @import("expo2.zig").expo2; const expo2 = @import("expo2.zig").expo2;

View file

@ -11,7 +11,6 @@
// TODO: Updated recently. // TODO: Updated recently.
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c // https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
const builtin = @import("builtin");
const expect = std.testing.expect; const expect = std.testing.expect;
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/log1pf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/log1pf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/log1p.c // https://git.musl-libc.org/cgit/musl/tree/src/math/log1p.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -8,7 +8,6 @@
// //
// https://golang.org/src/math/pow.go // https://golang.org/src/math/pow.go
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -8,7 +8,6 @@
// //
// https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/src/libcore/num/mod.rs#L3423 // https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/src/libcore/num/mod.rs#L3423
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const assert = std.debug.assert; const assert = std.debug.assert;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c // https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
const builtin = @import("builtin");
const expect = std.testing.expect; const expect = std.testing.expect;
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;

View file

@ -8,7 +8,6 @@
// //
// https://golang.org/src/math/sin.go // https://golang.org/src/math/sin.go
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/sinhf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/sinhf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/sinh.c // https://git.musl-libc.org/cgit/musl/tree/src/math/sinh.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -6,8 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;
const builtin = @import("builtin"); const TypeId = std.builtin.TypeId;
const TypeId = builtin.TypeId;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
/// Returns the square root of x. /// Returns the square root of x.

View file

@ -8,7 +8,6 @@
// //
// https://golang.org/src/math/tan.go // https://golang.org/src/math/tan.go
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -9,7 +9,6 @@
// https://git.musl-libc.org/cgit/musl/tree/src/math/tanhf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/tanhf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/tanh.c // https://git.musl-libc.org/cgit/musl/tree/src/math/tanh.c
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;

View file

@ -7,17 +7,18 @@ const std = @import("std.zig");
const debug = std.debug; const debug = std.debug;
const assert = debug.assert; const assert = debug.assert;
const math = std.math; const math = std.math;
const builtin = std.builtin;
const mem = @This(); const mem = @This();
const meta = std.meta; const meta = std.meta;
const trait = meta.trait; const trait = meta.trait;
const testing = std.testing; const testing = std.testing;
const Endian = std.builtin.Endian;
const native_endian = std.Target.current.cpu.arch.endian();
/// Compile time known minimum page size. /// Compile time known minimum page size.
/// https://github.com/ziglang/zig/issues/4082 /// https://github.com/ziglang/zig/issues/4082
pub const page_size = switch (builtin.arch) { pub const page_size = switch (std.Target.current.cpu.arch) {
.wasm32, .wasm64 => 64 * 1024, .wasm32, .wasm64 => 64 * 1024,
.aarch64 => switch (builtin.os.tag) { .aarch64 => switch (std.Target.current.os.tag) {
.macos, .ios, .watchos, .tvos => 16 * 1024, .macos, .ios, .watchos, .tvos => 16 * 1024,
else => 4 * 1024, else => 4 * 1024,
}, },
@ -1042,7 +1043,7 @@ test "mem.containsAtLeast" {
/// Reads an integer from memory with size equal to bytes.len. /// Reads an integer from memory with size equal to bytes.len.
/// T specifies the return type, which must be large enough to store /// T specifies the return type, which must be large enough to store
/// the result. /// the result.
pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType { pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType {
var result: ReturnType = 0; var result: ReturnType = 0;
switch (endian) { switch (endian) {
.Big => { .Big => {
@ -1077,12 +1078,12 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).In
return @byteSwap(T, readIntNative(T, bytes)); return @byteSwap(T, readIntNative(T, bytes));
} }
pub const readIntLittle = switch (builtin.endian) { pub const readIntLittle = switch (native_endian) {
.Little => readIntNative, .Little => readIntNative,
.Big => readIntForeign, .Big => readIntForeign,
}; };
pub const readIntBig = switch (builtin.endian) { pub const readIntBig = switch (native_endian) {
.Little => readIntForeign, .Little => readIntForeign,
.Big => readIntNative, .Big => readIntNative,
}; };
@ -1106,12 +1107,12 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
return @byteSwap(T, readIntSliceNative(T, bytes)); return @byteSwap(T, readIntSliceNative(T, bytes));
} }
pub const readIntSliceLittle = switch (builtin.endian) { pub const readIntSliceLittle = switch (native_endian) {
.Little => readIntSliceNative, .Little => readIntSliceNative,
.Big => readIntSliceForeign, .Big => readIntSliceForeign,
}; };
pub const readIntSliceBig = switch (builtin.endian) { pub const readIntSliceBig = switch (native_endian) {
.Little => readIntSliceForeign, .Little => readIntSliceForeign,
.Big => readIntSliceNative, .Big => readIntSliceNative,
}; };
@ -1119,8 +1120,8 @@ pub const readIntSliceBig = switch (builtin.endian) {
/// Reads an integer from memory with bit count specified by T. /// Reads an integer from memory with bit count specified by T.
/// The bit count of T must be evenly divisible by 8. /// The bit count of T must be evenly divisible by 8.
/// This function cannot fail and cannot cause undefined behavior. /// This function cannot fail and cannot cause undefined behavior.
pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: builtin.Endian) T { pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T {
if (endian == builtin.endian) { if (endian == native_endian) {
return readIntNative(T, bytes); return readIntNative(T, bytes);
} else { } else {
return readIntForeign(T, bytes); return readIntForeign(T, bytes);
@ -1130,7 +1131,7 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits,
/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0 /// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
/// and ignores extra bytes. /// and ignores extra bytes.
/// The bit count of T must be evenly divisible by 8. /// The bit count of T must be evenly divisible by 8.
pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: builtin.Endian) T { pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: Endian) T {
const n = @divExact(@typeInfo(T).Int.bits, 8); const n = @divExact(@typeInfo(T).Int.bits, 8);
assert(bytes.len >= n); assert(bytes.len >= n);
return readInt(T, bytes[0..n], endian); return readInt(T, bytes[0..n], endian);
@ -1188,12 +1189,12 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits,
writeIntNative(T, buf, @byteSwap(T, value)); writeIntNative(T, buf, @byteSwap(T, value));
} }
pub const writeIntLittle = switch (builtin.endian) { pub const writeIntLittle = switch (native_endian) {
.Little => writeIntNative, .Little => writeIntNative,
.Big => writeIntForeign, .Big => writeIntForeign,
}; };
pub const writeIntBig = switch (builtin.endian) { pub const writeIntBig = switch (native_endian) {
.Little => writeIntForeign, .Little => writeIntForeign,
.Big => writeIntNative, .Big => writeIntNative,
}; };
@ -1201,8 +1202,8 @@ pub const writeIntBig = switch (builtin.endian) {
/// Writes an integer to memory, storing it in twos-complement. /// Writes an integer to memory, storing it in twos-complement.
/// This function always succeeds, has defined behavior for all inputs, but /// This function always succeeds, has defined behavior for all inputs, but
/// the integer bit width must be divisible by 8. /// the integer bit width must be divisible by 8.
pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: builtin.Endian) void { pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
if (endian == builtin.endian) { if (endian == native_endian) {
return writeIntNative(T, buffer, value); return writeIntNative(T, buffer, value);
} else { } else {
return writeIntForeign(T, buffer, value); return writeIntForeign(T, buffer, value);
@ -1252,12 +1253,12 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
} }
} }
pub const writeIntSliceNative = switch (builtin.endian) { pub const writeIntSliceNative = switch (native_endian) {
.Little => writeIntSliceLittle, .Little => writeIntSliceLittle,
.Big => writeIntSliceBig, .Big => writeIntSliceBig,
}; };
pub const writeIntSliceForeign = switch (builtin.endian) { pub const writeIntSliceForeign = switch (native_endian) {
.Little => writeIntSliceBig, .Little => writeIntSliceBig,
.Big => writeIntSliceLittle, .Big => writeIntSliceLittle,
}; };
@ -1268,7 +1269,7 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
/// Any extra bytes in buffer not part of the integer are set to zero, with /// Any extra bytes in buffer not part of the integer are set to zero, with
/// respect to endianness. To avoid the branch to check for extra buffer bytes, /// respect to endianness. To avoid the branch to check for extra buffer bytes,
/// use writeInt instead. /// use writeInt instead.
pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void { pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void {
comptime assert(@typeInfo(T).Int.bits % 8 == 0); comptime assert(@typeInfo(T).Int.bits % 8 == 0);
return switch (endian) { return switch (endian) {
.Little => writeIntSliceLittle(T, buffer, value), .Little => writeIntSliceLittle(T, buffer, value),
@ -1678,10 +1679,10 @@ fn testReadIntImpl() void {
0x56, 0x56,
0x78, 0x78,
}; };
testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678); testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
testing.expect(readIntBig(u32, &bytes) == 0x12345678); testing.expect(readIntBig(u32, &bytes) == 0x12345678);
testing.expect(readIntBig(i32, &bytes) == 0x12345678); testing.expect(readIntBig(i32, &bytes) == 0x12345678);
testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412); testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
testing.expect(readIntLittle(u32, &bytes) == 0x78563412); testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
testing.expect(readIntLittle(i32, &bytes) == 0x78563412); testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
} }
@ -1692,7 +1693,7 @@ fn testReadIntImpl() void {
0x12, 0x12,
0x34, 0x34,
}; };
const answer = readInt(u32, &buf, builtin.Endian.Big); const answer = readInt(u32, &buf, Endian.Big);
testing.expect(answer == 0x00001234); testing.expect(answer == 0x00001234);
} }
{ {
@ -1702,7 +1703,7 @@ fn testReadIntImpl() void {
0x00, 0x00,
0x00, 0x00,
}; };
const answer = readInt(u32, &buf, builtin.Endian.Little); const answer = readInt(u32, &buf, Endian.Little);
testing.expect(answer == 0x00003412); testing.expect(answer == 0x00003412);
} }
{ {
@ -1724,19 +1725,19 @@ test "writeIntSlice" {
fn testWriteIntImpl() void { fn testWriteIntImpl() void {
var bytes: [8]u8 = undefined; var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big); writeIntSlice(u0, bytes[0..], 0, Endian.Big);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
})); }));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little); writeIntSlice(u0, bytes[0..], 0, Endian.Little);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
})); }));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big); writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x12, 0x12,
0x34, 0x34,
@ -1748,7 +1749,7 @@ fn testWriteIntImpl() void {
0xBE, 0xBE,
})); }));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little); writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x12, 0x12,
0x34, 0x34,
@ -1760,7 +1761,7 @@ fn testWriteIntImpl() void {
0xBE, 0xBE,
})); }));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big); writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00,
0x00, 0x00,
@ -1772,7 +1773,7 @@ fn testWriteIntImpl() void {
0x78, 0x78,
})); }));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little); writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x12, 0x12,
0x34, 0x34,
@ -1784,7 +1785,7 @@ fn testWriteIntImpl() void {
0x00, 0x00,
})); }));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big); writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00,
0x00, 0x00,
@ -1796,7 +1797,7 @@ fn testWriteIntImpl() void {
0x34, 0x34,
})); }));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little); writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
testing.expect(eql(u8, &bytes, &[_]u8{ testing.expect(eql(u8, &bytes, &[_]u8{
0x34, 0x34,
0x12, 0x12,
@ -1949,7 +1950,7 @@ test "replaceOwned" {
/// Converts a little-endian integer to host endianness. /// Converts a little-endian integer to host endianness.
pub fn littleToNative(comptime T: type, x: T) T { pub fn littleToNative(comptime T: type, x: T) T {
return switch (builtin.endian) { return switch (native_endian) {
.Little => x, .Little => x,
.Big => @byteSwap(T, x), .Big => @byteSwap(T, x),
}; };
@ -1957,14 +1958,14 @@ pub fn littleToNative(comptime T: type, x: T) T {
/// Converts a big-endian integer to host endianness. /// Converts a big-endian integer to host endianness.
pub fn bigToNative(comptime T: type, x: T) T { pub fn bigToNative(comptime T: type, x: T) T {
return switch (builtin.endian) { return switch (native_endian) {
.Little => @byteSwap(T, x), .Little => @byteSwap(T, x),
.Big => x, .Big => x,
}; };
} }
/// Converts an integer from specified endianness to host endianness. /// Converts an integer from specified endianness to host endianness.
pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T { pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T {
return switch (endianness_of_x) { return switch (endianness_of_x) {
.Little => littleToNative(T, x), .Little => littleToNative(T, x),
.Big => bigToNative(T, x), .Big => bigToNative(T, x),
@ -1972,7 +1973,7 @@ pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
} }
/// Converts an integer which has host endianness to the desired endianness. /// Converts an integer which has host endianness to the desired endianness.
pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T { pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T {
return switch (desired_endianness) { return switch (desired_endianness) {
.Little => nativeToLittle(T, x), .Little => nativeToLittle(T, x),
.Big => nativeToBig(T, x), .Big => nativeToBig(T, x),
@ -1981,7 +1982,7 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
/// Converts an integer which has host endianness to little endian. /// Converts an integer which has host endianness to little endian.
pub fn nativeToLittle(comptime T: type, x: T) T { pub fn nativeToLittle(comptime T: type, x: T) T {
return switch (builtin.endian) { return switch (native_endian) {
.Little => x, .Little => x,
.Big => @byteSwap(T, x), .Big => @byteSwap(T, x),
}; };
@ -1989,13 +1990,13 @@ pub fn nativeToLittle(comptime T: type, x: T) T {
/// Converts an integer which has host endianness to big endian. /// Converts an integer which has host endianness to big endian.
pub fn nativeToBig(comptime T: type, x: T) T { pub fn nativeToBig(comptime T: type, x: T) T {
return switch (builtin.endian) { return switch (native_endian) {
.Little => @byteSwap(T, x), .Little => @byteSwap(T, x),
.Big => x, .Big => x,
}; };
} }
fn CopyPtrAttrs(comptime source: type, comptime size: builtin.TypeInfo.Pointer.Size, comptime child: type) type { fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Pointer.Size, comptime child: type) type {
const info = @typeInfo(source).Pointer; const info = @typeInfo(source).Pointer;
return @Type(.{ return @Type(.{
.Pointer = .{ .Pointer = .{
@ -2027,7 +2028,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
test "asBytes" { test "asBytes" {
const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef = @as(u32, 0xDEADBEEF);
const deadbeef_bytes = switch (builtin.endian) { const deadbeef_bytes = switch (native_endian) {
.Big => "\xDE\xAD\xBE\xEF", .Big => "\xDE\xAD\xBE\xEF",
.Little => "\xEF\xBE\xAD\xDE", .Little => "\xEF\xBE\xAD\xDE",
}; };
@ -2080,13 +2081,13 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
test "toBytes" { test "toBytes" {
var my_bytes = toBytes(@as(u32, 0x12345678)); var my_bytes = toBytes(@as(u32, 0x12345678));
switch (builtin.endian) { switch (native_endian) {
.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
} }
my_bytes[0] = '\x99'; my_bytes[0] = '\x99';
switch (builtin.endian) { switch (native_endian) {
.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
} }
@ -2113,14 +2114,14 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,
test "bytesAsValue" { test "bytesAsValue" {
const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef = @as(u32, 0xDEADBEEF);
const deadbeef_bytes = switch (builtin.endian) { const deadbeef_bytes = switch (native_endian) {
.Big => "\xDE\xAD\xBE\xEF", .Big => "\xDE\xAD\xBE\xEF",
.Little => "\xEF\xBE\xAD\xDE", .Little => "\xEF\xBE\xAD\xDE",
}; };
testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
var codeface_bytes: [4]u8 = switch (builtin.endian) { var codeface_bytes: [4]u8 = switch (native_endian) {
.Big => "\xC0\xDE\xFA\xCE", .Big => "\xC0\xDE\xFA\xCE",
.Little => "\xCE\xFA\xDE\xC0", .Little => "\xCE\xFA\xDE\xC0",
}.*; }.*;
@ -2168,7 +2169,7 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T {
return bytesAsValue(T, bytes).*; return bytesAsValue(T, bytes).*;
} }
test "bytesToValue" { test "bytesToValue" {
const deadbeef_bytes = switch (builtin.endian) { const deadbeef_bytes = switch (native_endian) {
.Big => "\xDE\xAD\xBE\xEF", .Big => "\xDE\xAD\xBE\xEF",
.Little => "\xEF\xBE\xAD\xDE", .Little => "\xEF\xBE\xAD\xDE",
}; };
@ -2297,7 +2298,7 @@ test "sliceAsBytes" {
const bytes = [_]u16{ 0xDEAD, 0xBEEF }; const bytes = [_]u16{ 0xDEAD, 0xBEEF };
const slice = sliceAsBytes(bytes[0..]); const slice = sliceAsBytes(bytes[0..]);
testing.expect(slice.len == 4); testing.expect(slice.len == 4);
testing.expect(eql(u8, slice, switch (builtin.endian) { testing.expect(eql(u8, slice, switch (native_endian) {
.Big => "\xDE\xAD\xBE\xEF", .Big => "\xDE\xAD\xBE\xEF",
.Little => "\xAD\xDE\xEF\xBE", .Little => "\xAD\xDE\xEF\xBE",
})); }));
@ -2319,7 +2320,7 @@ test "sliceAsBytes packed struct at runtime and comptime" {
var foo: Foo = undefined; var foo: Foo = undefined;
var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]); var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
slice[0] = 0x13; slice[0] = 0x13;
switch (builtin.endian) { switch (native_endian) {
.Big => { .Big => {
testing.expect(foo.a == 0x1); testing.expect(foo.a == 0x1);
testing.expect(foo.b == 0x3); testing.expect(foo.b == 0x3);

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const debug = std.debug; const debug = std.debug;
const mem = std.mem; const mem = std.mem;
const math = std.math; const math = std.math;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const net = @This(); const net = @This();
const mem = std.mem; const mem = std.mem;

View file

@ -21,7 +21,7 @@
const root = @import("root"); const root = @import("root");
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const math = std.math; const math = std.math;
const mem = std.mem; const mem = std.mem;

View file

@ -3,17 +3,17 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const arch = std.Target.current.cpu.arch;
usingnamespace @import("../bits.zig"); usingnamespace @import("../bits.zig");
pub usingnamespace switch (builtin.arch) { pub usingnamespace switch (arch) {
.mips, .mipsel => @import("linux/errno-mips.zig"), .mips, .mipsel => @import("linux/errno-mips.zig"),
else => @import("linux/errno-generic.zig"), else => @import("linux/errno-generic.zig"),
}; };
pub usingnamespace switch (builtin.arch) { pub usingnamespace switch (arch) {
.i386 => @import("linux/i386.zig"), .i386 => @import("linux/i386.zig"),
.x86_64 => @import("linux/x86_64.zig"), .x86_64 => @import("linux/x86_64.zig"),
.aarch64 => @import("linux/arm64.zig"), .aarch64 => @import("linux/arm64.zig"),
@ -30,9 +30,9 @@ pub usingnamespace @import("linux/netlink.zig");
pub usingnamespace @import("linux/prctl.zig"); pub usingnamespace @import("linux/prctl.zig");
pub usingnamespace @import("linux/securebits.zig"); pub usingnamespace @import("linux/securebits.zig");
const is_mips = builtin.arch.isMIPS(); const is_mips = arch.isMIPS();
const is_ppc64 = builtin.arch.isPPC64(); const is_ppc64 = arch.isPPC64();
const is_sparc = builtin.arch.isSPARC(); const is_sparc = arch.isSPARC();
pub const pid_t = i32; pub const pid_t = i32;
pub const fd_t = i32; pub const fd_t = i32;
@ -134,7 +134,7 @@ pub const PROT_WRITE = 0x2;
pub const PROT_EXEC = 0x4; pub const PROT_EXEC = 0x4;
/// page may be used for atomic ops /// page may be used for atomic ops
pub const PROT_SEM = switch (builtin.arch) { pub const PROT_SEM = switch (arch) {
// TODO: also xtensa // TODO: also xtensa
.mips, .mipsel, .mips64, .mips64el => 0x10, .mips, .mipsel, .mips64, .mips64el => 0x10,
else => 0x8, else => 0x8,
@ -1004,7 +1004,7 @@ pub const sigset_t = [1024 / 32]u32;
pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len; pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
pub const k_sigaction = switch (builtin.arch) { pub const k_sigaction = switch (arch) {
.mips, .mipsel => extern struct { .mips, .mipsel => extern struct {
flags: c_uint, flags: c_uint,
handler: ?fn (c_int) callconv(.C) void, handler: ?fn (c_int) callconv(.C) void,
@ -1121,7 +1121,7 @@ pub const epoll_data = extern union {
// On x86_64 the structure is packed so that it matches the definition of its // On x86_64 the structure is packed so that it matches the definition of its
// 32bit counterpart // 32bit counterpart
pub const epoll_event = switch (builtin.arch) { pub const epoll_event = switch (arch) {
.x86_64 => packed struct { .x86_64 => packed struct {
events: u32, events: u32,
data: epoll_data, data: epoll_data,
@ -1288,12 +1288,12 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) //#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) //#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
pub const MINSIGSTKSZ = switch (builtin.arch) { pub const MINSIGSTKSZ = switch (arch) {
.i386, .x86_64, .arm, .mipsel => 2048, .i386, .x86_64, .arm, .mipsel => 2048,
.aarch64 => 5120, .aarch64 => 5120,
else => @compileError("MINSIGSTKSZ not defined for this architecture"), else => @compileError("MINSIGSTKSZ not defined for this architecture"),
}; };
pub const SIGSTKSZ = switch (builtin.arch) { pub const SIGSTKSZ = switch (arch) {
.i386, .x86_64, .arm, .mipsel => 8192, .i386, .x86_64, .arm, .mipsel => 8192,
.aarch64 => 16384, .aarch64 => 16384,
else => @compileError("SIGSTKSZ not defined for this architecture"), else => @compileError("SIGSTKSZ not defined for this architecture"),
@ -2053,7 +2053,7 @@ pub const B3000000 = 0o0010015;
pub const B3500000 = 0o0010016; pub const B3500000 = 0o0010016;
pub const B4000000 = 0o0010017; pub const B4000000 = 0o0010017;
pub usingnamespace switch (builtin.arch) { pub usingnamespace switch (arch) {
.powerpc, .powerpc64, .powerpc64le => struct { .powerpc, .powerpc64, .powerpc64le => struct {
pub const VINTR = 0; pub const VINTR = 0;
pub const VQUIT = 1; pub const VQUIT = 1;

View file

@ -3,7 +3,6 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin");
const std = @import("../std.zig"); const std = @import("../std.zig");
pub usingnamespace std.c; pub usingnamespace std.c;
pub usingnamespace @import("bits.zig"); pub usingnamespace @import("bits.zig");

View file

@ -11,14 +11,15 @@
// provide `rename` when only the `renameat` syscall exists. // provide `rename` when only the `renameat` syscall exists.
// * Does not support POSIX thread cancellation. // * Does not support POSIX thread cancellation.
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const elf = std.elf; const elf = std.elf;
const vdso = @import("linux/vdso.zig"); const vdso = @import("linux/vdso.zig");
const dl = @import("../dynamic_library.zig"); const dl = @import("../dynamic_library.zig");
const native_arch = std.Target.current.cpu.arch;
const native_endian = native_arch.endian();
pub usingnamespace switch (builtin.arch) { pub usingnamespace switch (native_arch) {
.i386 => @import("linux/i386.zig"), .i386 => @import("linux/i386.zig"),
.x86_64 => @import("linux/x86_64.zig"), .x86_64 => @import("linux/x86_64.zig"),
.aarch64 => @import("linux/arm64.zig"), .aarch64 => @import("linux/arm64.zig"),
@ -58,7 +59,7 @@ const require_aligned_register_pair =
// Split a 64bit value into a {LSB,MSB} pair. // Split a 64bit value into a {LSB,MSB} pair.
fn splitValue64(val: u64) [2]u32 { fn splitValue64(val: u64) [2]u32 {
switch (builtin.endian) { switch (native_endian) {
.Little => return [2]u32{ .Little => return [2]u32{
@truncate(u32, val), @truncate(u32, val),
@truncate(u32, val >> 32), @truncate(u32, val >> 32),
@ -113,7 +114,7 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:
} }
pub fn fork() usize { pub fn fork() usize {
if (comptime builtin.arch.isSPARC()) { if (comptime native_arch.isSPARC()) {
return syscall_fork(); return syscall_fork();
} else if (@hasField(SYS, "fork")) { } else if (@hasField(SYS, "fork")) {
return syscall0(.fork); return syscall0(.fork);
@ -431,7 +432,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
} }
pub fn pipe(fd: *[2]i32) usize { pub fn pipe(fd: *[2]i32) usize {
if (comptime (builtin.arch.isMIPS() or builtin.arch.isSPARC())) { if (comptime (native_arch.isMIPS() or native_arch.isSPARC())) {
return syscall_pipe(fd); return syscall_pipe(fd);
} else if (@hasField(SYS, "pipe")) { } else if (@hasField(SYS, "pipe")) {
return syscall1(.pipe, @ptrToInt(fd)); return syscall1(.pipe, @ptrToInt(fd));
@ -912,7 +913,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0; const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0;
const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0; const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0;
const result = switch (builtin.arch) { const result = switch (native_arch) {
// The sparc version of rt_sigaction needs the restorer function to be passed as an argument too. // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.
.sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size), .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size), else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
@ -944,42 +945,42 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
} }
pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
} }
return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
} }
pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
} }
return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
} }
pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol }); return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });
} }
return syscall3(.socket, domain, socket_type, protocol); return syscall3(.socket, domain, socket_type, protocol);
} }
pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) }); return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });
} }
return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
} }
pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) }); return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });
} }
return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
} }
pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize { pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
} }
return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
@ -1026,49 +1027,49 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
} }
pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len }); return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });
} }
return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
} }
pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
} }
return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
} }
pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) }); return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });
} }
return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
} }
pub fn shutdown(fd: i32, how: i32) usize { pub fn shutdown(fd: i32, how: i32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) }); return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });
} }
return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
} }
pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) }); return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });
} }
return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
} }
pub fn listen(fd: i32, backlog: u32) usize { pub fn listen(fd: i32, backlog: u32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog }); return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });
} }
return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog); return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
} }
pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) }); return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });
} }
return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
@ -1095,21 +1096,21 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
} }
pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) }); return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });
} }
return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
} }
pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize { pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 }); return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 });
} }
return accept4(fd, addr, len, 0); return accept4(fd, addr, len, 0);
} }
pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize { pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
if (builtin.arch == .i386) { if (native_arch == .i386) {
return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags }); return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });
} }
return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
@ -1388,7 +1389,7 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
} }
test { test {
if (builtin.os.tag == .linux) { if (std.Target.current.os.tag == .linux) {
_ = @import("linux/test.zig"); _ = @import("linux/test.zig");
} }
} }

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
const elf = std.elf; const elf = std.elf;
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const R_AMD64_RELATIVE = 8; const R_AMD64_RELATIVE = 8;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const linux = std.os.linux; const linux = std.os.linux;
const mem = std.mem; const mem = std.mem;
const elf = std.elf; const elf = std.elf;

View file

@ -4,12 +4,12 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = std.builtin;
const os = std.os; const os = std.os;
const mem = std.mem; const mem = std.mem;
const elf = std.elf; const elf = std.elf;
const math = std.math; const math = std.math;
const assert = std.debug.assert; const assert = std.debug.assert;
const native_arch = std.Target.current.cpu.arch;
// This file implements the two TLS variants [1] used by ELF-based systems. // This file implements the two TLS variants [1] used by ELF-based systems.
// //
@ -52,14 +52,14 @@ const TLSVariant = enum {
VariantII, VariantII,
}; };
const tls_variant = switch (builtin.arch) { const tls_variant = switch (native_arch) {
.arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => TLSVariant.VariantI, .arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => TLSVariant.VariantI,
.x86_64, .i386, .sparcv9 => TLSVariant.VariantII, .x86_64, .i386, .sparcv9 => TLSVariant.VariantII,
else => @compileError("undefined tls_variant for this architecture"), else => @compileError("undefined tls_variant for this architecture"),
}; };
// Controls how many bytes are reserved for the Thread Control Block // Controls how many bytes are reserved for the Thread Control Block
const tls_tcb_size = switch (builtin.arch) { const tls_tcb_size = switch (native_arch) {
// ARM EABI mandates enough space for two pointers: the first one points to // ARM EABI mandates enough space for two pointers: the first one points to
// the DTV while the second one is unspecified but reserved // the DTV while the second one is unspecified but reserved
.arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize), .arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize),
@ -68,7 +68,7 @@ const tls_tcb_size = switch (builtin.arch) {
}; };
// Controls if the TP points to the end of the TCB instead of its beginning // Controls if the TP points to the end of the TCB instead of its beginning
const tls_tp_points_past_tcb = switch (builtin.arch) { const tls_tp_points_past_tcb = switch (native_arch) {
.riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true,
else => false, else => false,
}; };
@ -76,12 +76,12 @@ const tls_tp_points_past_tcb = switch (builtin.arch) {
// Some architectures add some offset to the tp and dtv addresses in order to // Some architectures add some offset to the tp and dtv addresses in order to
// make the generated code more efficient // make the generated code more efficient
const tls_tp_offset = switch (builtin.arch) { const tls_tp_offset = switch (native_arch) {
.mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x7000, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x7000,
else => 0, else => 0,
}; };
const tls_dtv_offset = switch (builtin.arch) { const tls_dtv_offset = switch (native_arch) {
.mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x8000, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x8000,
.riscv32, .riscv64 => 0x800, .riscv32, .riscv64 => 0x800,
else => 0, else => 0,
@ -114,7 +114,7 @@ const TLSImage = struct {
pub var tls_image: TLSImage = undefined; pub var tls_image: TLSImage = undefined;
pub fn setThreadPointer(addr: usize) void { pub fn setThreadPointer(addr: usize) void {
switch (builtin.arch) { switch (native_arch) {
.i386 => { .i386 => {
var user_desc = std.os.linux.user_desc{ var user_desc = std.os.linux.user_desc{
.entry_number = tls_image.gdt_entry_number, .entry_number = tls_image.gdt_entry_number,
@ -228,7 +228,7 @@ fn initTLS() void {
// ARMv6 targets (and earlier) have no support for TLS in hardware // ARMv6 targets (and earlier) have no support for TLS in hardware
// FIXME: Elide the check for targets >= ARMv7 when the target feature API // FIXME: Elide the check for targets >= ARMv7 when the target feature API
// becomes less verbose (and more usable). // becomes less verbose (and more usable).
if (comptime builtin.arch.isARM()) { if (comptime native_arch.isARM()) {
if (at_hwcap & std.os.linux.HWCAP_TLS == 0) { if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {
// FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls
// For the time being use a simple abort instead of a @panic call to // For the time being use a simple abort instead of a @panic call to

View file

@ -18,7 +18,7 @@ const Thread = std.Thread;
const a = std.testing.allocator; const a = std.testing.allocator;
const builtin = @import("builtin"); const builtin = std.builtin;
const AtomicRmwOp = builtin.AtomicRmwOp; const AtomicRmwOp = builtin.AtomicRmwOp;
const AtomicOrder = builtin.AtomicOrder; const AtomicOrder = builtin.AtomicOrder;
const tmpDir = std.testing.tmpDir; const tmpDir = std.testing.tmpDir;

View file

@ -9,7 +9,7 @@
// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept // * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
// slices as well as APIs which accept null-terminated UTF16LE byte buffers. // slices as well as APIs which accept null-terminated UTF16LE byte buffers.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("../std.zig"); const std = @import("../std.zig");
const mem = std.mem; const mem = std.mem;
const assert = std.debug.assert; const assert = std.debug.assert;

View file

@ -5,10 +5,10 @@
// and substantial portions of the software. // and substantial portions of the software.
// Platform-dependent types and values that are used along with OS-specific APIs. // Platform-dependent types and values that are used along with OS-specific APIs.
const builtin = @import("builtin");
const std = @import("../../std.zig"); const std = @import("../../std.zig");
const assert = std.debug.assert; const assert = std.debug.assert;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const arch = std.Target.current.cpu.arch;
pub usingnamespace @import("win32error.zig"); pub usingnamespace @import("win32error.zig");
pub usingnamespace @import("ntstatus.zig"); pub usingnamespace @import("ntstatus.zig");
@ -24,7 +24,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
/// The standard error device. Initially, this is the active console screen buffer, CONOUT$. /// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
pub const WINAPI: builtin.CallingConvention = if (builtin.arch == .i386) pub const WINAPI: std.builtin.CallingConvention = if (arch == .i386)
.Stdcall .Stdcall
else else
.C; .C;
@ -937,7 +937,7 @@ pub const EXCEPTION_RECORD = extern struct {
ExceptionInformation: [15]usize, ExceptionInformation: [15]usize,
}; };
pub usingnamespace switch (builtin.arch) { pub usingnamespace switch (arch) {
.i386 => struct { .i386 => struct {
pub const FLOATING_SAVE_AREA = extern struct { pub const FLOATING_SAVE_AREA = extern struct {
ControlWord: DWORD, ControlWord: DWORD,

View file

@ -5,7 +5,7 @@
// and substantial portions of the software. // and substantial portions of the software.
usingnamespace @import("bits.zig"); usingnamespace @import("bits.zig");
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const windows = @import("../windows.zig"); const windows = @import("../windows.zig");
const unexpectedError = windows.unexpectedError; const unexpectedError = windows.unexpectedError;

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
const debug = std.debug; const debug = std.debug;
const testing = std.testing; const testing = std.testing;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std.zig"); const std = @import("std.zig");
const io = std.io; const io = std.io;
const math = std.math; const math = std.math;

View file

@ -13,7 +13,7 @@
//! TODO(tiehuis): Benchmark these against other reference implementations. //! TODO(tiehuis): Benchmark these against other reference implementations.
const std = @import("std.zig"); const std = @import("std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;

View file

@ -8,7 +8,7 @@ const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const mem = std.mem; const mem = std.mem;
const math = std.math; const math = std.math;
const builtin = @import("builtin"); const builtin = std.builtin;
pub fn binarySearch( pub fn binarySearch(
comptime T: type, comptime T: type,

View file

@ -10,19 +10,22 @@
// such as memcpy, memset, and some math functions. // such as memcpy, memset, and some math functions.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = std.builtin;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
const isNan = std.math.isNan; const isNan = std.math.isNan;
const native_arch = std.Target.current.cpu.arch;
const native_abi = std.Target.current.abi;
const native_os = std.Target.current.os.tag;
const is_wasm = switch (builtin.arch) { const is_wasm = switch (native_arch) {
.wasm32, .wasm64 => true, .wasm32, .wasm64 => true,
else => false, else => false,
}; };
const is_msvc = switch (builtin.abi) { const is_msvc = switch (native_abi) {
.msvc => true, .msvc => true,
else => false, else => false,
}; };
const is_freestanding = switch (builtin.os.tag) { const is_freestanding = switch (native_os) {
.freestanding => true, .freestanding => true,
else => false, else => false,
}; };
@ -174,7 +177,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
@setCold(true); @setCold(true);
std.debug.panic("{s}", .{msg}); std.debug.panic("{s}", .{msg});
} }
if (builtin.os.tag != .freestanding and builtin.os.tag != .other) { if (native_os != .freestanding and native_os != .other) {
std.os.abort(); std.os.abort();
} }
while (true) {} while (true) {}
@ -275,7 +278,7 @@ test "test_bcmp" {
} }
comptime { comptime {
if (builtin.os.tag == .linux) { if (native_os == .linux) {
@export(clone, .{ .name = "clone" }); @export(clone, .{ .name = "clone" });
} }
} }
@ -284,7 +287,7 @@ comptime {
// it causes a segfault in release mode. this is a workaround of calling it // it causes a segfault in release mode. this is a workaround of calling it
// across .o file boundaries. fix comptime @ptrCast of nakedcc functions. // across .o file boundaries. fix comptime @ptrCast of nakedcc functions.
fn clone() callconv(.Naked) void { fn clone() callconv(.Naked) void {
switch (builtin.arch) { switch (native_arch) {
.i386 => { .i386 => {
// __clone(func, stack, flags, arg, ptid, tls, ctid) // __clone(func, stack, flags, arg, ptid, tls, ctid)
// +8, +12, +16, +20, +24, +28, +32 // +8, +12, +16, +20, +24, +28, +32

View file

@ -6,15 +6,18 @@
const std = @import("std"); const std = @import("std");
const builtin = std.builtin; const builtin = std.builtin;
const is_test = builtin.is_test; const is_test = builtin.is_test;
const os_tag = std.Target.current.os.tag;
const arch = std.Target.current.cpu.arch;
const abi = std.Target.current.abi;
const is_gnu = std.Target.current.abi.isGnu(); const is_gnu = abi.isGnu();
const is_mingw = builtin.os.tag == .windows and is_gnu; const is_mingw = os_tag == .windows and is_gnu;
comptime { comptime {
const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak; const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;
const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong; const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
switch (builtin.arch) { switch (arch) {
.i386, .i386,
.x86_64, .x86_64,
=> @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{
@ -167,11 +170,11 @@ comptime {
@export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage }); @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
if (builtin.link_libc and builtin.os.tag == .openbsd) { if (builtin.link_libc and os_tag == .openbsd) {
@export(@import("compiler_rt/emutls.zig").__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage }); @export(@import("compiler_rt/emutls.zig").__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
} }
if ((builtin.arch.isARM() or builtin.arch.isThumb()) and !is_test) { if ((arch.isARM() or arch.isThumb()) and !is_test) {
@export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
@export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
@export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
@ -202,7 +205,7 @@ comptime {
@export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });
@export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });
if (builtin.os.tag == .linux) { if (os_tag == .linux) {
@export(@import("compiler_rt/arm.zig").__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage }); @export(@import("compiler_rt/arm.zig").__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
} }
@ -269,7 +272,7 @@ comptime {
@export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage }); @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
} }
if (builtin.arch == .i386 and builtin.abi == .msvc) { if (arch == .i386 and abi == .msvc) {
// Don't let LLVM apply the stdcall name mangling on those MSVC builtins // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
@export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage }); @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });
@export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage }); @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });
@ -277,7 +280,7 @@ comptime {
@export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage }); @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
} }
if (builtin.arch.isSPARC()) { if (arch.isSPARC()) {
// SPARC systems use a different naming scheme // SPARC systems use a different naming scheme
@export(@import("compiler_rt/sparc.zig")._Qp_add, .{ .name = "_Qp_add", .linkage = linkage }); @export(@import("compiler_rt/sparc.zig")._Qp_add, .{ .name = "_Qp_add", .linkage = linkage });
@export(@import("compiler_rt/sparc.zig")._Qp_div, .{ .name = "_Qp_div", .linkage = linkage }); @export(@import("compiler_rt/sparc.zig")._Qp_div, .{ .name = "_Qp_div", .linkage = linkage });
@ -334,7 +337,7 @@ comptime {
@export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage }); @export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
} }
switch (builtin.arch) { switch (arch) {
.i386 => { .i386 => {
@export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage }); @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });
@export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage }); @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });

View file

@ -5,6 +5,7 @@
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = std.builtin; const builtin = std.builtin;
const arch = std.Target.current.cpu.arch;
const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak; const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
@ -13,7 +14,7 @@ const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak
// Some architectures support atomic load/stores but no CAS, but we ignore this // Some architectures support atomic load/stores but no CAS, but we ignore this
// detail to keep the export logic clean and because we need some kind of CAS to // detail to keep the export logic clean and because we need some kind of CAS to
// implement the spinlocks. // implement the spinlocks.
const supports_atomic_ops = switch (builtin.arch) { const supports_atomic_ops = switch (arch) {
.msp430, .avr => false, .msp430, .avr => false,
.arm, .armeb, .thumb, .thumbeb => .arm, .armeb, .thumb, .thumbeb =>
// The ARM v6m ISA has no ldrex/strex and so it's impossible to do CAS // The ARM v6m ISA has no ldrex/strex and so it's impossible to do CAS
@ -27,7 +28,7 @@ const supports_atomic_ops = switch (builtin.arch) {
// The size (in bytes) of the biggest object that the architecture can // The size (in bytes) of the biggest object that the architecture can
// load/store atomically. // load/store atomically.
// Objects bigger than this threshold require the use of a lock. // Objects bigger than this threshold require the use of a lock.
const largest_atomic_size = switch (builtin.arch) { const largest_atomic_size = switch (arch) {
// XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b // XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b
// and set this parameter accordingly. // and set this parameter accordingly.
else => @sizeOf(usize), else => @sizeOf(usize),

View file

@ -3,14 +3,16 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const std = @import("std");
const is_test = std.builtin.is_test;
const native_endian = std.Target.current.cpu.arch.endian();
// Ported from // Ported from
// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c // https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
const dwords = extern union { const dwords = extern union {
all: i64, all: i64,
s: switch (builtin.endian) { s: switch (native_endian) {
.Little => extern struct { .Little => extern struct {
low: u32, low: u32,
high: u32, high: u32,
@ -23,7 +25,7 @@ const dwords = extern union {
}; };
fn __muldsi3(a: u32, b: u32) i64 { fn __muldsi3(a: u32, b: u32) i64 {
@setRuntimeSafety(builtin.is_test); @setRuntimeSafety(is_test);
const bits_in_word_2 = @sizeOf(i32) * 8 / 2; const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
const lower_mask = (~@as(u32, 0)) >> bits_in_word_2; const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
@ -45,7 +47,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
} }
pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 { pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
@setRuntimeSafety(builtin.is_test); @setRuntimeSafety(is_test);
const x = dwords{ .all = a }; const x = dwords{ .all = a };
const y = dwords{ .all = b }; const y = dwords{ .all = b };

View file

@ -3,15 +3,17 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin");
const compiler_rt = @import("../compiler_rt.zig"); const compiler_rt = @import("../compiler_rt.zig");
const std = @import("std");
const is_test = std.builtin.is_test;
const native_endian = std.Target.current.cpu.arch.endian();
// Ported from git@github.com:llvm-project/llvm-project-20170507.git // Ported from git@github.com:llvm-project/llvm-project-20170507.git
// ae684fad6d34858c014c94da69c15e7774a633c3 // ae684fad6d34858c014c94da69c15e7774a633c3
// 2018-08-13 // 2018-08-13
pub fn __multi3(a: i128, b: i128) callconv(.C) i128 { pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
@setRuntimeSafety(builtin.is_test); @setRuntimeSafety(is_test);
const x = twords{ .all = a }; const x = twords{ .all = a };
const y = twords{ .all = b }; const y = twords{ .all = b };
var r = twords{ .all = __mulddi3(x.s.low, y.s.low) }; var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };
@ -50,7 +52,7 @@ const twords = extern union {
all: i128, all: i128,
s: S, s: S,
const S = if (builtin.endian == .Little) const S = if (native_endian == .Little)
struct { struct {
low: u64, low: u64,
high: u64, high: u64,

View file

@ -4,8 +4,8 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("std"); const std = @import("std");
const builtin = std.builtin;
const Log2Int = std.math.Log2Int; const Log2Int = std.math.Log2Int;
const native_endian = std.Target.current.cpu.arch.endian();
fn Dwords(comptime T: type, comptime signed_half: bool) type { fn Dwords(comptime T: type, comptime signed_half: bool) type {
return extern union { return extern union {
@ -15,7 +15,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {
pub const HalfT = if (signed_half) HalfTS else HalfTU; pub const HalfT = if (signed_half) HalfTS else HalfTU;
all: T, all: T,
s: if (builtin.endian == .Little) s: if (native_endian == .Little)
struct { low: HalfT, high: HalfT } struct { low: HalfT, high: HalfT }
else else
struct { high: HalfT, low: HalfT }, struct { high: HalfT, low: HalfT },

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const native_arch = @import("std").Target.current.cpu.arch;
// Zig's own stack-probe routine (available only on x86 and x86_64) // Zig's own stack-probe routine (available only on x86 and x86_64)
pub fn zig_probe_stack() callconv(.Naked) void { pub fn zig_probe_stack() callconv(.Naked) void {
@ -13,7 +13,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
// invalid so let's update it on the go, otherwise we'll get a segfault // invalid so let's update it on the go, otherwise we'll get a segfault
// instead of triggering the stack growth. // instead of triggering the stack growth.
switch (builtin.arch) { switch (native_arch) {
.x86_64 => { .x86_64 => {
// %rax = probe length, %rsp = stack pointer // %rax = probe length, %rsp = stack pointer
asm volatile ( asm volatile (
@ -65,7 +65,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
fn win_probe_stack_only() void { fn win_probe_stack_only() void {
@setRuntimeSafety(false); @setRuntimeSafety(false);
switch (builtin.arch) { switch (native_arch) {
.x86_64 => { .x86_64 => {
asm volatile ( asm volatile (
\\ push %%rcx \\ push %%rcx
@ -117,7 +117,7 @@ fn win_probe_stack_only() void {
fn win_probe_stack_adjust_sp() void { fn win_probe_stack_adjust_sp() void {
@setRuntimeSafety(false); @setRuntimeSafety(false);
switch (builtin.arch) { switch (native_arch) {
.x86_64 => { .x86_64 => {
asm volatile ( asm volatile (
\\ push %%rcx \\ push %%rcx
@ -191,7 +191,7 @@ pub fn _chkstk() callconv(.Naked) void {
} }
pub fn __chkstk() callconv(.Naked) void { pub fn __chkstk() callconv(.Naked) void {
@setRuntimeSafety(false); @setRuntimeSafety(false);
switch (builtin.arch) { switch (native_arch) {
.i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}), .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),
.x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}), .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),
else => unreachable, else => unreachable,

View file

@ -5,8 +5,9 @@
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = @import("builtin");
const is_test = builtin.is_test; const is_test = builtin.is_test;
const native_endian = @import("std").Target.current.cpu.arch.endian();
const low = switch (builtin.endian) { const low = switch (native_endian) {
.Big => 1, .Big => 1,
.Little => 0, .Little => 0,
}; };

View file

@ -11,10 +11,12 @@ const builtin = @import("builtin");
const assert = std.debug.assert; const assert = std.debug.assert;
const uefi = std.os.uefi; const uefi = std.os.uefi;
const tlcsprng = @import("crypto/tlcsprng.zig"); const tlcsprng = @import("crypto/tlcsprng.zig");
const native_arch = std.Target.current.cpu.arch;
const native_os = std.Target.current.os.tag;
var argc_argv_ptr: [*]usize = undefined; var argc_argv_ptr: [*]usize = undefined;
const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start"; const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start";
comptime { comptime {
// The self-hosted compiler is not fully capable of handling all of this start.zig file. // The self-hosted compiler is not fully capable of handling all of this start.zig file.
@ -23,9 +25,7 @@ comptime {
if (builtin.zig_is_stage2) { if (builtin.zig_is_stage2) {
if (builtin.output_mode == .Exe) { if (builtin.output_mode == .Exe) {
if (builtin.link_libc or builtin.object_format == .c) { if (builtin.link_libc or builtin.object_format == .c) {
if (!@hasDecl(root, "main")) { @export(main2, "main");
@export(main2, "main");
}
} else { } else {
if (!@hasDecl(root, "_start")) { if (!@hasDecl(root, "_start")) {
@export(_start2, "_start"); @export(_start2, "_start");
@ -34,7 +34,7 @@ comptime {
} }
} else { } else {
if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
if (builtin.os.tag == .windows and !@hasDecl(root, "_DllMainCRTStartup")) { if (native_os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
@export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" }); @export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" });
} }
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
@ -42,7 +42,7 @@ comptime {
if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) { if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export(main, .{ .name = "main", .linkage = .Weak }); @export(main, .{ .name = "main", .linkage = .Weak });
} }
} else if (builtin.os.tag == .windows) { } else if (native_os == .windows) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup")) !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
{ {
@ -56,11 +56,11 @@ comptime {
{ {
@export(wWinMainCRTStartup, .{ .name = "wWinMainCRTStartup" }); @export(wWinMainCRTStartup, .{ .name = "wWinMainCRTStartup" });
} }
} else if (builtin.os.tag == .uefi) { } else if (native_os == .uefi) {
if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
} else if (builtin.arch.isWasm() and builtin.os.tag == .freestanding) { } else if (native_arch.isWasm() and native_os == .freestanding) {
if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
} else if (builtin.os.tag != .other and builtin.os.tag != .freestanding) { } else if (native_os != .other and native_os != .freestanding) {
if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
} }
} }
@ -80,7 +80,7 @@ fn _start2() callconv(.Naked) noreturn {
} }
fn exit2(code: u8) noreturn { fn exit2(code: u8) noreturn {
switch (builtin.arch) { switch (native_arch) {
.x86_64 => { .x86_64 => {
asm volatile ("syscall" asm volatile ("syscall"
: :
@ -157,13 +157,13 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv
} }
fn _start() callconv(.Naked) noreturn { fn _start() callconv(.Naked) noreturn {
if (builtin.os.tag == .wasi) { if (native_os == .wasi) {
// This is marked inline because for some reason LLVM in release mode fails to inline it, // This is marked inline because for some reason LLVM in release mode fails to inline it,
// and we want fewer call frames in stack traces. // and we want fewer call frames in stack traces.
std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})); std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{}));
} }
switch (builtin.arch) { switch (native_arch) {
.x86_64 => { .x86_64 => {
argc_argv_ptr = asm volatile ( argc_argv_ptr = asm volatile (
\\ xor %%rbp, %%rbp \\ xor %%rbp, %%rbp
@ -273,7 +273,7 @@ fn posixCallMainAndExit() noreturn {
while (envp_optional[envp_count]) |_| : (envp_count += 1) {} while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count]; const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
if (builtin.os.tag == .linux) { if (native_os == .linux) {
// Find the beginning of the auxiliary vector // Find the beginning of the auxiliary vector
const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1)); const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));
std.os.linux.elf_aux_maybe = auxv; std.os.linux.elf_aux_maybe = auxv;

View file

@ -1225,11 +1225,7 @@ pub const Target = struct {
} }
}; };
pub const current = Target{ pub const current = builtin.target;
.cpu = builtin.cpu,
.os = builtin.os,
.abi = builtin.abi,
};
pub const stack_align = 16; pub const stack_align = 16;

View file

@ -309,7 +309,7 @@ pub const TmpDir = struct {
}; };
fn getCwdOrWasiPreopen() std.fs.Dir { fn getCwdOrWasiPreopen() std.fs.Dir {
if (@import("builtin").os.tag == .wasi) { if (std.builtin.os.tag == .wasi) {
var preopens = std.fs.wasi.PreopenList.init(allocator); var preopens = std.fs.wasi.PreopenList.init(allocator);
defer preopens.deinit(); defer preopens.deinit();
preopens.populate() catch preopens.populate() catch

View file

@ -4,7 +4,7 @@
// The MIT license requires this copyright notice to be included in all copies // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const std = @import("./std.zig"); const std = @import("./std.zig");
const builtin = @import("builtin"); const builtin = std.builtin;
const assert = std.debug.assert; const assert = std.debug.assert;
const testing = std.testing; const testing = std.testing;
const mem = std.mem; const mem = std.mem;

View file

@ -3,7 +3,7 @@
// This file is part of [zig](https://ziglang.org/), which is MIT licensed. // 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 // The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software. // and substantial portions of the software.
const builtin = @import("builtin"); const builtin = std.builtin;
const std = @import("std.zig"); const std = @import("std.zig");
const math = std.math; const math = std.math;

View file

@ -14,6 +14,7 @@ const process = std.process;
const Target = std.Target; const Target = std.Target;
const CrossTarget = std.zig.CrossTarget; const CrossTarget = std.zig.CrossTarget;
const macos = @import("system/macos.zig"); const macos = @import("system/macos.zig");
const native_endian = std.Target.current.cpu.arch.endian();
pub const windows = @import("system/windows.zig"); pub const windows = @import("system/windows.zig");
pub const getSDKPath = macos.getSDKPath; pub const getSDKPath = macos.getSDKPath;
@ -603,7 +604,7 @@ pub const NativeTargetInfo = struct {
elf.ELFDATA2MSB => .Big, elf.ELFDATA2MSB => .Big,
else => return error.InvalidElfEndian, else => return error.InvalidElfEndian,
}; };
const need_bswap = elf_endian != std.builtin.endian; const need_bswap = elf_endian != native_endian;
if (hdr32.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; if (hdr32.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
const is_64 = switch (hdr32.e_ident[elf.EI_CLASS]) { const is_64 = switch (hdr32.e_ident[elf.EI_CLASS]) {