authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-12 16:43:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-15 19:06:39-07:00
log429cd2b5dd27bec15a4a3351114ce1bcd12d8d01
tree6f0dda8c4a63d7944046bf9a580e20ba304de814
parenta4bb7c8bb17a4ac692401946df6b9f4cc3e5b1b2

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


86 files changed, 264 insertions(+), 269 deletions(-)

lib/std/Thread/AutoResetEvent.zig+1-1
......@@ -32,7 +32,7 @@
3232state: usize = UNSET,
3333
3434const std = @import("../std.zig");
35const builtin = @import("builtin");
35const builtin = std.builtin;
3636const testing = std.testing;
3737const assert = std.debug.assert;
3838const StaticResetEvent = std.Thread.StaticResetEvent;
lib/std/array_hash_map.zig+1-1
......@@ -14,7 +14,7 @@ const trait = meta.trait;
1414const autoHash = std.hash.autoHash;
1515const Wyhash = std.hash.Wyhash;
1616const Allocator = mem.Allocator;
17const builtin = @import("builtin");
17const builtin = std.builtin;
1818const hash_map = @This();
1919
2020pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {
lib/std/atomic/queue.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const expect = std.testing.expect;
1010
lib/std/atomic/stack.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const assert = std.debug.assert;
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const expect = std.testing.expect;
99
1010/// Many reader, many writer, non-allocating, thread-safe
lib/std/build.zig+2-2
......@@ -1409,7 +1409,7 @@ pub const LibExeObjStep = struct {
14091409
14101410 red_zone: ?bool = null,
14111411
1412 subsystem: ?builtin.SubSystem = null,
1412 subsystem: ?std.Target.SubSystem = null,
14131413
14141414 /// Overrides the default stack size
14151415 stack_size: ?u64 = null,
......@@ -1961,7 +1961,7 @@ pub const LibExeObjStep = struct {
19611961 },
19621962 std.builtin.Version => {
19631963 out.print(
1964 \\pub const {}: @import("builtin").Version = .{{
1964 \\pub const {}: @import("std").builtin.Version = .{{
19651965 \\ .major = {d},
19661966 \\ .minor = {d},
19671967 \\ .patch = {d},
lib/std/builtin.zig+28-27
......@@ -3,39 +3,40 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6pub usingnamespace @import("builtin");
7
8/// Deprecated: use `std.Target`.
9pub const Target = std.Target;
10
11/// Deprecated: use `std.Target.Os`.
12pub const Os = std.Target.Os;
13
14/// Deprecated: use `std.Target.Cpu.Arch`.
15pub const Arch = std.Target.Cpu.Arch;
16
17/// Deprecated: use `std.Target.Abi`.
18pub const Abi = std.Target.Abi;
19
20/// Deprecated: use `std.Target.ObjectFormat`.
21pub const ObjectFormat = std.Target.ObjectFormat;
22
23/// Deprecated: use `std.Target.SubSystem`.
24pub const SubSystem = std.Target.SubSystem;
25
26/// Deprecated: use `std.Target.Cpu`.
27pub const Cpu = std.Target.Cpu;
6const builtin = @import("builtin");
7
8// These are all deprecated.
9pub const zig_version = builtin.zig_version;
10pub const zig_is_stage2 = builtin.zig_is_stage2;
11pub const output_mode = builtin.output_mode;
12pub const link_mode = builtin.link_mode;
13pub const is_test = builtin.is_test;
14pub const single_threaded = builtin.single_threaded;
15pub const abi = builtin.abi;
16pub const cpu = builtin.cpu;
17pub const os = builtin.os;
18pub const target = builtin.target;
19pub const object_format = builtin.object_format;
20pub const mode = builtin.mode;
21pub const link_libc = builtin.link_libc;
22pub const link_libcpp = builtin.link_libcpp;
23pub const have_error_return_tracing = builtin.have_error_return_tracing;
24pub const valgrind_support = builtin.valgrind_support;
25pub const position_independent_code = builtin.position_independent_code;
26pub const position_independent_executable = builtin.position_independent_executable;
27pub const strip_debug_info = builtin.strip_debug_info;
28pub const code_model = builtin.code_model;
2829
2930/// `explicit_subsystem` is missing when the subsystem is automatically detected,
3031/// so Zig standard library has the subsystem detection logic here. This should generally be
3132/// used rather than `explicit_subsystem`.
3233/// On non-Windows targets, this is `null`.
33pub const subsystem: ?SubSystem = blk: {
34 if (@hasDecl(@This(), "explicit_subsystem")) break :blk explicit_subsystem;
34pub const subsystem: ?std.Target.SubSystem = blk: {
35 if (@hasDecl(builtin, "explicit_subsystem")) break :blk explicit_subsystem;
3536 switch (os.tag) {
3637 .windows => {
3738 if (is_test) {
38 break :blk SubSystem.Console;
39 break :blk std.Target.SubSystem.Console;
3940 }
4041 if (@hasDecl(root, "main") or
4142 @hasDecl(root, "WinMain") or
......@@ -43,9 +44,9 @@ pub const subsystem: ?SubSystem = blk: {
4344 @hasDecl(root, "WinMainCRTStartup") or
4445 @hasDecl(root, "wWinMainCRTStartup"))
4546 {
46 break :blk SubSystem.Windows;
47 break :blk std.Target.SubSystem.Windows;
4748 } else {
48 break :blk SubSystem.Console;
49 break :blk std.Target.SubSystem.Console;
4950 }
5051 },
5152 else => break :blk null,
lib/std/c/linux.zig+8-6
......@@ -3,12 +3,14 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
76const std = @import("../std.zig");
87const maxInt = std.math.maxInt;
8const abi = std.Target.current.abi;
9const arch = std.Target.current.cpu.arch;
10const os_tag = std.Target.current.os.tag;
911usingnamespace std.c;
1012
11pub const _errno = switch (builtin.abi) {
13pub const _errno = switch (abi) {
1214 .android => struct {
1315 extern "c" var __errno: c_int;
1416 fn getErrno() *c_int {
......@@ -124,7 +126,7 @@ pub const pthread_mutex_t = extern struct {
124126pub const pthread_cond_t = extern struct {
125127 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
126128};
127pub const pthread_rwlock_t = switch (std.builtin.abi) {
129pub const pthread_rwlock_t = switch (abi) {
128130 .android => switch (@sizeOf(usize)) {
129131 4 => extern struct {
130132 lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
......@@ -155,11 +157,11 @@ pub const sem_t = extern struct {
155157};
156158
157159const __SIZEOF_PTHREAD_COND_T = 48;
158const __SIZEOF_PTHREAD_MUTEX_T = if (builtin.os.tag == .fuchsia) 40 else switch (builtin.abi) {
160const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
159161 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
160 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.arch) {
162 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {
161163 .aarch64 => 48,
162 .x86_64 => if (builtin.abi == .gnux32) 40 else 32,
164 .x86_64 => if (abi == .gnux32) 40 else 32,
163165 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
164166 else => if (@sizeOf(usize) == 8) 40 else 24,
165167 },
lib/std/child_process.zig+1-1
......@@ -15,7 +15,7 @@ const windows = os.windows;
1515const mem = std.mem;
1616const debug = std.debug;
1717const BufMap = std.BufMap;
18const builtin = @import("builtin");
18const builtin = std.builtin;
1919const Os = builtin.Os;
2020const TailQueue = std.TailQueue;
2121const maxInt = std.math.maxInt;
lib/std/coff.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77const std = @import("std.zig");
88const io = std.io;
99const mem = std.mem;
lib/std/cstr.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const debug = std.debug;
99const mem = std.mem;
1010const testing = std.testing;
lib/std/debug.zig+25-22
......@@ -21,6 +21,9 @@ const root = @import("root");
2121const maxInt = std.math.maxInt;
2222const File = std.fs.File;
2323const windows = std.os.windows;
24const native_arch = std.Target.current.cpu.arch;
25const native_os = std.Target.current.os.tag;
26const native_endian = native_arch.endian();
2427
2528pub const runtime_safety = switch (builtin.mode) {
2629 .Debug, .ReleaseSafe => true,
......@@ -90,7 +93,7 @@ pub fn detectTTYConfig() TTY.Config {
9093 const stderr_file = io.getStdErr();
9194 if (stderr_file.supportsAnsiEscapeCodes()) {
9295 return .escape_codes;
93 } else if (builtin.os.tag == .windows and stderr_file.isTty()) {
96 } else if (native_os == .windows and stderr_file.isTty()) {
9497 return .windows_api;
9598 } else {
9699 return .no_color;
......@@ -148,7 +151,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
148151/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
149152/// equals the passed in addresses pointer.
150153pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
151 if (builtin.os.tag == .windows) {
154 if (native_os == .windows) {
152155 const addrs = stack_trace.instruction_addresses;
153156 const u32_addrs_len = @intCast(u32, addrs.len);
154157 const first_addr = first_address orelse {
......@@ -226,7 +229,7 @@ pub fn assert(ok: bool) void {
226229pub fn panic(comptime format: []const u8, args: anytype) noreturn {
227230 @setCold(true);
228231 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address
229 const first_trace_addr = if (builtin.os.tag == .wasi) null else @returnAddress();
232 const first_trace_addr = if (native_os == .wasi) null else @returnAddress();
230233 panicExtra(null, first_trace_addr, format, args);
231234}
232235
......@@ -343,25 +346,25 @@ pub const StackIterator = struct {
343346 }
344347
345348 // Offset of the saved BP wrt the frame pointer.
346 const fp_offset = if (builtin.arch.isRISCV())
349 const fp_offset = if (native_arch.isRISCV())
347350 // On RISC-V the frame pointer points to the top of the saved register
348351 // area, on pretty much every other architecture it points to the stack
349352 // slot where the previous frame pointer is saved.
350353 2 * @sizeOf(usize)
351 else if (builtin.arch.isSPARC())
354 else if (native_arch.isSPARC())
352355 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
353356 14 * @sizeOf(usize)
354357 else
355358 0;
356359
357 const fp_bias = if (builtin.arch.isSPARC())
360 const fp_bias = if (native_arch.isSPARC())
358361 // On SPARC frame pointers are biased by a constant.
359362 2047
360363 else
361364 0;
362365
363366 // Positive offset of the saved PC wrt the frame pointer.
364 const pc_offset = if (builtin.arch == .powerpc64le)
367 const pc_offset = if (native_arch == .powerpc64le)
365368 2 * @sizeOf(usize)
366369 else
367370 @sizeOf(usize);
......@@ -380,7 +383,7 @@ pub const StackIterator = struct {
380383 }
381384
382385 fn next_internal(self: *StackIterator) ?usize {
383 const fp = if (builtin.arch.isSPARC())
386 const fp = if (native_arch.isSPARC())
384387 // On SPARC the offset is positive. (!)
385388 math.add(usize, self.fp, fp_offset) catch return null
386389 else
......@@ -416,7 +419,7 @@ pub fn writeCurrentStackTrace(
416419 tty_config: TTY.Config,
417420 start_addr: ?usize,
418421) !void {
419 if (builtin.os.tag == .windows) {
422 if (native_os == .windows) {
420423 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr);
421424 }
422425 var it = StackIterator.init(start_addr, null);
......@@ -473,7 +476,7 @@ pub const TTY = struct {
473476 .Dim => out_stream.writeAll(DIM) catch return,
474477 .Reset => out_stream.writeAll(RESET) catch return,
475478 },
476 .windows_api => if (builtin.os.tag == .windows) {
479 .windows_api => if (native_os == .windows) {
477480 const stderr_file = io.getStdErr();
478481 const S = struct {
479482 var attrs: windows.WORD = undefined;
......@@ -675,7 +678,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
675678 if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
676679 return root.os.debug.openSelfDebugInfo(allocator);
677680 }
678 switch (builtin.os.tag) {
681 switch (native_os) {
679682 .linux,
680683 .freebsd,
681684 .netbsd,
......@@ -888,7 +891,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
888891 elf.ELFDATA2MSB => .Big,
889892 else => return error.InvalidElfEndian,
890893 };
891 assert(endian == std.builtin.endian); // this is our own debug info
894 assert(endian == native_endian); // this is our own debug info
892895
893896 const shoff = hdr.e_shoff;
894897 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
......@@ -1123,9 +1126,9 @@ pub const DebugInfo = struct {
11231126 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
11241127 if (comptime std.Target.current.isDarwin()) {
11251128 return self.lookupModuleDyld(address);
1126 } else if (builtin.os.tag == .windows) {
1129 } else if (native_os == .windows) {
11271130 return self.lookupModuleWin32(address);
1128 } else if (builtin.os.tag == .haiku) {
1131 } else if (native_os == .haiku) {
11291132 return self.lookupModuleHaiku(address);
11301133 } else {
11311134 return self.lookupModuleDl(address);
......@@ -1353,7 +1356,7 @@ const SymbolInfo = struct {
13531356 }
13541357};
13551358
1356pub const ModuleDebugInfo = switch (builtin.os.tag) {
1359pub const ModuleDebugInfo = switch (native_os) {
13571360 .macos, .ios, .watchos, .tvos => struct {
13581361 base_address: usize,
13591362 mapped_memory: []const u8,
......@@ -1720,7 +1723,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
17201723}
17211724
17221725/// Whether or not the current target can print useful debug information when a segfault occurs.
1723pub const have_segfault_handling_support = switch (builtin.os.tag) {
1726pub const have_segfault_handling_support = switch (native_os) {
17241727 .linux, .netbsd => true,
17251728 .windows => true,
17261729 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
......@@ -1744,7 +1747,7 @@ pub fn attachSegfaultHandler() void {
17441747 if (!have_segfault_handling_support) {
17451748 @compileError("segfault handler not supported for this target");
17461749 }
1747 if (builtin.os.tag == .windows) {
1750 if (native_os == .windows) {
17481751 windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows);
17491752 return;
17501753 }
......@@ -1760,7 +1763,7 @@ pub fn attachSegfaultHandler() void {
17601763}
17611764
17621765fn resetSegfaultHandler() void {
1763 if (builtin.os.tag == .windows) {
1766 if (native_os == .windows) {
17641767 if (windows_segfault_handle) |handle| {
17651768 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
17661769 windows_segfault_handle = null;
......@@ -1783,7 +1786,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
17831786 // and the resulting segfault will crash the process rather than continually dump stack traces.
17841787 resetSegfaultHandler();
17851788
1786 const addr = switch (builtin.os.tag) {
1789 const addr = switch (native_os) {
17871790 .linux => @ptrToInt(info.fields.sigfault.addr),
17881791 .freebsd => @ptrToInt(info.addr),
17891792 .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
18021805 } catch os.abort();
18031806 }
18041807
1805 switch (builtin.arch) {
1808 switch (native_arch) {
18061809 .i386 => {
18071810 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
18081811 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
18111814 },
18121815 .x86_64 => {
18131816 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1814 const ip = switch (builtin.os.tag) {
1817 const ip = switch (native_os) {
18151818 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
18161819 .freebsd => @intCast(usize, ctx.mcontext.rip),
18171820 .openbsd => @intCast(usize, ctx.sc_rip),
18181821 else => unreachable,
18191822 };
1820 const bp = switch (builtin.os.tag) {
1823 const bp = switch (native_os) {
18211824 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
18221825 .openbsd => @intCast(usize, ctx.sc_rbp),
18231826 .freebsd => @intCast(usize, ctx.mcontext.rbp),
lib/std/dwarf.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const debug = std.debug;
99const fs = std.fs;
1010const io = std.io;
lib/std/dynamic_library.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77
88const std = @import("std.zig");
99const mem = std.mem;
lib/std/event/channel.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const testing = std.testing;
1010const Loop = std.event.Loop;
lib/std/event/future.zig+1-1
......@@ -6,7 +6,7 @@
66const std = @import("../std.zig");
77const assert = std.debug.assert;
88const testing = std.testing;
9const builtin = @import("builtin");
9const builtin = std.builtin;
1010const Lock = std.event.Lock;
1111
1212/// This is a value that starts out unavailable, until resolve() is called
lib/std/event/group.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const Lock = std.event.Lock;
99const testing = std.testing;
1010const Allocator = std.mem.Allocator;
lib/std/event/lock.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const testing = std.testing;
1010const mem = std.mem;
lib/std/event/loop.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const root = @import("root");
99const assert = std.debug.assert;
1010const testing = std.testing;
lib/std/event/rwlock.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const testing = std.testing;
1010const mem = std.mem;
lib/std/event/wait_group.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const Loop = std.event.Loop;
99
1010/// A WaitGroup keeps track and waits for a group of async tasks to finish.
lib/std/fmt.zig+1-1
......@@ -9,7 +9,7 @@ const assert = std.debug.assert;
99const mem = std.mem;
1010const unicode = std.unicode;
1111const meta = std.meta;
12const builtin = @import("builtin");
12const builtin = std.builtin;
1313const errol = @import("fmt/errol.zig");
1414const lossyCast = std.math.lossyCast;
1515const expectFmt = std.testing.expectFmt;
lib/std/fs.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77const std = @import("std.zig");
88const os = std.os;
99const mem = std.mem;
lib/std/fs/file.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const os = std.os;
99const io = std.io;
1010const mem = std.mem;
lib/std/fs/get_app_data_dir.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const unicode = std.unicode;
99const mem = std.mem;
1010const fs = std.fs;
lib/std/fs/path.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77const std = @import("../std.zig");
88const debug = std.debug;
99const assert = debug.assert;
lib/std/fs/wasi.zig+1-1
......@@ -167,7 +167,7 @@ pub const PreopenList = struct {
167167};
168168
169169test "extracting WASI preopens" {
170 if (@import("builtin").os.tag != .wasi) return error.SkipZigTest;
170 if (std.builtin.os.tag != .wasi) return error.SkipZigTest;
171171
172172 var preopens = PreopenList.init(std.testing.allocator);
173173 defer preopens.deinit();
lib/std/fs/watch.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const event = std.event;
99const assert = std.debug.assert;
1010const testing = std.testing;
lib/std/hash/auto_hash.zig+3-3
......@@ -4,10 +4,10 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = @import("builtin");
87const assert = std.debug.assert;
98const mem = std.mem;
109const meta = std.meta;
10const builtin = std.builtin;
1111
1212/// Describes how pointer types should be hashed.
1313pub const HashStrategy = enum {
......@@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240240test "typeContainsSlice" {
241241 comptime {
242 testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
242 testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));
243243
244244 testing.expect(typeContainsSlice([]const u8));
245245 testing.expect(!typeContainsSlice(u8));
......@@ -400,7 +400,7 @@ test "testHash union" {
400400
401401test "testHash vector" {
402402 // Disabled because of #3317
403 if (@import("builtin").arch == .mipsel or @import("builtin").arch == .mips) return error.SkipZigTest;
403 if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) return error.SkipZigTest;
404404
405405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
lib/std/hash/benchmark.zig+1-1
......@@ -5,7 +5,7 @@
55// and substantial portions of the software.
66// zig run benchmark.zig --release-fast --override-lib-dir ..
77
8const builtin = @import("builtin");
8const builtin = std.builtin;
99const std = @import("std");
1010const time = std.time;
1111const Timer = time.Timer;
lib/std/hash/cityhash.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88
99fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 {
1010 // ptr + offset doesn't work at comptime so we need this instead.
lib/std/hash/murmur.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const testing = std.testing;
99
1010const default_seed: u32 = 0xc70f6907;
lib/std/hash_map.zig-1
......@@ -4,7 +4,6 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
87const assert = debug.assert;
98const autoHash = std.hash.autoHash;
109const debug = std.debug;
lib/std/heap.zig+1-1
......@@ -10,7 +10,7 @@ const assert = debug.assert;
1010const testing = std.testing;
1111const mem = std.mem;
1212const os = std.os;
13const builtin = @import("builtin");
13const builtin = std.builtin;
1414const c = std.c;
1515const maxInt = std.math.maxInt;
1616
lib/std/io.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const root = @import("root");
99const c = std.c;
1010
lib/std/math/acosh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/acoshf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/acosh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expect = std.testing.expect;
lib/std/math/ceil.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expect = std.testing.expect;
lib/std/math/complex/atan.zig-1
......@@ -10,7 +10,6 @@
1010// https://git.musl-libc.org/cgit/musl/tree/src/complex/catan.c
1111
1212const std = @import("../../std.zig");
13const builtin = @import("builtin");
1413const testing = std.testing;
1514const math = std.math;
1615const cmath = math.complex;
lib/std/math/complex/cosh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccoshf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccosh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../../std.zig");
1413const testing = std.testing;
1514const math = std.math;
lib/std/math/complex/exp.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexpf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexp.c
1111
12const builtin = @import("builtin");
1312const std = @import("../../std.zig");
1413const testing = std.testing;
1514const math = std.math;
lib/std/math/complex/sinh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinhf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../../std.zig");
1413const testing = std.testing;
1514const math = std.math;
lib/std/math/complex/tanh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanhf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../../std.zig");
1413const testing = std.testing;
1514const math = std.math;
lib/std/math/cos.zig-1
......@@ -8,7 +8,6 @@
88//
99// https://golang.org/src/math/sin.go
1010
11const builtin = @import("builtin");
1211const std = @import("../std.zig");
1312const math = std.math;
1413const expect = std.testing.expect;
lib/std/math/cosh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/coshf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/cosh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expo2 = @import("expo2.zig").expo2;
lib/std/math/expm1.zig-1
......@@ -11,7 +11,6 @@
1111
1212// TODO: Updated recently.
1313
14const builtin = @import("builtin");
1514const std = @import("../std.zig");
1615const math = std.math;
1716const expect = std.testing.expect;
lib/std/math/floor.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
1111
12const builtin = @import("builtin");
1312const expect = std.testing.expect;
1413const std = @import("../std.zig");
1514const math = std.math;
lib/std/math/log1p.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/log1pf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/log1p.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expect = std.testing.expect;
lib/std/math/pow.zig-1
......@@ -8,7 +8,6 @@
88//
99// https://golang.org/src/math/pow.go
1010
11const builtin = @import("builtin");
1211const std = @import("../std.zig");
1312const math = std.math;
1413const expect = std.testing.expect;
lib/std/math/powi.zig-1
......@@ -8,7 +8,6 @@
88//
99// https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/src/libcore/num/mod.rs#L3423
1010
11const builtin = @import("builtin");
1211const std = @import("../std.zig");
1312const math = std.math;
1413const assert = std.debug.assert;
lib/std/math/round.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
1111
12const builtin = @import("builtin");
1312const expect = std.testing.expect;
1413const std = @import("../std.zig");
1514const math = std.math;
lib/std/math/sin.zig-1
......@@ -8,7 +8,6 @@
88//
99// https://golang.org/src/math/sin.go
1010
11const builtin = @import("builtin");
1211const std = @import("../std.zig");
1312const math = std.math;
1413const expect = std.testing.expect;
lib/std/math/sinh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/sinhf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/sinh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expect = std.testing.expect;
lib/std/math/sqrt.zig+1-2
......@@ -6,8 +6,7 @@
66const std = @import("../std.zig");
77const math = std.math;
88const expect = std.testing.expect;
9const builtin = @import("builtin");
10const TypeId = builtin.TypeId;
9const TypeId = std.builtin.TypeId;
1110const maxInt = std.math.maxInt;
1211
1312/// Returns the square root of x.
lib/std/math/tan.zig-1
......@@ -8,7 +8,6 @@
88//
99// https://golang.org/src/math/tan.go
1010
11const builtin = @import("builtin");
1211const std = @import("../std.zig");
1312const math = std.math;
1413const expect = std.testing.expect;
lib/std/math/tanh.zig-1
......@@ -9,7 +9,6 @@
99// https://git.musl-libc.org/cgit/musl/tree/src/math/tanhf.c
1010// https://git.musl-libc.org/cgit/musl/tree/src/math/tanh.c
1111
12const builtin = @import("builtin");
1312const std = @import("../std.zig");
1413const math = std.math;
1514const expect = std.testing.expect;
lib/std/mem.zig+46-45
......@@ -7,17 +7,18 @@ const std = @import("std.zig");
77const debug = std.debug;
88const assert = debug.assert;
99const math = std.math;
10const builtin = std.builtin;
1110const mem = @This();
1211const meta = std.meta;
1312const trait = meta.trait;
1413const testing = std.testing;
14const Endian = std.builtin.Endian;
15const native_endian = std.Target.current.cpu.arch.endian();
1516
1617/// Compile time known minimum page size.
1718/// https://github.com/ziglang/zig/issues/4082
18pub const page_size = switch (builtin.arch) {
19pub const page_size = switch (std.Target.current.cpu.arch) {
1920 .wasm32, .wasm64 => 64 * 1024,
20 .aarch64 => switch (builtin.os.tag) {
21 .aarch64 => switch (std.Target.current.os.tag) {
2122 .macos, .ios, .watchos, .tvos => 16 * 1024,
2223 else => 4 * 1024,
2324 },
......@@ -1042,7 +1043,7 @@ test "mem.containsAtLeast" {
10421043/// Reads an integer from memory with size equal to bytes.len.
10431044/// T specifies the return type, which must be large enough to store
10441045/// the result.
1045pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType {
1046pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType {
10461047 var result: ReturnType = 0;
10471048 switch (endian) {
10481049 .Big => {
......@@ -1077,12 +1078,12 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).In
10771078 return @byteSwap(T, readIntNative(T, bytes));
10781079}
10791080
1080pub const readIntLittle = switch (builtin.endian) {
1081pub const readIntLittle = switch (native_endian) {
10811082 .Little => readIntNative,
10821083 .Big => readIntForeign,
10831084};
10841085
1085pub const readIntBig = switch (builtin.endian) {
1086pub const readIntBig = switch (native_endian) {
10861087 .Little => readIntForeign,
10871088 .Big => readIntNative,
10881089};
......@@ -1106,12 +1107,12 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
11061107 return @byteSwap(T, readIntSliceNative(T, bytes));
11071108}
11081109
1109pub const readIntSliceLittle = switch (builtin.endian) {
1110pub const readIntSliceLittle = switch (native_endian) {
11101111 .Little => readIntSliceNative,
11111112 .Big => readIntSliceForeign,
11121113};
11131114
1114pub const readIntSliceBig = switch (builtin.endian) {
1115pub const readIntSliceBig = switch (native_endian) {
11151116 .Little => readIntSliceForeign,
11161117 .Big => readIntSliceNative,
11171118};
......@@ -1119,8 +1120,8 @@ pub const readIntSliceBig = switch (builtin.endian) {
11191120/// Reads an integer from memory with bit count specified by T.
11201121/// The bit count of T must be evenly divisible by 8.
11211122/// This function cannot fail and cannot cause undefined behavior.
1122pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: builtin.Endian) T {
1123 if (endian == builtin.endian) {
1123pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T {
1124 if (endian == native_endian) {
11241125 return readIntNative(T, bytes);
11251126 } else {
11261127 return readIntForeign(T, bytes);
......@@ -1130,7 +1131,7 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits,
11301131/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
11311132/// and ignores extra bytes.
11321133/// The bit count of T must be evenly divisible by 8.
1133pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: builtin.Endian) T {
1134pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: Endian) T {
11341135 const n = @divExact(@typeInfo(T).Int.bits, 8);
11351136 assert(bytes.len >= n);
11361137 return readInt(T, bytes[0..n], endian);
......@@ -1188,12 +1189,12 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits,
11881189 writeIntNative(T, buf, @byteSwap(T, value));
11891190}
11901191
1191pub const writeIntLittle = switch (builtin.endian) {
1192pub const writeIntLittle = switch (native_endian) {
11921193 .Little => writeIntNative,
11931194 .Big => writeIntForeign,
11941195};
11951196
1196pub const writeIntBig = switch (builtin.endian) {
1197pub const writeIntBig = switch (native_endian) {
11971198 .Little => writeIntForeign,
11981199 .Big => writeIntNative,
11991200};
......@@ -1201,8 +1202,8 @@ pub const writeIntBig = switch (builtin.endian) {
12011202/// Writes an integer to memory, storing it in twos-complement.
12021203/// This function always succeeds, has defined behavior for all inputs, but
12031204/// the integer bit width must be divisible by 8.
1204pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: builtin.Endian) void {
1205 if (endian == builtin.endian) {
1205pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
1206 if (endian == native_endian) {
12061207 return writeIntNative(T, buffer, value);
12071208 } else {
12081209 return writeIntForeign(T, buffer, value);
......@@ -1252,12 +1253,12 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
12521253 }
12531254}
12541255
1255pub const writeIntSliceNative = switch (builtin.endian) {
1256pub const writeIntSliceNative = switch (native_endian) {
12561257 .Little => writeIntSliceLittle,
12571258 .Big => writeIntSliceBig,
12581259};
12591260
1260pub const writeIntSliceForeign = switch (builtin.endian) {
1261pub const writeIntSliceForeign = switch (native_endian) {
12611262 .Little => writeIntSliceBig,
12621263 .Big => writeIntSliceLittle,
12631264};
......@@ -1268,7 +1269,7 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
12681269/// Any extra bytes in buffer not part of the integer are set to zero, with
12691270/// respect to endianness. To avoid the branch to check for extra buffer bytes,
12701271/// use writeInt instead.
1271pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {
1272pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void {
12721273 comptime assert(@typeInfo(T).Int.bits % 8 == 0);
12731274 return switch (endian) {
12741275 .Little => writeIntSliceLittle(T, buffer, value),
......@@ -1678,10 +1679,10 @@ fn testReadIntImpl() void {
16781679 0x56,
16791680 0x78,
16801681 };
1681 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
1682 testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
16821683 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
16831684 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1684 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
1685 testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
16851686 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
16861687 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
16871688 }
......@@ -1692,7 +1693,7 @@ fn testReadIntImpl() void {
16921693 0x12,
16931694 0x34,
16941695 };
1695 const answer = readInt(u32, &buf, builtin.Endian.Big);
1696 const answer = readInt(u32, &buf, Endian.Big);
16961697 testing.expect(answer == 0x00001234);
16971698 }
16981699 {
......@@ -1702,7 +1703,7 @@ fn testReadIntImpl() void {
17021703 0x00,
17031704 0x00,
17041705 };
1705 const answer = readInt(u32, &buf, builtin.Endian.Little);
1706 const answer = readInt(u32, &buf, Endian.Little);
17061707 testing.expect(answer == 0x00003412);
17071708 }
17081709 {
......@@ -1724,19 +1725,19 @@ test "writeIntSlice" {
17241725fn testWriteIntImpl() void {
17251726 var bytes: [8]u8 = undefined;
17261727
1727 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1728 writeIntSlice(u0, bytes[0..], 0, Endian.Big);
17281729 testing.expect(eql(u8, &bytes, &[_]u8{
17291730 0x00, 0x00, 0x00, 0x00,
17301731 0x00, 0x00, 0x00, 0x00,
17311732 }));
17321733
1733 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1734 writeIntSlice(u0, bytes[0..], 0, Endian.Little);
17341735 testing.expect(eql(u8, &bytes, &[_]u8{
17351736 0x00, 0x00, 0x00, 0x00,
17361737 0x00, 0x00, 0x00, 0x00,
17371738 }));
17381739
1739 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1740 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
17401741 testing.expect(eql(u8, &bytes, &[_]u8{
17411742 0x12,
17421743 0x34,
......@@ -1748,7 +1749,7 @@ fn testWriteIntImpl() void {
17481749 0xBE,
17491750 }));
17501751
1751 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1752 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
17521753 testing.expect(eql(u8, &bytes, &[_]u8{
17531754 0x12,
17541755 0x34,
......@@ -1760,7 +1761,7 @@ fn testWriteIntImpl() void {
17601761 0xBE,
17611762 }));
17621763
1763 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1764 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
17641765 testing.expect(eql(u8, &bytes, &[_]u8{
17651766 0x00,
17661767 0x00,
......@@ -1772,7 +1773,7 @@ fn testWriteIntImpl() void {
17721773 0x78,
17731774 }));
17741775
1775 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1776 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
17761777 testing.expect(eql(u8, &bytes, &[_]u8{
17771778 0x12,
17781779 0x34,
......@@ -1784,7 +1785,7 @@ fn testWriteIntImpl() void {
17841785 0x00,
17851786 }));
17861787
1787 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1788 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
17881789 testing.expect(eql(u8, &bytes, &[_]u8{
17891790 0x00,
17901791 0x00,
......@@ -1796,7 +1797,7 @@ fn testWriteIntImpl() void {
17961797 0x34,
17971798 }));
17981799
1799 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1800 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
18001801 testing.expect(eql(u8, &bytes, &[_]u8{
18011802 0x34,
18021803 0x12,
......@@ -1949,7 +1950,7 @@ test "replaceOwned" {
19491950
19501951/// Converts a little-endian integer to host endianness.
19511952pub fn littleToNative(comptime T: type, x: T) T {
1952 return switch (builtin.endian) {
1953 return switch (native_endian) {
19531954 .Little => x,
19541955 .Big => @byteSwap(T, x),
19551956 };
......@@ -1957,14 +1958,14 @@ pub fn littleToNative(comptime T: type, x: T) T {
19571958
19581959/// Converts a big-endian integer to host endianness.
19591960pub fn bigToNative(comptime T: type, x: T) T {
1960 return switch (builtin.endian) {
1961 return switch (native_endian) {
19611962 .Little => @byteSwap(T, x),
19621963 .Big => x,
19631964 };
19641965}
19651966
19661967/// Converts an integer from specified endianness to host endianness.
1967pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
1968pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T {
19681969 return switch (endianness_of_x) {
19691970 .Little => littleToNative(T, x),
19701971 .Big => bigToNative(T, x),
......@@ -1972,7 +1973,7 @@ pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
19721973}
19731974
19741975/// Converts an integer which has host endianness to the desired endianness.
1975pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
1976pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T {
19761977 return switch (desired_endianness) {
19771978 .Little => nativeToLittle(T, x),
19781979 .Big => nativeToBig(T, x),
......@@ -1981,7 +1982,7 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
19811982
19821983/// Converts an integer which has host endianness to little endian.
19831984pub fn nativeToLittle(comptime T: type, x: T) T {
1984 return switch (builtin.endian) {
1985 return switch (native_endian) {
19851986 .Little => x,
19861987 .Big => @byteSwap(T, x),
19871988 };
......@@ -1989,13 +1990,13 @@ pub fn nativeToLittle(comptime T: type, x: T) T {
19891990
19901991/// Converts an integer which has host endianness to big endian.
19911992pub fn nativeToBig(comptime T: type, x: T) T {
1992 return switch (builtin.endian) {
1993 return switch (native_endian) {
19931994 .Little => @byteSwap(T, x),
19941995 .Big => x,
19951996 };
19961997}
19971998
1998fn CopyPtrAttrs(comptime source: type, comptime size: builtin.TypeInfo.Pointer.Size, comptime child: type) type {
1999fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Pointer.Size, comptime child: type) type {
19992000 const info = @typeInfo(source).Pointer;
20002001 return @Type(.{
20012002 .Pointer = .{
......@@ -2027,7 +2028,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
20272028
20282029test "asBytes" {
20292030 const deadbeef = @as(u32, 0xDEADBEEF);
2030 const deadbeef_bytes = switch (builtin.endian) {
2031 const deadbeef_bytes = switch (native_endian) {
20312032 .Big => "\xDE\xAD\xBE\xEF",
20322033 .Little => "\xEF\xBE\xAD\xDE",
20332034 };
......@@ -2080,13 +2081,13 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
20802081
20812082test "toBytes" {
20822083 var my_bytes = toBytes(@as(u32, 0x12345678));
2083 switch (builtin.endian) {
2084 switch (native_endian) {
20842085 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
20852086 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
20862087 }
20872088
20882089 my_bytes[0] = '\x99';
2089 switch (builtin.endian) {
2090 switch (native_endian) {
20902091 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
20912092 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
20922093 }
......@@ -2113,14 +2114,14 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,
21132114
21142115test "bytesAsValue" {
21152116 const deadbeef = @as(u32, 0xDEADBEEF);
2116 const deadbeef_bytes = switch (builtin.endian) {
2117 const deadbeef_bytes = switch (native_endian) {
21172118 .Big => "\xDE\xAD\xBE\xEF",
21182119 .Little => "\xEF\xBE\xAD\xDE",
21192120 };
21202121
21212122 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21222123
2123 var codeface_bytes: [4]u8 = switch (builtin.endian) {
2124 var codeface_bytes: [4]u8 = switch (native_endian) {
21242125 .Big => "\xC0\xDE\xFA\xCE",
21252126 .Little => "\xCE\xFA\xDE\xC0",
21262127 }.*;
......@@ -2168,7 +2169,7 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T {
21682169 return bytesAsValue(T, bytes).*;
21692170}
21702171test "bytesToValue" {
2171 const deadbeef_bytes = switch (builtin.endian) {
2172 const deadbeef_bytes = switch (native_endian) {
21722173 .Big => "\xDE\xAD\xBE\xEF",
21732174 .Little => "\xEF\xBE\xAD\xDE",
21742175 };
......@@ -2297,7 +2298,7 @@ test "sliceAsBytes" {
22972298 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
22982299 const slice = sliceAsBytes(bytes[0..]);
22992300 testing.expect(slice.len == 4);
2300 testing.expect(eql(u8, slice, switch (builtin.endian) {
2301 testing.expect(eql(u8, slice, switch (native_endian) {
23012302 .Big => "\xDE\xAD\xBE\xEF",
23022303 .Little => "\xAD\xDE\xEF\xBE",
23032304 }));
......@@ -2319,7 +2320,7 @@ test "sliceAsBytes packed struct at runtime and comptime" {
23192320 var foo: Foo = undefined;
23202321 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
23212322 slice[0] = 0x13;
2322 switch (builtin.endian) {
2323 switch (native_endian) {
23232324 .Big => {
23242325 testing.expect(foo.a == 0x1);
23252326 testing.expect(foo.b == 0x3);
lib/std/meta.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const debug = std.debug;
99const mem = std.mem;
1010const math = std.math;
lib/std/net.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const net = @This();
1010const mem = std.mem;
lib/std/os.zig+1-1
......@@ -21,7 +21,7 @@
2121
2222const root = @import("root");
2323const std = @import("std.zig");
24const builtin = @import("builtin");
24const builtin = std.builtin;
2525const assert = std.debug.assert;
2626const math = std.math;
2727const mem = std.mem;
lib/std/os/bits/linux.zig+12-12
......@@ -3,17 +3,17 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
76const std = @import("../../std.zig");
87const maxInt = std.math.maxInt;
8const arch = std.Target.current.cpu.arch;
99usingnamespace @import("../bits.zig");
1010
11pub usingnamespace switch (builtin.arch) {
11pub usingnamespace switch (arch) {
1212 .mips, .mipsel => @import("linux/errno-mips.zig"),
1313 else => @import("linux/errno-generic.zig"),
1414};
1515
16pub usingnamespace switch (builtin.arch) {
16pub usingnamespace switch (arch) {
1717 .i386 => @import("linux/i386.zig"),
1818 .x86_64 => @import("linux/x86_64.zig"),
1919 .aarch64 => @import("linux/arm64.zig"),
......@@ -30,9 +30,9 @@ pub usingnamespace @import("linux/netlink.zig");
3030pub usingnamespace @import("linux/prctl.zig");
3131pub usingnamespace @import("linux/securebits.zig");
3232
33const is_mips = builtin.arch.isMIPS();
34const is_ppc64 = builtin.arch.isPPC64();
35const is_sparc = builtin.arch.isSPARC();
33const is_mips = arch.isMIPS();
34const is_ppc64 = arch.isPPC64();
35const is_sparc = arch.isSPARC();
3636
3737pub const pid_t = i32;
3838pub const fd_t = i32;
......@@ -134,7 +134,7 @@ pub const PROT_WRITE = 0x2;
134134pub const PROT_EXEC = 0x4;
135135
136136/// page may be used for atomic ops
137pub const PROT_SEM = switch (builtin.arch) {
137pub const PROT_SEM = switch (arch) {
138138 // TODO: also xtensa
139139 .mips, .mipsel, .mips64, .mips64el => 0x10,
140140 else => 0x8,
......@@ -1004,7 +1004,7 @@ pub const sigset_t = [1024 / 32]u32;
10041004pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
10051005pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
10061006
1007pub const k_sigaction = switch (builtin.arch) {
1007pub const k_sigaction = switch (arch) {
10081008 .mips, .mipsel => extern struct {
10091009 flags: c_uint,
10101010 handler: ?fn (c_int) callconv(.C) void,
......@@ -1121,7 +1121,7 @@ pub const epoll_data = extern union {
11211121
11221122// On x86_64 the structure is packed so that it matches the definition of its
11231123// 32bit counterpart
1124pub const epoll_event = switch (builtin.arch) {
1124pub const epoll_event = switch (arch) {
11251125 .x86_64 => packed struct {
11261126 events: u32,
11271127 data: epoll_data,
......@@ -1288,12 +1288,12 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
12881288//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
12891289//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
12901290
1291pub const MINSIGSTKSZ = switch (builtin.arch) {
1291pub const MINSIGSTKSZ = switch (arch) {
12921292 .i386, .x86_64, .arm, .mipsel => 2048,
12931293 .aarch64 => 5120,
12941294 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
12951295};
1296pub const SIGSTKSZ = switch (builtin.arch) {
1296pub const SIGSTKSZ = switch (arch) {
12971297 .i386, .x86_64, .arm, .mipsel => 8192,
12981298 .aarch64 => 16384,
12991299 else => @compileError("SIGSTKSZ not defined for this architecture"),
......@@ -2053,7 +2053,7 @@ pub const B3000000 = 0o0010015;
20532053pub const B3500000 = 0o0010016;
20542054pub const B4000000 = 0o0010017;
20552055
2056pub usingnamespace switch (builtin.arch) {
2056pub usingnamespace switch (arch) {
20572057 .powerpc, .powerpc64, .powerpc64le => struct {
20582058 pub const VINTR = 0;
20592059 pub const VQUIT = 1;
lib/std/os/darwin.zig-1
......@@ -3,7 +3,6 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
76const std = @import("../std.zig");
87pub usingnamespace std.c;
98pub usingnamespace @import("bits.zig");
lib/std/os/linux.zig+24-23
......@@ -11,14 +11,15 @@
1111// provide `rename` when only the `renameat` syscall exists.
1212// * Does not support POSIX thread cancellation.
1313const std = @import("../std.zig");
14const builtin = std.builtin;
1514const assert = std.debug.assert;
1615const maxInt = std.math.maxInt;
1716const elf = std.elf;
1817const vdso = @import("linux/vdso.zig");
1918const dl = @import("../dynamic_library.zig");
19const native_arch = std.Target.current.cpu.arch;
20const native_endian = native_arch.endian();
2021
21pub usingnamespace switch (builtin.arch) {
22pub usingnamespace switch (native_arch) {
2223 .i386 => @import("linux/i386.zig"),
2324 .x86_64 => @import("linux/x86_64.zig"),
2425 .aarch64 => @import("linux/arm64.zig"),
......@@ -58,7 +59,7 @@ const require_aligned_register_pair =
5859
5960// Split a 64bit value into a {LSB,MSB} pair.
6061fn splitValue64(val: u64) [2]u32 {
61 switch (builtin.endian) {
62 switch (native_endian) {
6263 .Little => return [2]u32{
6364 @truncate(u32, val),
6465 @truncate(u32, val >> 32),
......@@ -113,7 +114,7 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:
113114}
114115
115116pub fn fork() usize {
116 if (comptime builtin.arch.isSPARC()) {
117 if (comptime native_arch.isSPARC()) {
117118 return syscall_fork();
118119 } else if (@hasField(SYS, "fork")) {
119120 return syscall0(.fork);
......@@ -431,7 +432,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
431432}
432433
433434pub fn pipe(fd: *[2]i32) usize {
434 if (comptime (builtin.arch.isMIPS() or builtin.arch.isSPARC())) {
435 if (comptime (native_arch.isMIPS() or native_arch.isSPARC())) {
435436 return syscall_pipe(fd);
436437 } else if (@hasField(SYS, "pipe")) {
437438 return syscall1(.pipe, @ptrToInt(fd));
......@@ -912,7 +913,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
912913 const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0;
913914 const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0;
914915
915 const result = switch (builtin.arch) {
916 const result = switch (native_arch) {
916917 // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.
917918 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
918919 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 {
944945}
945946
946947pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
947 if (builtin.arch == .i386) {
948 if (native_arch == .i386) {
948949 return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
949950 }
950951 return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
951952}
952953
953954pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
954 if (builtin.arch == .i386) {
955 if (native_arch == .i386) {
955956 return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
956957 }
957958 return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
958959}
959960
960961pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
961 if (builtin.arch == .i386) {
962 if (native_arch == .i386) {
962963 return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });
963964 }
964965 return syscall3(.socket, domain, socket_type, protocol);
965966}
966967
967968pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
968 if (builtin.arch == .i386) {
969 if (native_arch == .i386) {
969970 return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });
970971 }
971972 return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
972973}
973974
974975pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
975 if (builtin.arch == .i386) {
976 if (native_arch == .i386) {
976977 return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });
977978 }
978979 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
979980}
980981
981982pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
982 if (builtin.arch == .i386) {
983 if (native_arch == .i386) {
983984 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
984985 }
985986 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
10261027}
10271028
10281029pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
1029 if (builtin.arch == .i386) {
1030 if (native_arch == .i386) {
10301031 return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });
10311032 }
10321033 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
10331034}
10341035
10351036pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
1036 if (builtin.arch == .i386) {
1037 if (native_arch == .i386) {
10371038 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
10381039 }
10391040 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
10401041}
10411042
10421043pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
1043 if (builtin.arch == .i386) {
1044 if (native_arch == .i386) {
10441045 return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });
10451046 }
10461047 return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
10471048}
10481049
10491050pub fn shutdown(fd: i32, how: i32) usize {
1050 if (builtin.arch == .i386) {
1051 if (native_arch == .i386) {
10511052 return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });
10521053 }
10531054 return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
10541055}
10551056
10561057pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1057 if (builtin.arch == .i386) {
1058 if (native_arch == .i386) {
10581059 return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });
10591060 }
10601061 return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
10611062}
10621063
10631064pub fn listen(fd: i32, backlog: u32) usize {
1064 if (builtin.arch == .i386) {
1065 if (native_arch == .i386) {
10651066 return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });
10661067 }
10671068 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
10681069}
10691070
10701071pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1071 if (builtin.arch == .i386) {
1072 if (native_arch == .i386) {
10721073 return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });
10731074 }
10741075 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 {
10951096}
10961097
10971098pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
1098 if (builtin.arch == .i386) {
1099 if (native_arch == .i386) {
10991100 return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });
11001101 }
11011102 return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
11021103}
11031104
11041105pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {
1105 if (builtin.arch == .i386) {
1106 if (native_arch == .i386) {
11061107 return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 });
11071108 }
11081109 return accept4(fd, addr, len, 0);
11091110}
11101111
11111112pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
1112 if (builtin.arch == .i386) {
1113 if (native_arch == .i386) {
11131114 return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });
11141115 }
11151116 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 {
13881389}
13891390
13901391test {
1391 if (builtin.os.tag == .linux) {
1392 if (std.Target.current.os.tag == .linux) {
13921393 _ = @import("linux/test.zig");
13931394 }
13941395}
lib/std/os/linux/start_pie.zig+1-1
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const elf = std.elf;
3const builtin = @import("builtin");
3const builtin = std.builtin;
44const assert = std.debug.assert;
55
66const R_AMD64_RELATIVE = 8;
lib/std/os/linux/test.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("../../std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const linux = std.os.linux;
99const mem = std.mem;
1010const elf = std.elf;
lib/std/os/linux/tls.zig+8-8
......@@ -4,12 +4,12 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = std.builtin;
87const os = std.os;
98const mem = std.mem;
109const elf = std.elf;
1110const math = std.math;
1211const assert = std.debug.assert;
12const native_arch = std.Target.current.cpu.arch;
1313
1414// This file implements the two TLS variants [1] used by ELF-based systems.
1515//
......@@ -52,14 +52,14 @@ const TLSVariant = enum {
5252 VariantII,
5353};
5454
55const tls_variant = switch (builtin.arch) {
55const tls_variant = switch (native_arch) {
5656 .arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => TLSVariant.VariantI,
5757 .x86_64, .i386, .sparcv9 => TLSVariant.VariantII,
5858 else => @compileError("undefined tls_variant for this architecture"),
5959};
6060
6161// Controls how many bytes are reserved for the Thread Control Block
62const tls_tcb_size = switch (builtin.arch) {
62const tls_tcb_size = switch (native_arch) {
6363 // ARM EABI mandates enough space for two pointers: the first one points to
6464 // the DTV while the second one is unspecified but reserved
6565 .arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize),
......@@ -68,7 +68,7 @@ const tls_tcb_size = switch (builtin.arch) {
6868};
6969
7070// Controls if the TP points to the end of the TCB instead of its beginning
71const tls_tp_points_past_tcb = switch (builtin.arch) {
71const tls_tp_points_past_tcb = switch (native_arch) {
7272 .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true,
7373 else => false,
7474};
......@@ -76,12 +76,12 @@ const tls_tp_points_past_tcb = switch (builtin.arch) {
7676// Some architectures add some offset to the tp and dtv addresses in order to
7777// make the generated code more efficient
7878
79const tls_tp_offset = switch (builtin.arch) {
79const tls_tp_offset = switch (native_arch) {
8080 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x7000,
8181 else => 0,
8282};
8383
84const tls_dtv_offset = switch (builtin.arch) {
84const tls_dtv_offset = switch (native_arch) {
8585 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x8000,
8686 .riscv32, .riscv64 => 0x800,
8787 else => 0,
......@@ -114,7 +114,7 @@ const TLSImage = struct {
114114pub var tls_image: TLSImage = undefined;
115115
116116pub fn setThreadPointer(addr: usize) void {
117 switch (builtin.arch) {
117 switch (native_arch) {
118118 .i386 => {
119119 var user_desc = std.os.linux.user_desc{
120120 .entry_number = tls_image.gdt_entry_number,
......@@ -228,7 +228,7 @@ fn initTLS() void {
228228 // ARMv6 targets (and earlier) have no support for TLS in hardware
229229 // FIXME: Elide the check for targets >= ARMv7 when the target feature API
230230 // becomes less verbose (and more usable).
231 if (comptime builtin.arch.isARM()) {
231 if (comptime native_arch.isARM()) {
232232 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {
233233 // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls
234234 // For the time being use a simple abort instead of a @panic call to
lib/std/os/test.zig+1-1
......@@ -18,7 +18,7 @@ const Thread = std.Thread;
1818
1919const a = std.testing.allocator;
2020
21const builtin = @import("builtin");
21const builtin = std.builtin;
2222const AtomicRmwOp = builtin.AtomicRmwOp;
2323const AtomicOrder = builtin.AtomicOrder;
2424const tmpDir = std.testing.tmpDir;
lib/std/os/windows.zig+1-1
......@@ -9,7 +9,7 @@
99// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
1010// slices as well as APIs which accept null-terminated UTF16LE byte buffers.
1111
12const builtin = @import("builtin");
12const builtin = std.builtin;
1313const std = @import("../std.zig");
1414const mem = std.mem;
1515const assert = std.debug.assert;
lib/std/os/windows/bits.zig+3-3
......@@ -5,10 +5,10 @@
55// and substantial portions of the software.
66// Platform-dependent types and values that are used along with OS-specific APIs.
77
8const builtin = @import("builtin");
98const std = @import("../../std.zig");
109const assert = std.debug.assert;
1110const maxInt = std.math.maxInt;
11const arch = std.Target.current.cpu.arch;
1212
1313pub usingnamespace @import("win32error.zig");
1414pub usingnamespace @import("ntstatus.zig");
......@@ -24,7 +24,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
2424/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
2525pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
2626
27pub const WINAPI: builtin.CallingConvention = if (builtin.arch == .i386)
27pub const WINAPI: std.builtin.CallingConvention = if (arch == .i386)
2828 .Stdcall
2929else
3030 .C;
......@@ -937,7 +937,7 @@ pub const EXCEPTION_RECORD = extern struct {
937937 ExceptionInformation: [15]usize,
938938};
939939
940pub usingnamespace switch (builtin.arch) {
940pub usingnamespace switch (arch) {
941941 .i386 => struct {
942942 pub const FLOATING_SAVE_AREA = extern struct {
943943 ControlWord: DWORD,
lib/std/os/windows/user32.zig+1-1
......@@ -5,7 +5,7 @@
55// and substantial portions of the software.
66usingnamespace @import("bits.zig");
77const std = @import("std");
8const builtin = @import("builtin");
8const builtin = std.builtin;
99const assert = std.debug.assert;
1010const windows = @import("../windows.zig");
1111const unexpectedError = windows.unexpectedError;
lib/std/packed_int_array.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const debug = std.debug;
99const testing = std.testing;
1010
lib/std/pdb.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77const std = @import("std.zig");
88const io = std.io;
99const math = std.math;
lib/std/rand.zig+1-1
......@@ -13,7 +13,7 @@
1313//! TODO(tiehuis): Benchmark these against other reference implementations.
1414
1515const std = @import("std.zig");
16const builtin = @import("builtin");
16const builtin = std.builtin;
1717const assert = std.debug.assert;
1818const expect = std.testing.expect;
1919const expectEqual = std.testing.expectEqual;
lib/std/sort.zig+1-1
......@@ -8,7 +8,7 @@ const assert = std.debug.assert;
88const testing = std.testing;
99const mem = std.mem;
1010const math = std.math;
11const builtin = @import("builtin");
11const builtin = std.builtin;
1212
1313pub fn binarySearch(
1414 comptime T: type,
lib/std/special/c.zig+10-7
......@@ -10,19 +10,22 @@
1010// such as memcpy, memset, and some math functions.
1111
1212const std = @import("std");
13const builtin = @import("builtin");
13const builtin = std.builtin;
1414const maxInt = std.math.maxInt;
1515const isNan = std.math.isNan;
16const native_arch = std.Target.current.cpu.arch;
17const native_abi = std.Target.current.abi;
18const native_os = std.Target.current.os.tag;
1619
17const is_wasm = switch (builtin.arch) {
20const is_wasm = switch (native_arch) {
1821 .wasm32, .wasm64 => true,
1922 else => false,
2023};
21const is_msvc = switch (builtin.abi) {
24const is_msvc = switch (native_abi) {
2225 .msvc => true,
2326 else => false,
2427};
25const is_freestanding = switch (builtin.os.tag) {
28const is_freestanding = switch (native_os) {
2629 .freestanding => true,
2730 else => false,
2831};
......@@ -174,7 +177,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
174177 @setCold(true);
175178 std.debug.panic("{s}", .{msg});
176179 }
177 if (builtin.os.tag != .freestanding and builtin.os.tag != .other) {
180 if (native_os != .freestanding and native_os != .other) {
178181 std.os.abort();
179182 }
180183 while (true) {}
......@@ -275,7 +278,7 @@ test "test_bcmp" {
275278}
276279
277280comptime {
278 if (builtin.os.tag == .linux) {
281 if (native_os == .linux) {
279282 @export(clone, .{ .name = "clone" });
280283 }
281284}
......@@ -284,7 +287,7 @@ comptime {
284287// it causes a segfault in release mode. this is a workaround of calling it
285288// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.
286289fn clone() callconv(.Naked) void {
287 switch (builtin.arch) {
290 switch (native_arch) {
288291 .i386 => {
289292 // __clone(func, stack, flags, arg, ptid, tls, ctid)
290293 // +8, +12, +16, +20, +24, +28, +32
lib/std/special/compiler_rt.zig+12-9
......@@ -6,15 +6,18 @@
66const std = @import("std");
77const builtin = std.builtin;
88const is_test = builtin.is_test;
9const os_tag = std.Target.current.os.tag;
10const arch = std.Target.current.cpu.arch;
11const abi = std.Target.current.abi;
912
10const is_gnu = std.Target.current.abi.isGnu();
11const is_mingw = builtin.os.tag == .windows and is_gnu;
13const is_gnu = abi.isGnu();
14const is_mingw = os_tag == .windows and is_gnu;
1215
1316comptime {
1417 const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;
1518 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
1619
17 switch (builtin.arch) {
20 switch (arch) {
1821 .i386,
1922 .x86_64,
2023 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{
......@@ -167,11 +170,11 @@ comptime {
167170
168171 @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
169172
170 if (builtin.link_libc and builtin.os.tag == .openbsd) {
173 if (builtin.link_libc and os_tag == .openbsd) {
171174 @export(@import("compiler_rt/emutls.zig").__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
172175 }
173176
174 if ((builtin.arch.isARM() or builtin.arch.isThumb()) and !is_test) {
177 if ((arch.isARM() or arch.isThumb()) and !is_test) {
175178 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
176179 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
177180 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
......@@ -202,7 +205,7 @@ comptime {
202205 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });
203206 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });
204207
205 if (builtin.os.tag == .linux) {
208 if (os_tag == .linux) {
206209 @export(@import("compiler_rt/arm.zig").__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
207210 }
208211
......@@ -269,7 +272,7 @@ comptime {
269272 @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
270273 }
271274
272 if (builtin.arch == .i386 and builtin.abi == .msvc) {
275 if (arch == .i386 and abi == .msvc) {
273276 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
274277 @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });
275278 @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });
......@@ -277,7 +280,7 @@ comptime {
277280 @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
278281 }
279282
280 if (builtin.arch.isSPARC()) {
283 if (arch.isSPARC()) {
281284 // SPARC systems use a different naming scheme
282285 @export(@import("compiler_rt/sparc.zig")._Qp_add, .{ .name = "_Qp_add", .linkage = linkage });
283286 @export(@import("compiler_rt/sparc.zig")._Qp_div, .{ .name = "_Qp_div", .linkage = linkage });
......@@ -334,7 +337,7 @@ comptime {
334337 @export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
335338 }
336339
337 switch (builtin.arch) {
340 switch (arch) {
338341 .i386 => {
339342 @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });
340343 @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });
lib/std/special/compiler_rt/atomics.zig+3-2
......@@ -5,6 +5,7 @@
55// and substantial portions of the software.
66const std = @import("std");
77const builtin = std.builtin;
8const arch = std.Target.current.cpu.arch;
89
910const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
1011
......@@ -13,7 +14,7 @@ const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak
1314// Some architectures support atomic load/stores but no CAS, but we ignore this
1415// detail to keep the export logic clean and because we need some kind of CAS to
1516// implement the spinlocks.
16const supports_atomic_ops = switch (builtin.arch) {
17const supports_atomic_ops = switch (arch) {
1718 .msp430, .avr => false,
1819 .arm, .armeb, .thumb, .thumbeb =>
1920 // 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) {
2728// The size (in bytes) of the biggest object that the architecture can
2829// load/store atomically.
2930// Objects bigger than this threshold require the use of a lock.
30const largest_atomic_size = switch (builtin.arch) {
31const largest_atomic_size = switch (arch) {
3132 // XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b
3233 // and set this parameter accordingly.
3334 else => @sizeOf(usize),
lib/std/special/compiler_rt/muldi3.zig+6-4
......@@ -3,14 +3,16 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const std = @import("std");
7const is_test = std.builtin.is_test;
8const native_endian = std.Target.current.cpu.arch.endian();
79
810// Ported from
911// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
1012
1113const dwords = extern union {
1214 all: i64,
13 s: switch (builtin.endian) {
15 s: switch (native_endian) {
1416 .Little => extern struct {
1517 low: u32,
1618 high: u32,
......@@ -23,7 +25,7 @@ const dwords = extern union {
2325};
2426
2527fn __muldsi3(a: u32, b: u32) i64 {
26 @setRuntimeSafety(builtin.is_test);
28 @setRuntimeSafety(is_test);
2729
2830 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
2931 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
......@@ -45,7 +47,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
4547}
4648
4749pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
48 @setRuntimeSafety(builtin.is_test);
50 @setRuntimeSafety(is_test);
4951
5052 const x = dwords{ .all = a };
5153 const y = dwords{ .all = b };
lib/std/special/compiler_rt/multi3.zig+5-3
......@@ -3,15 +3,17 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
76const compiler_rt = @import("../compiler_rt.zig");
7const std = @import("std");
8const is_test = std.builtin.is_test;
9const native_endian = std.Target.current.cpu.arch.endian();
810
911// Ported from git@github.com:llvm-project/llvm-project-20170507.git
1012// ae684fad6d34858c014c94da69c15e7774a633c3
1113// 2018-08-13
1214
1315pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
14 @setRuntimeSafety(builtin.is_test);
16 @setRuntimeSafety(is_test);
1517 const x = twords{ .all = a };
1618 const y = twords{ .all = b };
1719 var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };
......@@ -50,7 +52,7 @@ const twords = extern union {
5052 all: i128,
5153 s: S,
5254
53 const S = if (builtin.endian == .Little)
55 const S = if (native_endian == .Little)
5456 struct {
5557 low: u64,
5658 high: u64,
lib/std/special/compiler_rt/shift.zig+2-2
......@@ -4,8 +4,8 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("std");
7const builtin = std.builtin;
87const Log2Int = std.math.Log2Int;
8const native_endian = std.Target.current.cpu.arch.endian();
99
1010fn Dwords(comptime T: type, comptime signed_half: bool) type {
1111 return extern union {
......@@ -15,7 +15,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {
1515 pub const HalfT = if (signed_half) HalfTS else HalfTU;
1616
1717 all: T,
18 s: if (builtin.endian == .Little)
18 s: if (native_endian == .Little)
1919 struct { low: HalfT, high: HalfT }
2020 else
2121 struct { high: HalfT, low: HalfT },
lib/std/special/compiler_rt/stack_probe.zig+5-5
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const native_arch = @import("std").Target.current.cpu.arch;
77
88// Zig's own stack-probe routine (available only on x86 and x86_64)
99pub fn zig_probe_stack() callconv(.Naked) void {
......@@ -13,7 +13,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
1313 // invalid so let's update it on the go, otherwise we'll get a segfault
1414 // instead of triggering the stack growth.
1515
16 switch (builtin.arch) {
16 switch (native_arch) {
1717 .x86_64 => {
1818 // %rax = probe length, %rsp = stack pointer
1919 asm volatile (
......@@ -65,7 +65,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
6565fn win_probe_stack_only() void {
6666 @setRuntimeSafety(false);
6767
68 switch (builtin.arch) {
68 switch (native_arch) {
6969 .x86_64 => {
7070 asm volatile (
7171 \\ push %%rcx
......@@ -117,7 +117,7 @@ fn win_probe_stack_only() void {
117117fn win_probe_stack_adjust_sp() void {
118118 @setRuntimeSafety(false);
119119
120 switch (builtin.arch) {
120 switch (native_arch) {
121121 .x86_64 => {
122122 asm volatile (
123123 \\ push %%rcx
......@@ -191,7 +191,7 @@ pub fn _chkstk() callconv(.Naked) void {
191191}
192192pub fn __chkstk() callconv(.Naked) void {
193193 @setRuntimeSafety(false);
194 switch (builtin.arch) {
194 switch (native_arch) {
195195 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),
196196 .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),
197197 else => unreachable,
lib/std/special/compiler_rt/udivmod.zig+2-1
......@@ -5,8 +5,9 @@
55// and substantial portions of the software.
66const builtin = @import("builtin");
77const is_test = builtin.is_test;
8const native_endian = @import("std").Target.current.cpu.arch.endian();
89
9const low = switch (builtin.endian) {
10const low = switch (native_endian) {
1011 .Big => 1,
1112 .Little => 0,
1213};
lib/std/start.zig+13-13
......@@ -11,10 +11,12 @@ const builtin = @import("builtin");
1111const assert = std.debug.assert;
1212const uefi = std.os.uefi;
1313const tlcsprng = @import("crypto/tlcsprng.zig");
14const native_arch = std.Target.current.cpu.arch;
15const native_os = std.Target.current.os.tag;
1416
1517var argc_argv_ptr: [*]usize = undefined;
1618
17const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start";
19const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start";
1820
1921comptime {
2022 // The self-hosted compiler is not fully capable of handling all of this start.zig file.
......@@ -23,9 +25,7 @@ comptime {
2325 if (builtin.zig_is_stage2) {
2426 if (builtin.output_mode == .Exe) {
2527 if (builtin.link_libc or builtin.object_format == .c) {
26 if (!@hasDecl(root, "main")) {
27 @export(main2, "main");
28 }
28 @export(main2, "main");
2929 } else {
3030 if (!@hasDecl(root, "_start")) {
3131 @export(_start2, "_start");
......@@ -34,7 +34,7 @@ comptime {
3434 }
3535 } else {
3636 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
37 if (builtin.os.tag == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
37 if (native_os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
3838 @export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" });
3939 }
4040 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
......@@ -42,7 +42,7 @@ comptime {
4242 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
4343 @export(main, .{ .name = "main", .linkage = .Weak });
4444 }
45 } else if (builtin.os.tag == .windows) {
45 } else if (native_os == .windows) {
4646 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
4747 !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
4848 {
......@@ -56,11 +56,11 @@ comptime {
5656 {
5757 @export(wWinMainCRTStartup, .{ .name = "wWinMainCRTStartup" });
5858 }
59 } else if (builtin.os.tag == .uefi) {
59 } else if (native_os == .uefi) {
6060 if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
61 } else if (builtin.arch.isWasm() and builtin.os.tag == .freestanding) {
61 } else if (native_arch.isWasm() and native_os == .freestanding) {
6262 if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
63 } else if (builtin.os.tag != .other and builtin.os.tag != .freestanding) {
63 } else if (native_os != .other and native_os != .freestanding) {
6464 if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
6565 }
6666 }
......@@ -80,7 +80,7 @@ fn _start2() callconv(.Naked) noreturn {
8080}
8181
8282fn exit2(code: u8) noreturn {
83 switch (builtin.arch) {
83 switch (native_arch) {
8484 .x86_64 => {
8585 asm volatile ("syscall"
8686 :
......@@ -157,13 +157,13 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv
157157}
158158
159159fn _start() callconv(.Naked) noreturn {
160 if (builtin.os.tag == .wasi) {
160 if (native_os == .wasi) {
161161 // This is marked inline because for some reason LLVM in release mode fails to inline it,
162162 // and we want fewer call frames in stack traces.
163163 std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{}));
164164 }
165165
166 switch (builtin.arch) {
166 switch (native_arch) {
167167 .x86_64 => {
168168 argc_argv_ptr = asm volatile (
169169 \\ xor %%rbp, %%rbp
......@@ -273,7 +273,7 @@ fn posixCallMainAndExit() noreturn {
273273 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
274274 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
275275
276 if (builtin.os.tag == .linux) {
276 if (native_os == .linux) {
277277 // Find the beginning of the auxiliary vector
278278 const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));
279279 std.os.linux.elf_aux_maybe = auxv;
lib/std/target.zig+1-5
......@@ -1225,11 +1225,7 @@ pub const Target = struct {
12251225 }
12261226 };
12271227
1228 pub const current = Target{
1229 .cpu = builtin.cpu,
1230 .os = builtin.os,
1231 .abi = builtin.abi,
1232 };
1228 pub const current = builtin.target;
12331229
12341230 pub const stack_align = 16;
12351231
lib/std/testing.zig+1-1
......@@ -309,7 +309,7 @@ pub const TmpDir = struct {
309309};
310310
311311fn getCwdOrWasiPreopen() std.fs.Dir {
312 if (@import("builtin").os.tag == .wasi) {
312 if (std.builtin.os.tag == .wasi) {
313313 var preopens = std.fs.wasi.PreopenList.init(allocator);
314314 defer preopens.deinit();
315315 preopens.populate() catch
lib/std/unicode.zig+1-1
......@@ -4,7 +4,7 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66const std = @import("./std.zig");
7const builtin = @import("builtin");
7const builtin = std.builtin;
88const assert = std.debug.assert;
99const testing = std.testing;
1010const mem = std.mem;
lib/std/valgrind.zig+1-1
......@@ -3,7 +3,7 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6const builtin = @import("builtin");
6const builtin = std.builtin;
77const std = @import("std.zig");
88const math = std.math;
99
lib/std/zig/system.zig+2-1
......@@ -14,6 +14,7 @@ const process = std.process;
1414const Target = std.Target;
1515const CrossTarget = std.zig.CrossTarget;
1616const macos = @import("system/macos.zig");
17const native_endian = std.Target.current.cpu.arch.endian();
1718pub const windows = @import("system/windows.zig");
1819
1920pub const getSDKPath = macos.getSDKPath;
......@@ -603,7 +604,7 @@ pub const NativeTargetInfo = struct {
603604 elf.ELFDATA2MSB => .Big,
604605 else => return error.InvalidElfEndian,
605606 };
606 const need_bswap = elf_endian != std.builtin.endian;
607 const need_bswap = elf_endian != native_endian;
607608 if (hdr32.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
608609
609610 const is_64 = switch (hdr32.e_ident[elf.EI_CLASS]) {