From 6115cf22404467fd13d0290fc022d51d372d139a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 4 Oct 2021 23:47:27 -0700 Subject: [PATCH] migrate from `std.Target.current` to `@import("builtin").target` closes #9388 closes #9321 --- doc/docgen.zig | 4 +- doc/langref.html.in | 11 +- lib/std/Progress.zig | 7 +- lib/std/Thread/AutoResetEvent.zig | 2 +- lib/std/Thread/Condition.zig | 9 +- lib/std/Thread/Futex.zig | 7 +- lib/std/Thread/Mutex.zig | 6 +- lib/std/Thread/ResetEvent.zig | 4 +- lib/std/Thread/StaticResetEvent.zig | 7 +- lib/std/array_hash_map.zig | 1 - lib/std/atomic.zig | 2 +- lib/std/atomic/Atomic.zig | 2 +- lib/std/atomic/queue.zig | 2 +- lib/std/atomic/stack.zig | 4 +- lib/std/build.zig | 42 ++-- lib/std/build/OptionsStep.zig | 3 +- lib/std/build/RunStep.zig | 2 +- lib/std/builtin.zig | 45 ++-- lib/std/c.zig | 4 +- lib/std/c/darwin.zig | 4 +- lib/std/child_process.zig | 8 +- lib/std/coff.zig | 1 - lib/std/crypto.zig | 2 +- lib/std/crypto/aes.zig | 14 +- lib/std/crypto/aes/aesni.zig | 3 +- lib/std/crypto/aes_gcm.zig | 5 +- lib/std/crypto/aes_ocb.zig | 7 +- lib/std/crypto/benchmark.zig | 2 +- lib/std/crypto/blake3.zig | 3 +- lib/std/crypto/chacha20.zig | 3 +- lib/std/crypto/ghash.zig | 15 +- lib/std/crypto/gimli.zig | 21 +- lib/std/crypto/modes.zig | 3 +- lib/std/crypto/pcurves/common.zig | 7 +- lib/std/crypto/pcurves/p256.zig | 9 +- lib/std/crypto/pcurves/p256/p256_64.zig | 2 +- .../crypto/pcurves/p256/p256_scalar_64.zig | 2 +- lib/std/crypto/pcurves/p256/scalar.zig | 29 ++- lib/std/crypto/salsa20.zig | 3 +- lib/std/crypto/tlcsprng.zig | 9 +- lib/std/cstr.zig | 2 +- lib/std/debug.zig | 22 +- lib/std/dwarf.zig | 15 +- lib/std/dynamic_library.zig | 3 +- lib/std/event/channel.zig | 2 +- lib/std/event/future.zig | 2 +- lib/std/event/group.zig | 2 +- lib/std/event/lock.zig | 2 +- lib/std/event/loop.zig | 8 +- lib/std/event/rwlock.zig | 2 +- lib/std/event/wait_group.zig | 2 +- lib/std/fs.zig | 10 +- lib/std/fs/file.zig | 6 +- lib/std/fs/get_app_data_dir.zig | 2 +- lib/std/fs/test.zig | 2 +- lib/std/fs/wasi.zig | 3 +- lib/std/fs/watch.zig | 4 +- lib/std/hash/auto_hash.zig | 3 +- lib/std/hash/benchmark.zig | 2 +- lib/std/hash/cityhash.zig | 1 - lib/std/hash/crc.zig | 3 +- lib/std/heap.zig | 20 +- lib/std/heap/general_purpose_allocator.zig | 15 +- lib/std/io.zig | 2 +- lib/std/io/bit_reader.zig | 5 +- lib/std/io/bit_writer.zig | 5 +- lib/std/io/c_writer.zig | 2 +- lib/std/io/reader.zig | 9 +- lib/std/io/stream_source.zig | 3 +- lib/std/io/writer.zig | 5 +- lib/std/log.zig | 4 +- lib/std/mem.zig | 7 +- lib/std/meta.zig | 5 +- lib/std/meta/trait.zig | 7 +- lib/std/net.zig | 6 +- lib/std/net/test.zig | 24 +- lib/std/once.zig | 2 +- lib/std/os.zig | 52 ++--- lib/std/os/linux.zig | 17 +- lib/std/os/linux/bpf/kern.zig | 3 +- lib/std/os/linux/io_uring.zig | 2 +- lib/std/os/linux/start_pie.zig | 2 +- lib/std/os/linux/test.zig | 2 +- lib/std/os/linux/tls.zig | 2 +- lib/std/os/windows/user32.zig | 3 +- lib/std/pdb.zig | 1 - lib/std/process.zig | 6 +- lib/std/rand.zig | 1 - lib/std/rand/ziggurat.zig | 21 +- lib/std/sort.zig | 1 - lib/std/special/compiler_rt.zig | 4 +- lib/std/special/compiler_rt/atomics.zig | 10 +- lib/std/special/compiler_rt/clear_cache.zig | 7 +- lib/std/special/compiler_rt/count0bits.zig | 16 +- lib/std/special/compiler_rt/emutls.zig | 3 +- lib/std/special/compiler_rt/muldi3.zig | 5 +- lib/std/special/compiler_rt/multi3.zig | 5 +- lib/std/special/compiler_rt/shift.zig | 2 +- lib/std/special/compiler_rt/stack_probe.zig | 2 +- lib/std/special/compiler_rt/udivmod.zig | 2 +- lib/std/special/ssp.zig | 31 ++- lib/std/std.zig | 2 +- lib/std/target.zig | 6 +- lib/std/testing.zig | 5 +- lib/std/time.zig | 10 +- lib/std/unicode.zig | 1 - lib/std/unicode/throughput_test.zig | 1 - lib/std/x/net/tcp.zig | 3 +- lib/std/x/os/io.zig | 3 +- lib/std/x/os/net.zig | 3 +- lib/std/x/os/socket.zig | 5 +- lib/std/zig/cross_target.zig | 25 +- lib/std/zig/system.zig | 27 +-- lib/std/zig/system/darwin/macos.zig | 3 +- lib/std/zig/system/linux.zig | 3 +- src/Air.zig | 3 +- src/Cache.zig | 13 +- src/Compilation.zig | 6 +- src/ThreadPool.zig | 5 +- src/Zir.zig | 3 +- src/codegen.zig | 3 +- src/codegen/c.zig | 3 +- src/introspect.zig | 3 +- src/libc_installation.zig | 8 +- src/link.zig | 4 +- src/link/Elf.zig | 10 +- src/link/MachO.zig | 2 +- src/link/MachO/fat.zig | 4 +- src/main.zig | 19 +- src/tracy.zig | 5 +- test/assemble_and_link.zig | 3 +- test/behavior/asm.zig | 3 +- test/behavior/atomics.zig | 2 +- .../namespace_depends_on_compile_var.zig | 3 +- test/behavior/sizeof_and_typeof.zig | 1 - test/behavior/sizeof_and_typeof_stage1.zig | 1 - test/behavior/vector.zig | 2 +- test/cli.zig | 3 +- test/compare_output.zig | 6 +- test/compile_errors.zig | 6 +- test/src/compare_output.zig | 3 +- test/standalone.zig | 9 +- test/standalone/c_compiler/build.zig | 5 +- test/standalone/install_raw_hex/build.zig | 220 +++++++++--------- test/tests.zig | 14 +- test/translate_c.zig | 13 +- tools/update_cpu_features.zig | 3 +- 147 files changed, 624 insertions(+), 596 deletions(-) diff --git a/doc/docgen.zig b/doc/docgen.zig index 148a8bedb7..0ba44df267 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -1334,7 +1334,7 @@ fn genHtml( if (mem.startsWith(u8, triple, "wasm32") or mem.startsWith(u8, triple, "riscv64-linux") or (mem.startsWith(u8, triple, "x86_64-linux") and - std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64)) + builtin.os.tag != .linux or builtin.cpu.arch != .x86_64)) { // skip execution break :code_block; @@ -1602,7 +1602,7 @@ fn genHtml( Code.Id.Lib => { const bin_basename = try std.zig.binNameAlloc(allocator, .{ .root_name = code.name, - .target = std.Target.current, + .target = builtin.target, .output_mode = .Lib, }); diff --git a/doc/langref.html.in b/doc/langref.html.in index 772565a604..4c4c24a005 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2681,6 +2681,7 @@ test "pointer child type" {

{#code_begin|test|variable_alignment#} const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; test "variable alignment" { @@ -2688,7 +2689,7 @@ test "variable alignment" { const align_of_i32 = @alignOf(@TypeOf(x)); try expect(@TypeOf(&x) == *i32); try expect(*i32 == *align(align_of_i32) i32); - if (std.Target.current.cpu.arch == .x86_64) { + if (builtin.target.cpu.arch == .x86_64) { try expect(@typeInfo(*i32).Pointer.alignment == 4); } } @@ -3878,6 +3879,7 @@ test "separate scopes" { {#header_open|switch#} {#code_begin|test|switch#} const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; test "switch simple" { @@ -3922,7 +3924,7 @@ test "switch simple" { } // Switch expressions can be used outside a function: -const os_msg = switch (std.Target.current.os.tag) { +const os_msg = switch (builtin.target.os.tag) { .linux => "we found a linux user", else => "not a linux user", }; @@ -3930,7 +3932,7 @@ const os_msg = switch (std.Target.current.os.tag) { // Inside a function, switch statements implicitly are compile-time // evaluated if the target expression is compile-time known. test "switch inside function" { - switch (std.Target.current.os.tag) { + switch (builtin.target.os.tag) { .fuchsia => { // On an OS other than fuchsia, block is not even analyzed, // so this compile error is not triggered. @@ -5690,6 +5692,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {

{#code_begin|test|test_integer_widening#} const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; const mem = std.mem; @@ -5712,7 +5715,7 @@ test "implicit unsigned integer to signed integer" { test "float widening" { // Note: there is an open issue preventing this from working on aarch64: // https://github.com/ziglang/zig/issues/3282 - if (std.Target.current.cpu.arch == .aarch64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .aarch64) return error.SkipZigTest; var a: f16 = 12.34; var b: f32 = a; diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index e99b298c1e..0625fbaad9 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -7,6 +7,7 @@ //! * `initial_delay_ms` const std = @import("std"); +const builtin = @import("builtin"); const windows = std.os.windows; const testing = std.testing; const assert = std.debug.assert; @@ -144,10 +145,10 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) !* if (stderr.supportsAnsiEscapeCodes()) { self.terminal = stderr; self.supports_ansi_escape_codes = true; - } else if (std.builtin.os.tag == .windows and stderr.isTty()) { + } else if (builtin.os.tag == .windows and stderr.isTty()) { self.is_windows_terminal = true; self.terminal = stderr; - } else if (std.builtin.os.tag != .windows) { + } else if (builtin.os.tag != .windows) { // we are in a "dumb" terminal like in acme or writing to a file self.terminal = stderr; } @@ -200,7 +201,7 @@ fn refreshWithHeldLock(self: *Progress) void { if (self.supports_ansi_escape_codes) { end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{d}D", .{self.columns_written}) catch unreachable).len; end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len; - } else if (std.builtin.os.tag == .windows) winapi: { + } else if (builtin.os.tag == .windows) winapi: { std.debug.assert(self.is_windows_terminal); var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; diff --git a/lib/std/Thread/AutoResetEvent.zig b/lib/std/Thread/AutoResetEvent.zig index 49639d60e9..f22b1e3db0 100644 --- a/lib/std/Thread/AutoResetEvent.zig +++ b/lib/std/Thread/AutoResetEvent.zig @@ -26,7 +26,7 @@ state: usize = UNSET, const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const testing = std.testing; const assert = std.debug.assert; const StaticResetEvent = std.Thread.StaticResetEvent; diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig index d08a7c3c96..658817fc08 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -5,6 +5,7 @@ impl: Impl = .{}, const std = @import("../std.zig"); +const builtin = @import("builtin"); const Condition = @This(); const windows = std.os.windows; const linux = std.os.linux; @@ -23,9 +24,9 @@ pub fn broadcast(cond: *Condition) void { cond.impl.broadcast(); } -const Impl = if (std.builtin.single_threaded) +const Impl = if (builtin.single_threaded) SingleThreadedCondition -else if (std.Target.current.os.tag == .windows) +else if (builtin.os.tag == .windows) WindowsCondition else if (std.Thread.use_pthreads) PthreadCondition @@ -101,7 +102,7 @@ pub const AtomicCondition = struct { fn wait(cond: *@This()) void { while (@atomicLoad(i32, &cond.futex, .Acquire) == 0) { - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => { switch (linux.getErrno(linux.futex_wait( &cond.futex, @@ -123,7 +124,7 @@ pub const AtomicCondition = struct { fn notify(cond: *@This()) void { @atomicStore(i32, &cond.futex, 1, .Release); - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => { switch (linux.getErrno(linux.futex_wake( &cond.futex, diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig index 8411041166..7c73d54017 100644 --- a/lib/std/Thread/Futex.zig +++ b/lib/std/Thread/Futex.zig @@ -4,10 +4,11 @@ //! Using Futex, other Thread synchronization primitives can be built which efficiently wait for cross-thread events or signals. const std = @import("../std.zig"); +const builtin = @import("builtin"); const Futex = @This(); -const target = std.Target.current; -const single_threaded = std.builtin.single_threaded; +const target = builtin.target; +const single_threaded = builtin.single_threaded; const assert = std.debug.assert; const testing = std.testing; @@ -70,7 +71,7 @@ else if (target.os.tag == .linux) LinuxFutex else if (target.isDarwin()) DarwinFutex -else if (std.builtin.link_libc) +else if (builtin.link_libc) PosixFutex else UnsupportedFutex; diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig index 7473d9ec7f..db9a2408b8 100644 --- a/lib/std/Thread/Mutex.zig +++ b/lib/std/Thread/Mutex.zig @@ -24,7 +24,7 @@ impl: Impl = .{}, const Mutex = @This(); const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const os = std.os; const assert = std.debug.assert; const windows = os.windows; @@ -160,7 +160,7 @@ pub const AtomicMutex = struct { .unlocked => return, else => {}, } - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => { switch (linux.getErrno(linux.futex_wait( @ptrCast(*const i32, &m.state), @@ -182,7 +182,7 @@ pub const AtomicMutex = struct { fn unlockSlow(m: *AtomicMutex) void { @setCold(true); - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => { switch (linux.getErrno(linux.futex_wake( @ptrCast(*const i32, &m.state), diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig index d85cf7f133..7fc4f3c2b4 100644 --- a/lib/std/Thread/ResetEvent.zig +++ b/lib/std/Thread/ResetEvent.zig @@ -8,7 +8,7 @@ const ResetEvent = @This(); const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const testing = std.testing; const assert = std.debug.assert; const c = std.c; @@ -19,7 +19,7 @@ impl: Impl, pub const Impl = if (builtin.single_threaded) std.Thread.StaticResetEvent.DebugEvent -else if (std.Target.current.isDarwin()) +else if (builtin.target.isDarwin()) DarwinEvent else if (std.Thread.use_pthreads) PosixEvent diff --git a/lib/std/Thread/StaticResetEvent.zig b/lib/std/Thread/StaticResetEvent.zig index 29fdf3e489..b115206632 100644 --- a/lib/std/Thread/StaticResetEvent.zig +++ b/lib/std/Thread/StaticResetEvent.zig @@ -8,6 +8,7 @@ //! the logic needs stronger API guarantees. const std = @import("../std.zig"); +const builtin = @import("builtin"); const StaticResetEvent = @This(); const assert = std.debug.assert; const os = std.os; @@ -18,7 +19,7 @@ const testing = std.testing; impl: Impl = .{}, -pub const Impl = if (std.builtin.single_threaded) +pub const Impl = if (builtin.single_threaded) DebugEvent else AtomicEvent; @@ -162,7 +163,7 @@ pub const AtomicEvent = struct { @atomicStore(u32, &ev.waiters, 0, .Monotonic); } - pub const Futex = switch (std.Target.current.os.tag) { + pub const Futex = switch (builtin.os.tag) { .windows => WindowsFutex, .linux => LinuxFutex, else => SpinFutex, @@ -322,7 +323,7 @@ test "basic usage" { try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1)); // test cross-thread signaling - if (std.builtin.single_threaded) + if (builtin.single_threaded) return; const Context = struct { diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 42443f2138..83d5c73a00 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -9,7 +9,6 @@ const trait = meta.trait; const autoHash = std.hash.autoHash; const Wyhash = std.hash.Wyhash; const Allocator = mem.Allocator; -const builtin = std.builtin; const hash_map = @This(); /// An ArrayHashMap with default hash and equal functions. diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig index 95d218736a..b1b5789b02 100644 --- a/lib/std/atomic.zig +++ b/lib/std/atomic.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const target = std.Target.current; +const target = @import("builtin").target; pub const Ordering = std.builtin.AtomicOrder; diff --git a/lib/std/atomic/Atomic.zig b/lib/std/atomic/Atomic.zig index 98c4cb95f7..336230333a 100644 --- a/lib/std/atomic/Atomic.zig +++ b/lib/std/atomic/Atomic.zig @@ -1,7 +1,7 @@ const std = @import("../std.zig"); const testing = std.testing; -const target = std.Target.current; +const target = @import("builtin").target; const Ordering = std.atomic.Ordering; pub fn Atomic(comptime T: type) type { diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index f3781b4ce7..b93b4b7c07 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const expect = std.testing.expect; diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index a1747db0f5..1005195b29 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -1,5 +1,6 @@ +const std = @import("../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; -const builtin = std.builtin; const expect = std.testing.expect; /// Many reader, many writer, non-allocating, thread-safe @@ -67,7 +68,6 @@ pub fn Stack(comptime T: type) type { }; } -const std = @import("../std.zig"); const Context = struct { allocator: *std.mem.Allocator, stack: *Stack(i32), diff --git a/lib/std/build.zig b/lib/std/build.zig index 58fc94503f..228c50cd20 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const io = std.io; const fs = std.fs; const mem = std.mem; @@ -62,7 +62,7 @@ pub const Builder = struct { build_root: []const u8, cache_root: []const u8, global_cache_root: []const u8, - release_mode: ?builtin.Mode, + release_mode: ?std.builtin.Mode, is_release: bool, override_lib_dir: ?[]const u8, vcpkg_root: VcpkgRoot, @@ -633,18 +633,18 @@ pub const Builder = struct { } /// This provides the -Drelease option to the build user and does not give them the choice. - pub fn setPreferredReleaseMode(self: *Builder, mode: builtin.Mode) void { + pub fn setPreferredReleaseMode(self: *Builder, mode: std.builtin.Mode) void { if (self.release_mode != null) { @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice"); } const description = self.fmt("Create a release build ({s})", .{@tagName(mode)}); self.is_release = self.option(bool, "release", description) orelse false; - self.release_mode = if (self.is_release) mode else builtin.Mode.Debug; + self.release_mode = if (self.is_release) mode else std.builtin.Mode.Debug; } /// If you call this without first calling `setPreferredReleaseMode` then it gives the build user /// the choice of what kind of release. - pub fn standardReleaseOptions(self: *Builder) builtin.Mode { + pub fn standardReleaseOptions(self: *Builder) std.builtin.Mode { if (self.release_mode) |mode| return mode; const release_safe = self.option(bool, "release-safe", "Optimizations on and safety on") orelse false; @@ -652,17 +652,17 @@ pub const Builder = struct { const release_small = self.option(bool, "release-small", "Size optimizations on and safety off") orelse false; const mode = if (release_safe and !release_fast and !release_small) - builtin.Mode.ReleaseSafe + std.builtin.Mode.ReleaseSafe else if (release_fast and !release_safe and !release_small) - builtin.Mode.ReleaseFast + std.builtin.Mode.ReleaseFast else if (release_small and !release_fast and !release_safe) - builtin.Mode.ReleaseSmall + std.builtin.Mode.ReleaseSmall else if (!release_fast and !release_safe and !release_small) - builtin.Mode.Debug + std.builtin.Mode.Debug else x: { warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)\n\n", .{}); self.markInvalidUserInput(); - break :x builtin.Mode.Debug; + break :x std.builtin.Mode.Debug; }; self.is_release = mode != .Debug; self.release_mode = mode; @@ -1290,7 +1290,7 @@ test "builder.findProgram compiles" { } /// Deprecated. Use `std.builtin.Version`. -pub const Version = builtin.Version; +pub const Version = std.builtin.Version; /// Deprecated. Use `std.zig.CrossTarget`. pub const Target = std.zig.CrossTarget; @@ -1417,8 +1417,8 @@ pub const LibExeObjStep = struct { version_script: ?[]const u8 = null, out_filename: []const u8, linkage: ?Linkage = null, - version: ?Version, - build_mode: builtin.Mode, + version: ?std.builtin.Version, + build_mode: std.builtin.Mode, kind: Kind, major_only_filename: ?[]const u8, name_only_filename: ?[]const u8, @@ -1447,8 +1447,8 @@ pub const LibExeObjStep = struct { filter: ?[]const u8, single_threaded: bool, test_evented_io: bool = false, - code_model: builtin.CodeModel = .default, - wasi_exec_model: ?builtin.WasiExecModel = null, + code_model: std.builtin.CodeModel = .default, + wasi_exec_model: ?std.builtin.WasiExecModel = null, root_src: ?FileSource, out_h_filename: []const u8, @@ -1550,7 +1550,7 @@ pub const LibExeObjStep = struct { }; const SharedLibKind = union(enum) { - versioned: Version, + versioned: std.builtin.Version, unversioned: void, }; @@ -1585,7 +1585,7 @@ pub const LibExeObjStep = struct { root_src_raw: ?FileSource, kind: Kind, linkage: ?Linkage, - ver: ?Version, + ver: ?std.builtin.Version, ) *LibExeObjStep { const name = builder.dupe(name_raw); const root_src: ?FileSource = if (root_src_raw) |rsrc| rsrc.dupe(builder) else null; @@ -1599,7 +1599,7 @@ pub const LibExeObjStep = struct { .builder = builder, .verbose_link = false, .verbose_cc = false, - .build_mode = builtin.Mode.Debug, + .build_mode = std.builtin.Mode.Debug, .linkage = linkage, .kind = kind, .root_src = root_src, @@ -1988,7 +1988,7 @@ pub const LibExeObjStep = struct { self.verbose_cc = value; } - pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void { + pub fn setBuildMode(self: *LibExeObjStep, mode: std.builtin.Mode) void { self.build_mode = mode; } @@ -2553,7 +2553,7 @@ pub const LibExeObjStep = struct { const resolved_include_path = self.builder.pathFromRoot(include_path); - const common_include_path = if (std.Target.current.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: { + const common_include_path = if (builtin.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: { // We need to check for disk designator and strip it out from dir path so // that zig/clang can concat resolved_include_path with sysroot. const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path); @@ -3237,7 +3237,7 @@ test "LibExeObjStep.addPackage" { test { // The only purpose of this test is to get all these untested functions // to be referenced to avoid regression so it is okay to skip some targets. - if (comptime std.Target.current.cpu.arch.ptrBitWidth() == 64) { + if (comptime builtin.cpu.arch.ptrBitWidth() == 64) { std.testing.refAllDecls(@This()); std.testing.refAllDecls(Builder); diff --git a/lib/std/build/OptionsStep.zig b/lib/std/build/OptionsStep.zig index 2440fce16d..781c015742 100644 --- a/lib/std/build/OptionsStep.zig +++ b/lib/std/build/OptionsStep.zig @@ -1,4 +1,5 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const build = std.build; const fs = std.fs; const Step = build.Step; @@ -219,7 +220,7 @@ const OptionFileSourceArg = struct { }; test "OptionsStep" { - if (std.builtin.os.tag == .wasi) return error.SkipZigTest; + if (builtin.os.tag == .wasi) return error.SkipZigTest; var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); diff --git a/lib/std/build/RunStep.zig b/lib/std/build/RunStep.zig index 67929b6f5d..8a21c87f8e 100644 --- a/lib/std/build/RunStep.zig +++ b/lib/std/build/RunStep.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const build = std.build; const Step = build.Step; const Builder = build.Builder; diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index c0d2e9f725..289e1dee0d 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -1,26 +1,27 @@ const builtin = @import("builtin"); -// These are all deprecated. -pub const zig_version = builtin.zig_version; -pub const zig_is_stage2 = builtin.zig_is_stage2; -pub const output_mode = builtin.output_mode; -pub const link_mode = builtin.link_mode; -pub const is_test = builtin.is_test; -pub const single_threaded = builtin.single_threaded; -pub const abi = builtin.abi; -pub const cpu = builtin.cpu; -pub const os = builtin.os; -pub const target = builtin.target; -pub const object_format = builtin.object_format; -pub const mode = builtin.mode; -pub const link_libc = builtin.link_libc; -pub const link_libcpp = builtin.link_libcpp; -pub const have_error_return_tracing = builtin.have_error_return_tracing; -pub const valgrind_support = builtin.valgrind_support; -pub const position_independent_code = builtin.position_independent_code; -pub const position_independent_executable = builtin.position_independent_executable; -pub const strip_debug_info = builtin.strip_debug_info; -pub const code_model = builtin.code_model; +// TODO delete these after releasing 0.9.0 + +pub const zig_version = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const zig_is_stage2 = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const output_mode = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const link_mode = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const is_test = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const single_threaded = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const abi = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const cpu = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const os = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const target = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const object_format = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const mode = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const link_libc = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const link_libcpp = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const have_error_return_tracing = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const valgrind_support = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const position_independent_code = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const position_independent_executable = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const strip_debug_info = @compileError("get this from @import(\"builtin\") instead of std.builtin"); +pub const code_model = @compileError("get this from @import(\"builtin\") instead of std.builtin"); /// `explicit_subsystem` is missing when the subsystem is automatically detected, /// so Zig standard library has the subsystem detection logic here. This should generally be @@ -694,7 +695,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn @breakpoint(); } } - switch (os.tag) { + switch (builtin.os.tag) { .freestanding => { while (true) { @breakpoint(); diff --git a/lib/std/c.zig b/lib/std/c.zig index 84fbb59640..f827bd9185 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = std.builtin; +const builtin = @import("builtin"); const c = @This(); const page_size = std.mem.page_size; const iovec = std.os.iovec; @@ -20,7 +20,7 @@ pub const Tokenizer = tokenizer.Tokenizer; /// If linking gnu libc (glibc), the `ok` value will be true if the target /// version is greater than or equal to `glibc_version`. /// If linking a libc other than these, returns `false`. -pub fn versionCheck(glibc_version: builtin.Version) type { +pub fn versionCheck(glibc_version: std.builtin.Version) type { return struct { pub const ok = blk: { if (!builtin.link_libc) break :blk false; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index b85a5bc40f..0f79c537f3 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -1,6 +1,6 @@ const std = @import("../std.zig"); -const assert = std.debug.assert; const builtin = @import("builtin"); +const assert = std.debug.assert; const macho = std.macho; const native_arch = builtin.target.cpu.arch; const maxInt = std.math.maxInt; @@ -72,7 +72,7 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; var dummy_execute_header: mach_hdr = undefined; pub extern var _mh_execute_header: mach_hdr; comptime { - if (std.Target.current.isDarwin()) { + if (builtin.target.isDarwin()) { @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .Weak }); } } diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index b6f4f4c516..978a45a2cc 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -1,4 +1,5 @@ const std = @import("std.zig"); +const builtin = @import("builtin"); const cstr = std.cstr; const unicode = std.unicode; const io = std.io; @@ -12,8 +13,7 @@ const mem = std.mem; const math = std.math; const debug = std.debug; const BufMap = std.BufMap; -const builtin = std.builtin; -const Os = builtin.Os; +const Os = std.builtin.Os; const TailQueue = std.TailQueue; const maxInt = std.math.maxInt; const assert = std.debug.assert; @@ -561,9 +561,9 @@ pub const ChildProcess = struct { if (self.env_map) |env_map| { const envp_buf = try createNullDelimitedEnvMap(arena, env_map); break :m envp_buf.ptr; - } else if (std.builtin.link_libc) { + } else if (builtin.link_libc) { break :m std.c.environ; - } else if (std.builtin.output_mode == .Exe) { + } else if (builtin.output_mode == .Exe) { // Then we have Zig start code and this works. // TODO type-safety for null-termination of `os.environ`. break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr); diff --git a/lib/std/coff.zig b/lib/std/coff.zig index c8b0a44044..c3823f6c53 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -1,4 +1,3 @@ -const builtin = std.builtin; const std = @import("std.zig"); const io = std.io; const mem = std.mem; diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig index f052b0bb4f..c8e9968158 100644 --- a/lib/std/crypto.zig +++ b/lib/std/crypto.zig @@ -163,7 +163,7 @@ const std = @import("std.zig"); pub const errors = @import("crypto/errors.zig"); test "crypto" { - const please_windows_dont_oom = std.Target.current.os.tag == .windows; + const please_windows_dont_oom = @import("builtin").os.tag == .windows; if (please_windows_dont_oom) return error.SkipZigTest; inline for (std.meta.declarations(@This())) |decl| { diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index 18bae3978e..778cb80f8b 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -1,13 +1,13 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const testing = std.testing; -const builtin = std.builtin; -const has_aesni = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes); -const has_avx = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); -const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes); -const impl = if (std.Target.current.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { +const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes); +const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); +const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); +const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { break :impl @import("aes/aesni.zig"); -} else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) +} else if (builtin.cpu.arch == .aarch64 and has_armaes) impl: { break :impl @import("aes/armcrypto.zig"); } else impl: { @@ -41,7 +41,7 @@ test "ctr" { var out: [exp_out.len]u8 = undefined; var ctx = Aes128.initEnc(key); - ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big); + ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.Big); try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); } diff --git a/lib/std/crypto/aes/aesni.zig b/lib/std/crypto/aes/aesni.zig index ab11b5bc8b..b76e01e70b 100644 --- a/lib/std/crypto/aes/aesni.zig +++ b/lib/std/crypto/aes/aesni.zig @@ -1,4 +1,5 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const mem = std.mem; const debug = std.debug; const Vector = std.meta.Vector; @@ -97,7 +98,7 @@ pub const Block = struct { const cpu = std.Target.x86.cpu; /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation. - pub const optimal_parallel_blocks = switch (std.Target.current.cpu.model) { + pub const optimal_parallel_blocks = switch (builtin.cpu.model) { &cpu.westmere => 6, &cpu.sandybridge, &cpu.ivybridge => 8, &cpu.haswell, &cpu.broadwell => 7, diff --git a/lib/std/crypto/aes_gcm.zig b/lib/std/crypto/aes_gcm.zig index 2d1cefaa31..bb35bc9e8a 100644 --- a/lib/std/crypto/aes_gcm.zig +++ b/lib/std/crypto/aes_gcm.zig @@ -1,6 +1,5 @@ const std = @import("std"); const assert = std.debug.assert; -const builtin = std.builtin; const crypto = std.crypto; const debug = std.debug; const Ghash = std.crypto.onetimeauth.Ghash; @@ -40,7 +39,7 @@ fn AesGcm(comptime Aes: anytype) type { mac.pad(); mem.writeIntBig(u32, j[nonce_length..][0..4], 2); - modes.ctr(@TypeOf(aes), aes, c, m, j, builtin.Endian.Big); + modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.Big); mac.update(c[0..m.len][0..]); mac.pad(); @@ -94,7 +93,7 @@ fn AesGcm(comptime Aes: anytype) type { } mem.writeIntBig(u32, j[nonce_length..][0..4], 2); - modes.ctr(@TypeOf(aes), aes, m, c, j, builtin.Endian.Big); + modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big); } }; } diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig index 69c34afcda..cc50bbbe45 100644 --- a/lib/std/crypto/aes_ocb.zig +++ b/lib/std/crypto/aes_ocb.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const aes = crypto.core.aes; const assert = std.debug.assert; @@ -100,9 +101,9 @@ fn AesOcb(comptime Aes: anytype) type { return offset; } - const has_aesni = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes); - const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes); - const wb: usize = if ((std.Target.current.cpu.arch == .x86_64 and has_aesni) or (std.Target.current.cpu.arch == .aarch64 and has_armaes)) 4 else 0; + const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes); + const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); + const wb: usize = if ((builtin.cpu.arch == .x86_64 and has_aesni) or (builtin.cpu.arch == .aarch64 and has_armaes)) 4 else 0; /// c: ciphertext: output buffer should be of size m.len /// tag: authentication tag: output MAC diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig index 65e7ecb680..414880b1ca 100644 --- a/lib/std/crypto/benchmark.zig +++ b/lib/std/crypto/benchmark.zig @@ -1,7 +1,7 @@ // zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const mem = std.mem; const time = std.time; const Timer = time.Timer; diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig index 2e3f3f3c7b..b2077bb9e7 100644 --- a/lib/std/crypto/blake3.zig +++ b/lib/std/crypto/blake3.zig @@ -2,6 +2,7 @@ // Source: https://github.com/BLAKE3-team/BLAKE3 const std = @import("../std.zig"); +const builtin = @import("builtin"); const fmt = std.fmt; const math = std.math; const mem = std.mem; @@ -200,7 +201,7 @@ const CompressGeneric = struct { } }; -const compress = if (std.Target.current.cpu.arch == .x86_64) CompressVectorized.compress else CompressGeneric.compress; +const compress = if (builtin.cpu.arch == .x86_64) CompressVectorized.compress else CompressGeneric.compress; fn first8Words(words: [16]u32) [8]u32 { return @ptrCast(*const [8]u32, &words).*; diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index 11496034a0..8655121ce0 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -1,6 +1,7 @@ // Based on public domain Supercop by Daniel J. Bernstein const std = @import("../std.zig"); +const builtin = @import("builtin"); const math = std.math; const mem = std.mem; const assert = std.debug.assert; @@ -359,7 +360,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { } fn ChaChaImpl(comptime rounds_nb: usize) type { - return if (std.Target.current.cpu.arch == .x86_64) ChaChaVecImpl(rounds_nb) else ChaChaNonVecImpl(rounds_nb); + return if (builtin.cpu.arch == .x86_64) ChaChaVecImpl(rounds_nb) else ChaChaNonVecImpl(rounds_nb); } fn keyToWords(key: [32]u8) [8]u32 { diff --git a/lib/std/crypto/ghash.zig b/lib/std/crypto/ghash.zig index dfbc13993a..c24c16ce77 100644 --- a/lib/std/crypto/ghash.zig +++ b/lib/std/crypto/ghash.zig @@ -2,6 +2,7 @@ // Adapted from BearSSL's ctmul64 implementation originally written by Thomas Pornin const std = @import("../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; const math = std.math; const mem = std.mem; @@ -45,7 +46,7 @@ pub const Ghash = struct { const h2 = h0 ^ h1; const h2r = h0r ^ h1r; - if (std.builtin.mode == .ReleaseSmall) { + if (builtin.mode == .ReleaseSmall) { return Ghash{ .h0 = h0, .h1 = h1, @@ -132,12 +133,12 @@ pub const Ghash = struct { return z0 | z1 | z2 | z3; } - const has_pclmul = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .pclmul); - const has_avx = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); - const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes); - const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: { + const has_pclmul = std.Target.x86.featureSetHas(builtin.cpu.features, .pclmul); + const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); + const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); + const clmul = if (builtin.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: { break :impl clmul_pclmul; - } else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) impl: { + } else if (builtin.cpu.arch == .aarch64 and has_armaes) impl: { break :impl clmul_pmull; } else impl: { break :impl clmul_soft; @@ -151,7 +152,7 @@ pub const Ghash = struct { var i: usize = 0; // 2-blocks aggregated reduction - if (std.builtin.mode != .ReleaseSmall) { + if (builtin.mode != .ReleaseSmall) { while (i + 32 <= msg.len) : (i += 32) { // B0 * H^2 unreduced y1 ^= mem.readIntBig(u64, msg[i..][0..8]); diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig index c234213704..fc4b5313b8 100644 --- a/lib/std/crypto/gimli.zig +++ b/lib/std/crypto/gimli.zig @@ -1,13 +1,14 @@ -// Gimli is a 384-bit permutation designed to achieve high security with high -// performance across a broad range of platforms, including 64-bit Intel/AMD -// server CPUs, 64-bit and 32-bit ARM smartphone CPUs, 32-bit ARM -// microcontrollers, 8-bit AVR microcontrollers, FPGAs, ASICs without -// side-channel protection, and ASICs with side-channel protection. -// -// https://gimli.cr.yp.to/ -// https://csrc.nist.gov/CSRC/media/Projects/Lightweight-Cryptography/documents/round-1/spec-doc/gimli-spec.pdf +//! Gimli is a 384-bit permutation designed to achieve high security with high +//! performance across a broad range of platforms, including 64-bit Intel/AMD +//! server CPUs, 64-bit and 32-bit ARM smartphone CPUs, 32-bit ARM +//! microcontrollers, 8-bit AVR microcontrollers, FPGAs, ASICs without +//! side-channel protection, and ASICs with side-channel protection. +//! +//! https://gimli.cr.yp.to/ +//! https://csrc.nist.gov/CSRC/media/Projects/Lightweight-Cryptography/documents/round-1/spec-doc/gimli-spec.pdf const std = @import("../std.zig"); +const builtin = @import("builtin"); const mem = std.mem; const math = std.math; const debug = std.debug; @@ -152,9 +153,9 @@ pub const State = struct { self.endianSwap(); } - pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: { + pub const permute = if (builtin.cpu.arch == .x86_64) impl: { break :impl permute_vectorized; - } else if (std.builtin.mode == .ReleaseSmall) impl: { + } else if (builtin.mode == .ReleaseSmall) impl: { break :impl permute_small; } else impl: { break :impl permute_unrolled; diff --git a/lib/std/crypto/modes.zig b/lib/std/crypto/modes.zig index d2df2ce15a..325d8c0ceb 100644 --- a/lib/std/crypto/modes.zig +++ b/lib/std/crypto/modes.zig @@ -1,7 +1,6 @@ // Based on Go stdlib implementation const std = @import("../std.zig"); -const builtin = std.builtin; const mem = std.mem; const debug = std.debug; @@ -11,7 +10,7 @@ const debug = std.debug; /// /// Important: the counter mode doesn't provide authenticated encryption: the ciphertext can be trivially modified without this being detected. /// As a result, applications should generally never use it directly, but only in a construction that includes a MAC. -pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8, src: []const u8, iv: [BlockCipher.block_length]u8, endian: builtin.Endian) void { +pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8, src: []const u8, iv: [BlockCipher.block_length]u8, endian: std.builtin.Endian) void { debug.assert(dst.len >= src.len); const block_length = BlockCipher.block_length; var counter: [BlockCipher.block_length]u8 = undefined; diff --git a/lib/std/crypto/pcurves/common.zig b/lib/std/crypto/pcurves/common.zig index 32876910e1..917fd70fbd 100644 --- a/lib/std/crypto/pcurves/common.zig +++ b/lib/std/crypto/pcurves/common.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const crypto = std.crypto; const debug = std.debug; const mem = std.mem; @@ -51,7 +50,7 @@ pub fn Field(comptime params: FieldParams) type { }; /// Reject non-canonical encodings of an element. - pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: builtin.Endian) NonCanonicalError!void { + pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!void { var s = if (endian == .Little) s_ else orderSwap(s_); const field_order_s = comptime fos: { var fos: [encoded_length]u8 = undefined; @@ -71,7 +70,7 @@ pub fn Field(comptime params: FieldParams) type { } /// Unpack a field element. - pub fn fromBytes(s_: [encoded_length]u8, endian: builtin.Endian) NonCanonicalError!Fe { + pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { var s = if (endian == .Little) s_ else orderSwap(s_); try rejectNonCanonical(s, .Little); var limbs_z: NonMontgomeryDomainFieldElement = undefined; @@ -82,7 +81,7 @@ pub fn Field(comptime params: FieldParams) type { } /// Pack a field element. - pub fn toBytes(fe: Fe, endian: builtin.Endian) [encoded_length]u8 { + pub fn toBytes(fe: Fe, endian: std.builtin.Endian) [encoded_length]u8 { var limbs_z: NonMontgomeryDomainFieldElement = undefined; fiat.fromMontgomery(&limbs_z, fe.limbs); var s: [encoded_length]u8 = undefined; diff --git a/lib/std/crypto/pcurves/p256.zig b/lib/std/crypto/pcurves/p256.zig index 02410a8859..06aeed450f 100644 --- a/lib/std/crypto/pcurves/p256.zig +++ b/lib/std/crypto/pcurves/p256.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const crypto = std.crypto; const mem = std.mem; const meta = std.meta; @@ -59,7 +58,7 @@ pub const P256 = struct { } /// Create a point from serialized affine coordinates. - pub fn fromSerializedAffineCoordinates(xs: [32]u8, ys: [32]u8, endian: builtin.Endian) (NonCanonicalError || EncodingError)!P256 { + pub fn fromSerializedAffineCoordinates(xs: [32]u8, ys: [32]u8, endian: std.builtin.Endian) (NonCanonicalError || EncodingError)!P256 { const x = try Fe.fromBytes(xs, endian); const y = try Fe.fromBytes(ys, endian); return fromAffineCoordinates(.{ .x = x, .y = y }); @@ -396,7 +395,7 @@ pub const P256 = struct { /// Multiply an elliptic curve point by a scalar. /// Return error.IdentityElement if the result is the identity element. - pub fn mul(p: P256, s_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 { + pub fn mul(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { const s = if (endian == .Little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, false); @@ -408,7 +407,7 @@ pub const P256 = struct { /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* /// This can be used for signature verification. - pub fn mulPublic(p: P256, s_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 { + pub fn mulPublic(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { const s = if (endian == .Little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, true); @@ -420,7 +419,7 @@ pub const P256 = struct { /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* /// This can be used for signature verification. - pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 { + pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); try p1.rejectIdentity(); diff --git a/lib/std/crypto/pcurves/p256/p256_64.zig b/lib/std/crypto/pcurves/p256/p256_64.zig index 11c7652968..9d24bdc956 100644 --- a/lib/std/crypto/pcurves/p256/p256_64.zig +++ b/lib/std/crypto/pcurves/p256/p256_64.zig @@ -18,7 +18,7 @@ // if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256 const std = @import("std"); -const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels +const mode = @import("builtin").mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels // The type MontgomeryDomainFieldElement is a field element in the Montgomery domain. // Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] diff --git a/lib/std/crypto/pcurves/p256/p256_scalar_64.zig b/lib/std/crypto/pcurves/p256/p256_scalar_64.zig index 61b732203c..c6c08b4c46 100644 --- a/lib/std/crypto/pcurves/p256/p256_scalar_64.zig +++ b/lib/std/crypto/pcurves/p256/p256_scalar_64.zig @@ -18,7 +18,7 @@ // if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256 const std = @import("std"); -const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels +const mode = @import("builtin").mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels // The type MontgomeryDomainFieldElement is a field element in the Montgomery domain. // Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] diff --git a/lib/std/crypto/pcurves/p256/scalar.zig b/lib/std/crypto/pcurves/p256/scalar.zig index 265300a7a6..9ed52a85d8 100644 --- a/lib/std/crypto/pcurves/p256/scalar.zig +++ b/lib/std/crypto/pcurves/p256/scalar.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const common = @import("../common.zig"); const crypto = std.crypto; const debug = std.debug; @@ -26,47 +25,47 @@ const Fe = Field(.{ }); /// Reject a scalar whose encoding is not canonical. -pub fn rejectNonCanonical(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!void { +pub fn rejectNonCanonical(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!void { return Fe.rejectNonCanonical(s, endian); } /// Reduce a 48-bytes scalar to the field size. -pub fn reduce48(s: [48]u8, endian: builtin.Endian) CompressedScalar { +pub fn reduce48(s: [48]u8, endian: std.builtin.Endian) CompressedScalar { return Scalar.fromBytes48(s, endian).toBytes(endian); } /// Reduce a 64-bytes scalar to the field size. -pub fn reduce64(s: [64]u8, endian: builtin.Endian) CompressedScalar { +pub fn reduce64(s: [64]u8, endian: std.builtin.Endian) CompressedScalar { return ScalarDouble.fromBytes64(s, endian).toBytes(endian); } /// Return a*b (mod L) -pub fn mul(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar { +pub fn mul(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar { return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).toBytes(endian); } /// Return a*b+c (mod L) -pub fn mulAdd(a: CompressedScalar, b: CompressedScalar, c: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar { +pub fn mulAdd(a: CompressedScalar, b: CompressedScalar, c: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar { return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).add(try Scalar.fromBytes(c, endian)).toBytes(endian); } /// Return a+b (mod L) -pub fn add(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar { +pub fn add(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar { return (try Scalar.fromBytes(a, endian)).add(try Scalar.fromBytes(b, endian)).toBytes(endian); } /// Return -s (mod L) -pub fn neg(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar { +pub fn neg(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar { return (try Scalar.fromBytes(s, endian)).neg().toBytes(endian); } /// Return (a-b) (mod L) -pub fn sub(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar { +pub fn sub(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar { return (try Scalar.fromBytes(a, endian)).sub(try Scalar.fromBytes(b.endian)).toBytes(endian); } /// Return a random scalar -pub fn random(endian: builtin.Endian) CompressedScalar { +pub fn random(endian: std.builtin.Endian) CompressedScalar { return Scalar.random().toBytes(endian); } @@ -81,24 +80,24 @@ pub const Scalar = struct { pub const one = Scalar{ .fe = Fe.one }; /// Unpack a serialized representation of a scalar. - pub fn fromBytes(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!Scalar { + pub fn fromBytes(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!Scalar { return Scalar{ .fe = try Fe.fromBytes(s, endian) }; } /// Reduce a 384 bit input to the field size. - pub fn fromBytes48(s: [48]u8, endian: builtin.Endian) Scalar { + pub fn fromBytes48(s: [48]u8, endian: std.builtin.Endian) Scalar { const t = ScalarDouble.fromBytes(384, s, endian); return t.reduce(384); } /// Reduce a 512 bit input to the field size. - pub fn fromBytes64(s: [64]u8, endian: builtin.Endian) Scalar { + pub fn fromBytes64(s: [64]u8, endian: std.builtin.Endian) Scalar { const t = ScalarDouble.fromBytes(512, s, endian); return t.reduce(512); } /// Pack a scalar into bytes. - pub fn toBytes(n: Scalar, endian: builtin.Endian) CompressedScalar { + pub fn toBytes(n: Scalar, endian: std.builtin.Endian) CompressedScalar { return n.fe.toBytes(endian); } @@ -180,7 +179,7 @@ const ScalarDouble = struct { x2: Fe, x3: Fe, - fn fromBytes(comptime bits: usize, s_: [bits / 8]u8, endian: builtin.Endian) ScalarDouble { + fn fromBytes(comptime bits: usize, s_: [bits / 8]u8, endian: std.builtin.Endian) ScalarDouble { debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); var s = s_; diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig index 45dad75a8f..0e7d67b78f 100644 --- a/lib/std/crypto/salsa20.zig +++ b/lib/std/crypto/salsa20.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const debug = std.debug; const math = std.math; @@ -304,7 +305,7 @@ const Salsa20NonVecImpl = struct { } }; -const Salsa20Impl = if (std.Target.current.cpu.arch == .x86_64) Salsa20VecImpl else Salsa20NonVecImpl; +const Salsa20Impl = if (builtin.cpu.arch == .x86_64) Salsa20VecImpl else Salsa20NonVecImpl; fn keyToWords(key: [32]u8) [8]u32 { var k: [8]u32 = undefined; diff --git a/lib/std/crypto/tlcsprng.zig b/lib/std/crypto/tlcsprng.zig index d72262da53..3e92c0ae18 100644 --- a/lib/std/crypto/tlcsprng.zig +++ b/lib/std/crypto/tlcsprng.zig @@ -4,6 +4,7 @@ //! directly to standard library users. const std = @import("std"); +const builtin = @import("builtin"); const root = @import("root"); const mem = std.mem; const os = std.os; @@ -12,7 +13,7 @@ const os = std.os; /// point to thread-local variables. pub var interface = std.rand.Random{ .fillFn = tlsCsprngFill }; -const os_has_fork = switch (std.Target.current.os.tag) { +const os_has_fork = switch (builtin.os.tag) { .dragonfly, .freebsd, .ios, @@ -29,10 +30,10 @@ const os_has_fork = switch (std.Target.current.os.tag) { else => false, }; -const os_has_arc4random = std.builtin.link_libc and @hasDecl(std.c, "arc4random_buf"); +const os_has_arc4random = builtin.link_libc and @hasDecl(std.c, "arc4random_buf"); const want_fork_safety = os_has_fork and !os_has_arc4random and (std.meta.globalOption("crypto_fork_safety", bool) orelse true); -const maybe_have_wipe_on_fork = std.Target.current.os.isAtLeast(.linux, .{ +const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 14, }) orelse true; @@ -55,7 +56,7 @@ var install_atfork_handler = std.once(struct { threadlocal var wipe_mem: []align(mem.page_size) u8 = &[_]u8{}; fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void { - if (std.builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) { + if (builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) { // arc4random is already a thread-local CSPRNG. return std.c.arc4random_buf(buffer.ptr, buffer.len); } diff --git a/lib/std/cstr.zig b/lib/std/cstr.zig index 6de5672df3..64beb378d9 100644 --- a/lib/std/cstr.zig +++ b/lib/std/cstr.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const debug = std.debug; const mem = std.mem; const testing = std.testing; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 2194886c0a..36300e4691 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const math = std.math; const mem = std.mem; const io = std.io; @@ -16,8 +16,8 @@ const root = @import("root"); const maxInt = std.math.maxInt; const File = std.fs.File; const windows = std.os.windows; -const native_arch = std.Target.current.cpu.arch; -const native_os = std.Target.current.os.tag; +const native_arch = builtin.cpu.arch; +const native_os = builtin.os.tag; const native_endian = native_arch.endian(); pub const runtime_safety = switch (builtin.mode) { @@ -150,7 +150,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { /// capture that many stack frames exactly, and then look for the first address, /// chopping off the irrelevant frames and shifting so that the returned 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: *std.builtin.StackTrace) void { if (native_os == .windows) { const addrs = stack_trace.instruction_addresses; const u32_addrs_len = @intCast(u32, addrs.len); @@ -194,7 +194,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. /// TODO multithreaded awareness -pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { +pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void { nosuspend { const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { @@ -235,7 +235,7 @@ pub fn panic(comptime format: []const u8, args: anytype) noreturn { /// `panicExtra` is useful when you want to print out an `@errorReturnTrace` /// and also print out some values. pub fn panicExtra( - trace: ?*builtin.StackTrace, + trace: ?*std.builtin.StackTrace, comptime format: []const u8, args: anytype, ) noreturn { @@ -253,7 +253,7 @@ pub fn panicExtra( break :blk &buf; }, }; - builtin.panic(msg, trace); + std.builtin.panic(msg, trace); } /// Non-zero whenever the program triggered a panic. @@ -269,7 +269,7 @@ threadlocal var panic_stage: usize = 0; // `panicImpl` could be useful in implementing a custom panic handler which // calls the default handler (on supported platforms) -pub fn panicImpl(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn { +pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn { @setCold(true); if (enable_segfault_handler) { @@ -339,7 +339,7 @@ const DIM = "\x1b[2m"; const RESET = "\x1b[0m"; pub fn writeStackTrace( - stack_trace: builtin.StackTrace, + stack_trace: std.builtin.StackTrace, out_stream: anytype, allocator: *mem.Allocator, debug_info: *DebugInfo, @@ -764,7 +764,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic; if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; - const endian: builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { + const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { elf.ELFDATA2LSB => .Little, elf.ELFDATA2MSB => .Big, else => return error.InvalidElfEndian, @@ -1002,7 +1002,7 @@ pub const DebugInfo = struct { } pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo { - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { return self.lookupModuleDyld(address); } else if (native_os == .windows) { return self.lookupModuleWin32(address); diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 8f14f88e2e..26031be662 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -1,5 +1,4 @@ const std = @import("std.zig"); -const builtin = std.builtin; const debug = std.debug; const fs = std.fs; const io = std.io; @@ -454,7 +453,7 @@ const LineNumberProgram = struct { } }; -fn readUnitLength(in_stream: anytype, endian: builtin.Endian, is_64: *bool) !u64 { +fn readUnitLength(in_stream: anytype, endian: std.builtin.Endian, is_64: *bool) !u64 { const first_32_bits = try in_stream.readInt(u32, endian); is_64.* = (first_32_bits == 0xffffffff); if (is_64.*) { @@ -475,7 +474,7 @@ fn readAllocBytes(allocator: *mem.Allocator, in_stream: anytype, size: usize) ![ } // TODO the nosuspends here are workarounds -fn readAddress(in_stream: anytype, endian: builtin.Endian, is_64: bool) !u64 { +fn readAddress(in_stream: anytype, endian: std.builtin.Endian, is_64: bool) !u64 { return nosuspend if (is_64) try in_stream.readInt(u64, endian) else @@ -488,12 +487,12 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: anytype, size: u } // TODO the nosuspends here are workarounds -fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: usize) !FormValue { +fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: usize) !FormValue { const block_len = try nosuspend in_stream.readVarInt(usize, endian, size); return parseFormValueBlockLen(allocator, in_stream, block_len); } -fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue { +fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: std.builtin.Endian, comptime size: i32) !FormValue { _ = allocator; // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here. // `nosuspend` should be removed from all the function calls once it is fixed. @@ -521,7 +520,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: } // TODO the nosuspends here are workarounds -fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue { +fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: i32) !FormValue { _ = allocator; return FormValue{ .Ref = switch (size) { @@ -536,7 +535,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: buil } // TODO the nosuspends here are workarounds -fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue { +fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: std.builtin.Endian, is_64: bool) anyerror!FormValue { return switch (form_id) { FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) }, FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1), @@ -593,7 +592,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con } pub const DwarfInfo = struct { - endian: builtin.Endian, + endian: std.builtin.Endian, // No memory is owned by the DwarfInfo debug_info: []const u8, debug_abbrev: []const u8, diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 91c66503f1..2f61db5680 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -1,6 +1,5 @@ -const builtin = std.builtin; - const std = @import("std.zig"); +const builtin = @import("builtin"); const mem = std.mem; const os = std.os; const assert = std.debug.assert; diff --git a/lib/std/event/channel.zig b/lib/std/event/channel.zig index 915681d4a6..fb478ed6ed 100644 --- a/lib/std/event/channel.zig +++ b/lib/std/event/channel.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const testing = std.testing; const Loop = std.event.Loop; diff --git a/lib/std/event/future.zig b/lib/std/event/future.zig index 17a7c3050b..44ee166e6f 100644 --- a/lib/std/event/future.zig +++ b/lib/std/event/future.zig @@ -1,7 +1,7 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; const testing = std.testing; -const builtin = std.builtin; const Lock = std.event.Lock; /// This is a value that starts out unavailable, until resolve() is called diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig index dc200017a4..599e8d9496 100644 --- a/lib/std/event/group.zig +++ b/lib/std/event/group.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const Lock = std.event.Lock; const testing = std.testing; const Allocator = std.mem.Allocator; diff --git a/lib/std/event/lock.zig b/lib/std/event/lock.zig index eea6a31455..645b6adad6 100644 --- a/lib/std/event/lock.zig +++ b/lib/std/event/lock.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const testing = std.testing; const mem = std.mem; diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index e7fe2da33d..a16f3ea6ac 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const root = @import("root"); const assert = std.debug.assert; const testing = std.testing; @@ -9,7 +9,7 @@ const windows = os.windows; const maxInt = std.math.maxInt; const Thread = std.Thread; -const is_windows = std.Target.current.os.tag == .windows; +const is_windows = builtin.os.tag == .windows; pub const Loop = struct { next_tick_queue: std.atomic.Queue(anyframe), @@ -191,7 +191,7 @@ pub const Loop = struct { self.fs_thread.join(); }; - if (!std.builtin.single_threaded) + if (!builtin.single_threaded) try self.delay_queue.init(); } @@ -825,7 +825,7 @@ pub const Loop = struct { } pub fn sleep(self: *Loop, nanoseconds: u64) void { - if (std.builtin.single_threaded) + if (builtin.single_threaded) @compileError("TODO: integrate timers with epoll/kevent/iocp for single-threaded"); suspend { diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig index 951f305cff..fd42842a3a 100644 --- a/lib/std/event/rwlock.zig +++ b/lib/std/event/rwlock.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const testing = std.testing; const mem = std.mem; diff --git a/lib/std/event/wait_group.zig b/lib/std/event/wait_group.zig index 2275a06d08..d26986f384 100644 --- a/lib/std/event/wait_group.zig +++ b/lib/std/event/wait_group.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const Loop = std.event.Loop; /// A WaitGroup keeps track and waits for a group of async tasks to finish. diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 7aa5dd3976..fca5304bf2 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -1,6 +1,6 @@ -const root = @import("root"); -const builtin = std.builtin; const std = @import("std.zig"); +const builtin = @import("builtin"); +const root = @import("root"); const os = std.os; const mem = std.mem; const base64 = std.base64; @@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator; const assert = std.debug.assert; const math = std.math; -const is_darwin = std.Target.current.os.tag.isDarwin(); +const is_darwin = builtin.os.tag.isDarwin(); pub const path = @import("fs/path.zig"); pub const File = @import("fs/file.zig").File; @@ -2607,7 +2607,7 @@ const CopyFileError = error{SystemResources} || os.CopyFileRangeError || os.Send // The copy starts at offset 0, the initial offsets are preserved. // No metadata is transferred over. fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); switch (os.errno(rc)) { .SUCCESS => return, @@ -2620,7 +2620,7 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { } } - if (std.Target.current.os.tag == .linux) { + if (builtin.os.tag == .linux) { // Try copy_file_range first as that works at the FS level and is the // most efficient method (if available). var offset: u64 = 0; diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index a71c9ae0d2..1025719ca2 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -1,14 +1,14 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const os = std.os; const io = std.io; const mem = std.mem; const math = std.math; const assert = std.debug.assert; const windows = os.windows; -const Os = builtin.Os; +const Os = std.builtin.Os; const maxInt = std.math.maxInt; -const is_windows = std.Target.current.os.tag == .windows; +const is_windows = builtin.os.tag == .windows; pub const File = struct { /// The OS-specific file descriptor or file handle. diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig index 491b6fe824..de5be26626 100644 --- a/lib/std/fs/get_app_data_dir.zig +++ b/lib/std/fs/get_app_data_dir.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const unicode = std.unicode; const mem = std.mem; const fs = std.fs; diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index a6e1e440fd..3d1b0d7794 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1,6 +1,6 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const testing = std.testing; -const builtin = std.builtin; const fs = std.fs; const mem = std.mem; const wasi = std.os.wasi; diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index a6c6dac711..528ccfc0f1 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const os = std.os; const mem = std.mem; const math = std.math; @@ -165,7 +166,7 @@ pub const PreopenList = struct { }; test "extracting WASI preopens" { - if (std.builtin.os.tag != .wasi or std.builtin.link_libc) return error.SkipZigTest; + if (builtin.os.tag != .wasi or builtin.link_libc) return error.SkipZigTest; var preopens = PreopenList.init(std.testing.allocator); defer preopens.deinit(); diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig index 117843bf95..56544162c8 100644 --- a/lib/std/fs/watch.zig +++ b/lib/std/fs/watch.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = std.builtin; +const builtin = @import("builtin"); const event = std.event; const assert = std.debug.assert; const testing = std.testing; @@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type { }; // @TODO Can I close this fd and get an error from bsdWaitKev? - const flags = if (comptime std.Target.current.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0; + const flags = if (comptime builtin.target.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0; const fd = try os.open(realpath, flags, 0); gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*); return null; diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 0049991378..5663bed249 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -2,7 +2,6 @@ const std = @import("std"); const assert = std.debug.assert; const mem = std.mem; const meta = std.meta; -const builtin = std.builtin; /// Describes how pointer types should be hashed. pub const HashStrategy = enum { @@ -233,7 +232,7 @@ fn testHashDeepRecursive(key: anytype) u64 { test "typeContainsSlice" { comptime { - try testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo))); + try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo))); try testing.expect(typeContainsSlice([]const u8)); try testing.expect(!typeContainsSlice(u8)); diff --git a/lib/std/hash/benchmark.zig b/lib/std/hash/benchmark.zig index d9865bcdd8..9e6ec5b6bc 100644 --- a/lib/std/hash/benchmark.zig +++ b/lib/std/hash/benchmark.zig @@ -1,7 +1,7 @@ // zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig -const builtin = std.builtin; const std = @import("std"); +const builtin = @import("builtin"); const time = std.time; const Timer = time.Timer; const hash = std.hash; diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index c6118c8cdc..8a535f372e 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { // ptr + offset doesn't work at comptime so we need this instead. diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig index 0b7a9a7c51..3990287322 100644 --- a/lib/std/hash/crc.zig +++ b/lib/std/hash/crc.zig @@ -6,6 +6,7 @@ // still moderately fast just slow relative to the slicing approach. const std = @import("../std.zig"); +const builtin = @import("builtin"); const debug = std.debug; const testing = std.testing; @@ -97,7 +98,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { }; } -const please_windows_dont_oom = std.Target.current.os.tag == .windows; +const please_windows_dont_oom = builtin.os.tag == .windows; test "crc32 ieee" { if (please_windows_dont_oom) return error.SkipZigTest; diff --git a/lib/std/heap.zig b/lib/std/heap.zig index e6e7af4626..47d964c239 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -1,11 +1,11 @@ const std = @import("std.zig"); +const builtin = @import("builtin"); const root = @import("root"); const debug = std.debug; const assert = debug.assert; const testing = std.testing; const mem = std.mem; const os = std.os; -const builtin = std.builtin; const c = std.c; const maxInt = std.math.maxInt; @@ -209,9 +209,9 @@ fn rawCResize( /// This allocator makes a syscall directly for every allocation and free. /// Thread-safe and lock-free. -pub const page_allocator = if (std.Target.current.isWasm()) +pub const page_allocator = if (builtin.target.isWasm()) &wasm_page_allocator_state -else if (std.Target.current.os.tag == .freestanding) +else if (builtin.target.os.tag == .freestanding) root.os.heap.page_allocator else &page_allocator_state; @@ -402,7 +402,7 @@ const PageAllocator = struct { const WasmPageAllocator = struct { comptime { - if (!std.Target.current.isWasm()) { + if (!builtin.target.isWasm()) { @compileError("WasmPageAllocator is only available for wasm32 arch"); } } @@ -608,11 +608,11 @@ pub const HeapAllocator = switch (builtin.os.tag) { const self = @fieldParentPtr(HeapAllocator, "allocator", allocator); const amt = n + ptr_align - 1 + @sizeOf(usize); - const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst); + const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst); const heap_handle = optional_heap_handle orelse blk: { const options = if (builtin.single_threaded) os.windows.HEAP_NO_SERIALIZE else 0; const hh = os.windows.kernel32.HeapCreate(options, amt, 0) orelse return error.OutOfMemory; - const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse break :blk hh; + const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, .SeqCst, .SeqCst) orelse break :blk hh; os.windows.HeapDestroy(hh); break :blk other_hh.?; // can't be null because of the cmpxchg }; @@ -792,7 +792,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: { _ = len_align; _ = ra; const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator); - var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst); + var end_index = @atomicLoad(usize, &self.end_index, .SeqCst); while (true) { const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse return error.OutOfMemory; @@ -801,7 +801,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: { if (new_end_index > self.buffer.len) { return error.OutOfMemory; } - end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse return self.buffer[adjusted_index..new_end_index]; + end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .SeqCst, .SeqCst) orelse return self.buffer[adjusted_index..new_end_index]; } } @@ -884,7 +884,7 @@ test "raw_c_allocator" { } test "WasmPageAllocator internals" { - if (comptime std.Target.current.isWasm()) { + if (comptime builtin.target.isWasm()) { const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size; const initial = try page_allocator.alloc(u8, mem.page_size); try testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite. @@ -924,7 +924,7 @@ test "PageAllocator" { const allocator = page_allocator; try testAllocator(allocator); try testAllocatorAligned(allocator); - if (!std.Target.current.isWasm()) { + if (!builtin.target.isWasm()) { try testAllocatorLargeAlignment(allocator); try testAllocatorAlignedShrink(allocator); } diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 3dd6b9db3d..37df19e823 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -93,6 +93,7 @@ //! in a `std.HashMap` using the backing allocator. const std = @import("std"); +const builtin = @import("builtin"); const log = std.log.scoped(.gpa); const math = std.math; const assert = std.debug.assert; @@ -104,7 +105,7 @@ const StackTrace = std.builtin.StackTrace; /// Integer type for pointing to slots in a small allocation const SlotIndex = std.meta.Int(.unsigned, math.log2(page_size) + 1); -const sys_can_stack_trace = switch (std.Target.current.cpu.arch) { +const sys_can_stack_trace = switch (builtin.cpu.arch) { // Observed to go into an infinite loop. // TODO: Make this work. .mips, @@ -115,13 +116,13 @@ const sys_can_stack_trace = switch (std.Target.current.cpu.arch) { // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address". .wasm32, .wasm64, - => std.Target.current.os.tag == .emscripten, + => builtin.os.tag == .emscripten, else => true, }; -const default_test_stack_trace_frames: usize = if (std.builtin.is_test) 8 else 4; +const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4; const default_sys_stack_trace_frames: usize = if (sys_can_stack_trace) default_test_stack_trace_frames else 0; -const default_stack_trace_frames: usize = switch (std.builtin.mode) { +const default_stack_trace_frames: usize = switch (builtin.mode) { .Debug => default_sys_stack_trace_frames, else => 0, }; @@ -141,7 +142,7 @@ pub const Config = struct { safety: bool = std.debug.runtime_safety, /// Whether the allocator may be used simultaneously from multiple threads. - thread_safe: bool = !std.builtin.single_threaded, + thread_safe: bool = !builtin.single_threaded, /// What type of mutex you'd like to use, for thread safety. /// when specfied, the mutex type must have the same shape as `std.Thread.Mutex` and @@ -988,7 +989,7 @@ test "shrink large object to large object with larger alignment" { var slice = try allocator.alignedAlloc(u8, 16, alloc_size); defer allocator.free(slice); - const big_alignment: usize = switch (std.Target.current.os.tag) { + const big_alignment: usize = switch (builtin.os.tag) { .windows => page_size * 32, // Windows aligns to 64K. else => page_size * 2, }; @@ -1058,7 +1059,7 @@ test "realloc large object to larger alignment" { var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); defer allocator.free(slice); - const big_alignment: usize = switch (std.Target.current.os.tag) { + const big_alignment: usize = switch (builtin.os.tag) { .windows => page_size * 32, // Windows aligns to 64K. else => page_size * 2, }; diff --git a/lib/std/io.zig b/lib/std/io.zig index 4127a7b08b..cc9edd9906 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const root = @import("root"); const c = std.c; diff --git a/lib/std/io/bit_reader.zig b/lib/std/io/bit_reader.zig index cb123bacbf..83b6c03876 100644 --- a/lib/std/io/bit_reader.zig +++ b/lib/std/io/bit_reader.zig @@ -1,5 +1,4 @@ const std = @import("../std.zig"); -const builtin = std.builtin; const io = std.io; const assert = std.debug.assert; const testing = std.testing; @@ -8,7 +7,7 @@ const meta = std.meta; const math = std.math; /// Creates a stream which allows for reading bit fields from another stream -pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type { +pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type { return struct { forward_reader: ReaderType, bit_buffer: u7, @@ -162,7 +161,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type { } pub fn bitReader( - comptime endian: builtin.Endian, + comptime endian: std.builtin.Endian, underlying_stream: anytype, ) BitReader(endian, @TypeOf(underlying_stream)) { return BitReader(endian, @TypeOf(underlying_stream)).init(underlying_stream); diff --git a/lib/std/io/bit_writer.zig b/lib/std/io/bit_writer.zig index 5236e4965a..ea8f984f0e 100644 --- a/lib/std/io/bit_writer.zig +++ b/lib/std/io/bit_writer.zig @@ -1,5 +1,4 @@ const std = @import("../std.zig"); -const builtin = std.builtin; const io = std.io; const testing = std.testing; const assert = std.debug.assert; @@ -8,7 +7,7 @@ const meta = std.meta; const math = std.math; /// Creates a stream which allows for writing bit fields to another stream -pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type { +pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type { return struct { forward_writer: WriterType, bit_buffer: u8, @@ -138,7 +137,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type { } pub fn bitWriter( - comptime endian: builtin.Endian, + comptime endian: std.builtin.Endian, underlying_stream: anytype, ) BitWriter(endian, @TypeOf(underlying_stream)) { return BitWriter(endian, @TypeOf(underlying_stream)).init(underlying_stream); diff --git a/lib/std/io/c_writer.zig b/lib/std/io/c_writer.zig index 07a719b0c2..d962bfd854 100644 --- a/lib/std/io/c_writer.zig +++ b/lib/std/io/c_writer.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const io = std.io; const testing = std.testing; const os = std.os; diff --git a/lib/std/io/reader.zig b/lib/std/io/reader.zig index f8e7650bc4..29dc6c225a 100644 --- a/lib/std/io/reader.zig +++ b/lib/std/io/reader.zig @@ -1,5 +1,4 @@ const std = @import("../std.zig"); -const builtin = std.builtin; const math = std.math; const assert = std.debug.assert; const mem = std.mem; @@ -265,12 +264,12 @@ pub fn Reader( return mem.readIntBig(T, &bytes); } - pub fn readInt(self: Self, comptime T: type, endian: builtin.Endian) !T { + pub fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) !T { const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8); return mem.readInt(T, &bytes, endian); } - pub fn readVarInt(self: Self, comptime ReturnType: type, endian: builtin.Endian, size: usize) !ReturnType { + pub fn readVarInt(self: Self, comptime ReturnType: type, endian: std.builtin.Endian, size: usize) !ReturnType { assert(size <= @sizeOf(ReturnType)); var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined; const bytes = bytes_buf[0..size]; @@ -310,7 +309,7 @@ pub fn Reader( pub fn readStruct(self: Self, comptime T: type) !T { // Only extern and packed structs have defined in-memory layout. - comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); + comptime assert(@typeInfo(T).Struct.layout != std.builtin.TypeInfo.ContainerLayout.Auto); var res: [1]T = undefined; try self.readNoEof(mem.sliceAsBytes(res[0..])); return res[0]; @@ -319,7 +318,7 @@ pub fn Reader( /// Reads an integer with the same size as the given enum's tag type. If the integer matches /// an enum tag, casts the integer to the enum tag and returns it. Otherwise, returns an error. /// TODO optimization taking advantage of most fields being in order - pub fn readEnum(self: Self, comptime Enum: type, endian: builtin.Endian) !Enum { + pub fn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) !Enum { const E = error{ /// An integer was read, but it did not match any of the tags in the supplied enum. InvalidValue, diff --git a/lib/std/io/stream_source.zig b/lib/std/io/stream_source.zig index 06903b2977..ce5256028c 100644 --- a/lib/std/io/stream_source.zig +++ b/lib/std/io/stream_source.zig @@ -1,4 +1,5 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const io = std.io; /// Provides `io.Reader`, `io.Writer`, and `io.SeekableStream` for in-memory buffers as @@ -6,7 +7,7 @@ const io = std.io; /// For memory sources, if the supplied byte buffer is const, then `io.Writer` is not available. /// The error set of the stream functions is the error set of the corresponding file functions. pub const StreamSource = union(enum) { - const has_file = (std.builtin.os.tag != .freestanding); + const has_file = (builtin.os.tag != .freestanding); /// The stream access is redirected to this buffer. buffer: io.FixedBufferStream([]u8), diff --git a/lib/std/io/writer.zig b/lib/std/io/writer.zig index 4f809dcca5..b05a3d0b28 100644 --- a/lib/std/io/writer.zig +++ b/lib/std/io/writer.zig @@ -1,6 +1,5 @@ const std = @import("../std.zig"); const assert = std.debug.assert; -const builtin = std.builtin; const mem = std.mem; pub fn Writer( @@ -77,7 +76,7 @@ pub fn Writer( } /// TODO audit non-power-of-two int sizes - pub fn writeInt(self: Self, comptime T: type, value: T, endian: builtin.Endian) Error!void { + pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void { var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined; mem.writeInt(T, &bytes, value, endian); return self.writeAll(&bytes); @@ -85,7 +84,7 @@ pub fn Writer( pub fn writeStruct(self: Self, value: anytype) Error!void { // Only extern and packed structs have defined in-memory layout. - comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); + comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != std.builtin.TypeInfo.ContainerLayout.Auto); return self.writeAll(mem.asBytes(&value)); } }; diff --git a/lib/std/log.zig b/lib/std/log.zig index 02c209c680..51eaaae695 100644 --- a/lib/std/log.zig +++ b/lib/std/log.zig @@ -69,7 +69,7 @@ //! ``` const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const root = @import("root"); pub const Level = enum { @@ -170,7 +170,7 @@ pub fn defaultLog( comptime format: []const u8, args: anytype, ) void { - if (std.Target.current.os.tag == .freestanding) { + if (builtin.os.tag == .freestanding) { // On freestanding one must provide a log function; we do not have // any I/O configured. return; diff --git a/lib/std/mem.zig b/lib/std/mem.zig index b3d0755adc..11b06422c0 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1,4 +1,5 @@ const std = @import("std.zig"); +const builtin = @import("builtin"); const debug = std.debug; const assert = debug.assert; const math = std.math; @@ -7,13 +8,13 @@ const meta = std.meta; const trait = meta.trait; const testing = std.testing; const Endian = std.builtin.Endian; -const native_endian = std.Target.current.cpu.arch.endian(); +const native_endian = builtin.cpu.arch.endian(); /// Compile time known minimum page size. /// https://github.com/ziglang/zig/issues/4082 -pub const page_size = switch (std.Target.current.cpu.arch) { +pub const page_size = switch (builtin.cpu.arch) { .wasm32, .wasm64 => 64 * 1024, - .aarch64 => switch (std.Target.current.os.tag) { + .aarch64 => switch (builtin.os.tag) { .macos, .ios, .watchos, .tvos => 16 * 1024, else => 4 * 1024, }, diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 62866bb711..5cdbeb4caa 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -1,5 +1,4 @@ const std = @import("std.zig"); -const builtin = std.builtin; const debug = std.debug; const mem = std.mem; const math = std.math; @@ -9,7 +8,7 @@ const root = @import("root"); pub const trait = @import("meta/trait.zig"); pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags; -const TypeInfo = builtin.TypeInfo; +const TypeInfo = std.builtin.TypeInfo; pub fn tagName(v: anytype) []const u8 { const T = @TypeOf(v); @@ -858,7 +857,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De pub const IntType = @compileError("replaced by std.meta.Int"); -pub fn Int(comptime signedness: builtin.Signedness, comptime bit_count: u16) type { +pub fn Int(comptime signedness: std.builtin.Signedness, comptime bit_count: u16) type { return @Type(TypeInfo{ .Int = .{ .signedness = signedness, diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index d1590141a1..6b6124ebeb 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -1,5 +1,4 @@ const std = @import("../std.zig"); -const builtin = std.builtin; const mem = std.mem; const debug = std.debug; const testing = std.testing; @@ -98,7 +97,7 @@ test "std.meta.trait.hasField" { try testing.expect(!hasField("value")(u8)); } -pub fn is(comptime id: builtin.TypeId) TraitFn { +pub fn is(comptime id: std.builtin.TypeId) TraitFn { const Closure = struct { pub fn trait(comptime T: type) bool { return id == @typeInfo(T); @@ -115,7 +114,7 @@ test "std.meta.trait.is" { try testing.expect(!is(.Optional)(anyerror)); } -pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn { +pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn { const Closure = struct { pub fn trait(comptime T: type) bool { if (!comptime isSingleItemPtr(T)) return false; @@ -131,7 +130,7 @@ test "std.meta.trait.isPtrTo" { try testing.expect(!isPtrTo(.Struct)(**struct {})); } -pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn { +pub fn isSliceOf(comptime id: std.builtin.TypeId) TraitFn { const Closure = struct { pub fn trait(comptime T: type) bool { if (!comptime isSlice(T)) return false; diff --git a/lib/std/net.zig b/lib/std/net.zig index 94df1532d6..772a75411d 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -12,7 +12,7 @@ const native_endian = builtin.target.cpu.arch.endian(); // first release to support them. pub const has_unix_sockets = @hasDecl(os.sockaddr, "un") and (builtin.target.os.tag != .windows or - std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false); + builtin.os.version_range.windows.isAtLeast(.win10_rs4) orelse false); pub const Address = extern union { any: os.sockaddr, @@ -1623,7 +1623,7 @@ pub const Stream = struct { } pub fn read(self: Stream, buffer: []u8) ReadError!usize { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return os.windows.ReadFile(self.handle, buffer, null, io.default_mode); } @@ -1638,7 +1638,7 @@ pub const Stream = struct { /// file system thread instead of non-blocking. It needs to be reworked to properly /// use non-blocking I/O. pub fn write(self: Stream, buffer: []const u8) WriteError!usize { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return os.windows.WriteFile(self.handle, buffer, null, io.default_mode); } diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 16a43fa421..1742fb2947 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -1,5 +1,5 @@ const std = @import("../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const net = std.net; const mem = std.mem; const testing = std.testing; @@ -35,7 +35,7 @@ test "parse and render IPv6 addresses" { var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); - if (std.builtin.os.tag == .linux) { + if (builtin.os.tag == .linux) { var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable; try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3])); @@ -49,7 +49,7 @@ test "parse and render IPv6 addresses" { try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0)); try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0)); // TODO Make this test pass on other operating systems. - if (std.builtin.os.tag == .linux) { + if (builtin.os.tag == .linux) { try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0)); try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0)); try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0)); @@ -57,7 +57,7 @@ test "parse and render IPv6 addresses" { } test "invalid but parseable IPv6 scope ids" { - if (std.builtin.os.tag != .linux) { + if (builtin.os.tag != .linux) { // Currently, resolveIp6 with alphanumerical scope IDs only works on Linux. // TODO Make this test pass on other operating systems. return error.SkipZigTest; @@ -106,11 +106,11 @@ test "parse and render UNIX addresses" { test "resolve DNS" { if (builtin.os.tag == .wasi) return error.SkipZigTest; - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { _ = try std.os.windows.WSAStartup(2, 2); } defer { - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { std.os.windows.WSACleanup() catch unreachable; } } @@ -143,11 +143,11 @@ test "listen on a port, send bytes, receive bytes" { if (builtin.single_threaded) return error.SkipZigTest; if (builtin.os.tag == .wasi) return error.SkipZigTest; - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { _ = try std.os.windows.WSAStartup(2, 2); } defer { - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { std.os.windows.WSACleanup() catch unreachable; } } @@ -185,7 +185,7 @@ test "listen on a port, send bytes, receive bytes" { test "listen on a port, send bytes, receive bytes" { if (!std.io.is_async) return error.SkipZigTest; - if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) { + if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) { // TODO build abstractions for other operating systems return error.SkipZigTest; } @@ -207,7 +207,7 @@ test "listen on a port, send bytes, receive bytes" { test "listen on ipv4 try connect on ipv6 then ipv4" { if (!std.io.is_async) return error.SkipZigTest; - if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) { + if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) { // TODO build abstractions for other operating systems return error.SkipZigTest; } @@ -267,11 +267,11 @@ test "listen on a unix socket, send bytes, receive bytes" { if (builtin.single_threaded) return error.SkipZigTest; if (!net.has_unix_sockets) return error.SkipZigTest; - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { _ = try std.os.windows.WSAStartup(2, 2); } defer { - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { std.os.windows.WSACleanup() catch unreachable; } } diff --git a/lib/std/once.zig b/lib/std/once.zig index 638d3b1066..f3a85f76d0 100644 --- a/lib/std/once.zig +++ b/lib/std/once.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const testing = std.testing; pub fn once(comptime f: fn () void) Once(f) { diff --git a/lib/std/os.zig b/lib/std/os.zig index a4fad9bc20..eda246d2a3 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -240,7 +240,7 @@ pub fn close(fd: fd_t) void { _ = wasi.fd_close(fd); return; } - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { // This avoids the EINTR problem. switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) { .BADF => unreachable, // Always a race condition. @@ -487,7 +487,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { } // Prevents EINVAL. - const max_count = switch (std.Target.current.os.tag) { + const max_count = switch (builtin.os.tag) { .linux => 0x7ffff000, .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), @@ -525,7 +525,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { /// * Windows /// On these systems, the read races with concurrent writes to the same file descriptor. pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { // TODO improve this to use ReadFileScatter if (iov.len == 0) return @as(usize, 0); const first = iov[0]; @@ -616,7 +616,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { } // Prevent EINVAL. - const max_count = switch (std.Target.current.os.tag) { + const max_count = switch (builtin.os.tag) { .linux => 0x7ffff000, .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), @@ -662,7 +662,7 @@ pub const TruncateError = error{ } || UnexpectedError; pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { var io_status_block: windows.IO_STATUS_BLOCK = undefined; var eof_info = windows.FILE_END_OF_FILE_INFORMATION{ .EndOfFile = @bitCast(windows.LARGE_INTEGER, length), @@ -683,7 +683,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { else => return windows.unexpectedStatus(rc), } } - if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { + if (builtin.os.tag == .wasi and !builtin.link_libc) { switch (wasi.fd_filestat_set_size(fd, length)) { .SUCCESS => return, .INTR => unreachable, @@ -733,7 +733,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { /// * Windows /// On these systems, the read races with concurrent writes to the same file descriptor. pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { - const have_pread_but_not_preadv = switch (std.Target.current.os.tag) { + const have_pread_but_not_preadv = switch (builtin.os.tag) { .windows, .macos, .ios, .watchos, .tvos, .haiku => true, else => false, }; @@ -868,7 +868,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { } } - const max_count = switch (std.Target.current.os.tag) { + const max_count = switch (builtin.os.tag) { .linux => 0x7ffff000, .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), @@ -916,7 +916,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { /// /// If `iov.len` is larger than `IOV_MAX`, a partial write will occur. pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { // TODO improve this to use WriteFileScatter if (iov.len == 0) return @as(usize, 0); const first = iov[0]; @@ -991,7 +991,7 @@ pub const PWriteError = WriteError || error{Unseekable}; /// The limit on Darwin is `0x7fffffff`, trying to write more than that returns EINVAL. /// The corresponding POSIX limit is `math.maxInt(isize)`. pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return windows.WriteFile(fd, bytes, offset, std.io.default_mode); } if (builtin.os.tag == .wasi and !builtin.link_libc) { @@ -1024,7 +1024,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { } // Prevent EINVAL. - const max_count = switch (std.Target.current.os.tag) { + const max_count = switch (builtin.os.tag) { .linux => 0x7ffff000, .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), @@ -1083,7 +1083,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { /// /// If `iov.len` is larger than `IOV_MAX`, a partial write will occur. pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize { - const have_pwrite_but_not_pwritev = switch (std.Target.current.os.tag) { + const have_pwrite_but_not_pwritev = switch (builtin.os.tag) { .windows, .macos, .ios, .watchos, .tvos, .haiku => true, else => false, }; @@ -1199,7 +1199,7 @@ pub const OpenError = error{ /// Open and possibly create a file. Keeps trying if it gets interrupted. /// See also `openZ`. pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { const file_path_w = try windows.sliceToPrefixedFileW(file_path); return openW(file_path_w.span(), flags, perm); } @@ -1212,7 +1212,7 @@ pub const openC = @compileError("deprecated: renamed to openZ"); /// Open and possibly create a file. Keeps trying if it gets interrupted. /// See also `open`. pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { const file_path_w = try windows.cStrToPrefixedFileW(file_path); return openW(file_path_w.span(), flags, perm); } @@ -2900,7 +2900,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t return rc; } - const have_sock_flags = comptime !std.Target.current.isDarwin(); + const have_sock_flags = comptime !builtin.target.isDarwin(); const filtered_sock_type = if (!have_sock_flags) socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC) else @@ -3199,7 +3199,7 @@ pub fn accept( /// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful. flags: u32, ) AcceptError!socket_t { - const have_accept4 = comptime !(std.Target.current.isDarwin() or builtin.os.tag == .windows); + const have_accept4 = comptime !(builtin.target.isDarwin() or builtin.os.tag == .windows); assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s) const accepted_sock = while (true) { @@ -4807,7 +4807,7 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; /// TODO: change this to return the timespec as a return value /// TODO: look into making clk_id an enum pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { - if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { + if (builtin.os.tag == .wasi and !builtin.link_libc) { var ts: timestamp_t = undefined; switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) { .SUCCESS => { @@ -4821,7 +4821,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { } return; } - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { if (clk_id == CLOCK.REALTIME) { var ft: windows.FILETIME = undefined; windows.kernel32.GetSystemTimeAsFileTime(&ft); @@ -4848,7 +4848,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { } pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { - if (std.Target.current.os.tag == .wasi and !builtin.link_libc) { + if (builtin.os.tag == .wasi and !builtin.link_libc) { var ts: timestamp_t = undefined; switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) { .SUCCESS => res.* = .{ @@ -5416,19 +5416,19 @@ pub fn sendfile( // Prevents EOVERFLOW. const size_t = std.meta.Int(.unsigned, @typeInfo(usize).Int.bits - 1); - const max_count = switch (std.Target.current.os.tag) { + const max_count = switch (builtin.os.tag) { .linux => 0x7ffff000, .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(size_t), }; - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => sf: { // sendfile() first appeared in Linux 2.2, glibc 2.1. const call_sf = comptime if (builtin.link_libc) std.c.versionCheck(.{ .major = 2, .minor = 1 }).ok else - std.Target.current.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2 }) != .lt; + builtin.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2 }) != .lt; if (!call_sf) break :sf; if (headers.len != 0) { @@ -5719,13 +5719,13 @@ var has_copy_file_range_syscall = std.atomic.Atomic(bool).init(true); /// /// Maximum offsets on Linux are `math.maxInt(i64)`. pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize { - const call_cfr = comptime if (std.Target.current.os.tag == .wasi) + const call_cfr = comptime if (builtin.os.tag == .wasi) // WASI-libc doesn't have copy_file_range. false else if (builtin.link_libc) std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok else - std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; + builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true; if (call_cfr and has_copy_file_range_syscall.load(.Monotonic)) { var off_in_copy = @bitCast(i64, off_in); @@ -6179,7 +6179,7 @@ pub fn syncfs(fd: fd_t) SyncError!void { /// Write all pending file contents and metadata modifications for the specified file descriptor to the underlying filesystem. pub fn fsync(fd: fd_t) SyncError!void { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { if (windows.kernel32.FlushFileBuffers(fd) != 0) return; switch (windows.kernel32.GetLastError()) { @@ -6203,7 +6203,7 @@ pub fn fsync(fd: fd_t) SyncError!void { /// Write all pending file contents for the specified file descriptor to the underlying filesystem, but not necessarily the metadata. pub fn fdatasync(fd: fd_t) SyncError!void { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return fsync(fd) catch |err| switch (err) { SyncError.AccessDenied => return, // fdatasync doesn't promise that the access time was synced else => return err, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index f3e4495220..7e482fe2f4 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -6,12 +6,13 @@ //! provide `rename` when only the `renameat` syscall exists. //! * Does not support POSIX thread cancellation. const std = @import("../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; const maxInt = std.math.maxInt; const elf = std.elf; const vdso = @import("linux/vdso.zig"); const dl = @import("../dynamic_library.zig"); -const native_arch = std.Target.current.cpu.arch; +const native_arch = builtin.cpu.arch; const native_endian = native_arch.endian(); const is_mips = native_arch.isMIPS(); const is_ppc = native_arch.isPPC(); @@ -21,7 +22,7 @@ const iovec = std.os.iovec; const iovec_const = std.os.iovec_const; test { - if (std.Target.current.os.tag == .linux) { + if (builtin.os.tag == .linux) { _ = @import("linux/test.zig"); } } @@ -150,10 +151,10 @@ pub fn getauxval(index: usize) usize { // Some architectures (and some syscalls) require 64bit parameters to be passed // in a even-aligned register pair. const require_aligned_register_pair = - std.Target.current.cpu.arch.isPPC() or - std.Target.current.cpu.arch.isMIPS() or - std.Target.current.cpu.arch.isARM() or - std.Target.current.cpu.arch.isThumb(); + builtin.cpu.arch.isPPC() or + builtin.cpu.arch.isMIPS() or + builtin.cpu.arch.isARM() or + builtin.cpu.arch.isThumb(); // Split a 64bit value into a {LSB,MSB} pair. // The LE/BE variants specify the endianness to assume. @@ -1579,7 +1580,7 @@ pub fn process_vm_writev(pid: pid_t, local: [*]const iovec, local_count: usize, } pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { - if (comptime std.Target.current.cpu.arch.isMIPS()) { + if (comptime builtin.cpu.arch.isMIPS()) { // MIPS requires a 7 argument syscall const offset_halves = splitValue64(offset); @@ -1595,7 +1596,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { length_halves[1], advice, ); - } else if (comptime std.Target.current.cpu.arch.isARM()) { + } else if (comptime builtin.cpu.arch.isARM()) { // ARM reorders the arguments const offset_halves = splitValue64(offset); diff --git a/lib/std/os/linux/bpf/kern.zig b/lib/std/os/linux/bpf/kern.zig index 729495e91d..68ba35581b 100644 --- a/lib/std/os/linux/bpf/kern.zig +++ b/lib/std/os/linux/bpf/kern.zig @@ -1,6 +1,7 @@ const std = @import("../../../std.zig"); +const builtin = @import("builtin"); -const in_bpf_program = switch (std.builtin.cpu.arch) { +const in_bpf_program = switch (builtin.cpu.arch) { .bpfel, .bpfeb => true, else => false, }; diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 9653e2a08c..6bab93e3cf 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -1,6 +1,6 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; -const builtin = std.builtin; const mem = std.mem; const net = std.net; const os = std.os; diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index 89dbeaf212..bf3e9c4c1e 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -1,6 +1,6 @@ const std = @import("std"); +const builtin = @import("builtin"); const elf = std.elf; -const builtin = std.builtin; const assert = std.debug.assert; const R_AMD64_RELATIVE = 8; diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 14ff8ea38d..63deab3edc 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -1,5 +1,5 @@ const std = @import("../../std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const linux = std.os.linux; const mem = std.mem; const elf = std.elf; diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index de9c475083..37f6abfefc 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -4,7 +4,7 @@ const mem = std.mem; const elf = std.elf; const math = std.math; const assert = std.debug.assert; -const native_arch = std.Target.current.cpu.arch; +const native_arch = @import("builtin").cpu.arch; // This file implements the two TLS variants [1] used by ELF-based systems. // diff --git a/lib/std/os/windows/user32.zig b/lib/std/os/windows/user32.zig index 5224b9f0cb..f1c6f1110d 100644 --- a/lib/std/os/windows/user32.zig +++ b/lib/std/os/windows/user32.zig @@ -1,4 +1,5 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; const windows = std.os.windows; @@ -29,7 +30,7 @@ const HBRUSH = windows.HBRUSH; fn selectSymbol(comptime function_static: anytype, function_dynamic: @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) @TypeOf(function_static) { comptime { - const sym_ok = std.Target.current.os.isAtLeast(.windows, os); + const sym_ok = builtin.os.isAtLeast(.windows, os); if (sym_ok == true) return function_static; if (sym_ok == null) return function_dynamic; if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required"); diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 698407a3a8..a8d9161981 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -1,4 +1,3 @@ -const builtin = std.builtin; const std = @import("std.zig"); const io = std.io; const math = std.math; diff --git a/lib/std/process.zig b/lib/std/process.zig index 8dce2462a2..178dc495c6 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1,5 +1,5 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const os = std.os; const fs = std.fs; const BufMap = std.BufMap; @@ -863,9 +863,9 @@ pub fn execve( if (env_map) |m| { const envp_buf = try child_process.createNullDelimitedEnvMap(arena, m); break :m envp_buf.ptr; - } else if (std.builtin.link_libc) { + } else if (builtin.link_libc) { break :m std.c.environ; - } else if (std.builtin.output_mode == .Exe) { + } else if (builtin.output_mode == .Exe) { // Then we have Zig start code and this works. // TODO type-safety for null-termination of `os.environ`. break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr); diff --git a/lib/std/rand.zig b/lib/std/rand.zig index 104be7f692..7a4f5e4018 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -7,7 +7,6 @@ //! TODO(tiehuis): Benchmark these against other reference implementations. const std = @import("std.zig"); -const builtin = std.builtin; const assert = std.debug.assert; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; diff --git a/lib/std/rand/ziggurat.zig b/lib/std/rand/ziggurat.zig index 2b9728fa96..67cd996a30 100644 --- a/lib/std/rand/ziggurat.zig +++ b/lib/std/rand/ziggurat.zig @@ -1,14 +1,15 @@ -// Implements ZIGNOR [1]. -// -// [1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to Generate Normal Random Samples*] -// (https://www.doornik.com/research/ziggurat.pdf). Nuffield College, Oxford. -// -// rust/rand used as a reference; -// -// NOTE: This seems interesting but reference code is a bit hard to grok: -// https://sbarral.github.io/etf. +//! Implements ZIGNOR [1]. +//! +//! [1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to Generate Normal Random Samples*] +//! (https://www.doornik.com/research/ziggurat.pdf). Nuffield College, Oxford. +//! +//! rust/rand used as a reference; +//! +//! NOTE: This seems interesting but reference code is a bit hard to grok: +//! https://sbarral.github.io/etf. const std = @import("../std.zig"); +const builtin = @import("builtin"); const math = std.math; const Random = std.rand.Random; @@ -126,7 +127,7 @@ fn norm_zero_case(random: *Random, u: f64) f64 { } } -const please_windows_dont_oom = std.Target.current.os.tag == .windows; +const please_windows_dont_oom = builtin.os.tag == .windows; test "normal dist sanity" { if (please_windows_dont_oom) return error.SkipZigTest; diff --git a/lib/std/sort.zig b/lib/std/sort.zig index cbc24d9abd..60c8f32dc6 100644 --- a/lib/std/sort.zig +++ b/lib/std/sort.zig @@ -3,7 +3,6 @@ const assert = std.debug.assert; const testing = std.testing; const mem = std.mem; const math = std.math; -const builtin = std.builtin; pub fn binarySearch( comptime T: type, diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 6e47df9177..ce3373abac 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -1,9 +1,9 @@ const std = @import("std"); const builtin = @import("builtin"); const is_test = builtin.is_test; -const os_tag = std.Target.current.os.tag; +const os_tag = builtin.os.tag; const arch = builtin.stage2_arch; -const abi = std.Target.current.abi; +const abi = builtin.abi; const is_gnu = abi.isGnu(); const is_mingw = os_tag == .windows and is_gnu; diff --git a/lib/std/special/compiler_rt/atomics.zig b/lib/std/special/compiler_rt/atomics.zig index b6d0b55e33..ca97bebf0b 100644 --- a/lib/std/special/compiler_rt/atomics.zig +++ b/lib/std/special/compiler_rt/atomics.zig @@ -1,8 +1,8 @@ const std = @import("std"); -const builtin = std.builtin; -const arch = std.Target.current.cpu.arch; +const builtin = @import("builtin"); +const arch = builtin.cpu.arch; -const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak; +const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak; // This parameter is true iff the target architecture supports the bare minimum // to implement the atomic load/store intrinsics. @@ -16,7 +16,7 @@ const supports_atomic_ops = switch (arch) { // operations (unless we're targeting Linux, the kernel provides a way to // perform CAS operations). // XXX: The Linux code path is not implemented yet. - !std.Target.arm.featureSetHas(std.Target.current.cpu.features, .has_v6m), + !std.Target.arm.featureSetHas(builtin.cpu.features, .has_v6m), else => true, }; @@ -257,7 +257,7 @@ comptime { } } -fn fetchFn(comptime T: type, comptime op: builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T { +fn fetchFn(comptime T: type, comptime op: std.builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T { return struct { pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T { _ = model; diff --git a/lib/std/special/compiler_rt/clear_cache.zig b/lib/std/special/compiler_rt/clear_cache.zig index fdc847e439..d6ce02249e 100644 --- a/lib/std/special/compiler_rt/clear_cache.zig +++ b/lib/std/special/compiler_rt/clear_cache.zig @@ -1,6 +1,7 @@ const std = @import("std"); -const arch = std.builtin.cpu.arch; -const os = std.builtin.os.tag; +const builtin = @import("builtin"); +const arch = builtin.cpu.arch; +const os = builtin.os.tag; // Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28 @@ -156,7 +157,7 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { } } -const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak; +const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak; fn exportIt() void { @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); diff --git a/lib/std/special/compiler_rt/count0bits.zig b/lib/std/special/compiler_rt/count0bits.zig index 380dc58ba2..36fbb394e3 100644 --- a/lib/std/special/compiler_rt/count0bits.zig +++ b/lib/std/special/compiler_rt/count0bits.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = std.builtin; +const builtin = @import("builtin"); // clz - count leading zeroes // - clzXi2_generic for little endian @@ -118,18 +118,18 @@ fn __clzsi2_arm32() callconv(.Naked) void { } pub const __clzsi2 = impl: { - switch (std.Target.current.cpu.arch) { + switch (builtin.cpu.arch) { .arm, .armeb, .thumb, .thumbeb => { const use_thumb1 = - (std.Target.current.cpu.arch.isThumb() or - std.Target.arm.featureSetHas(std.Target.current.cpu.features, .noarm)) and - !std.Target.arm.featureSetHas(std.Target.current.cpu.features, .thumb2); + (builtin.cpu.arch.isThumb() or + std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and + !std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2); if (use_thumb1) { break :impl __clzsi2_thumb1; } // From here on we're either targeting Thumb2 or ARM. - else if (!std.Target.current.cpu.arch.isThumb()) { + else if (!builtin.cpu.arch.isThumb()) { break :impl __clzsi2_arm32; } // Use the generic implementation otherwise. @@ -140,14 +140,14 @@ pub const __clzsi2 = impl: { }; pub const __clzdi2 = impl: { - switch (std.Target.current.cpu.arch) { + switch (builtin.cpu.arch) { // TODO architecture optimised versions else => break :impl clzXi2_generic(i64), } }; pub const __clzti2 = impl: { - switch (std.Target.current.cpu.arch) { + switch (builtin.cpu.arch) { // TODO architecture optimised versions else => break :impl clzXi2_generic(i128), } diff --git a/lib/std/special/compiler_rt/emutls.zig b/lib/std/special/compiler_rt/emutls.zig index 5d018d84ae..a15903eab5 100644 --- a/lib/std/special/compiler_rt/emutls.zig +++ b/lib/std/special/compiler_rt/emutls.zig @@ -5,6 +5,7 @@ // const std = @import("std"); +const builtin = @import("builtin"); const abort = std.os.abort; const assert = std.debug.assert; @@ -15,7 +16,7 @@ const expect = std.testing.expect; const gcc_word = usize; comptime { - assert(std.builtin.link_libc); + assert(builtin.link_libc); } /// public entrypoint for generated code using EmulatedTLS diff --git a/lib/std/special/compiler_rt/muldi3.zig b/lib/std/special/compiler_rt/muldi3.zig index 3d426bd48e..f0d857e1e9 100644 --- a/lib/std/special/compiler_rt/muldi3.zig +++ b/lib/std/special/compiler_rt/muldi3.zig @@ -1,6 +1,7 @@ const std = @import("std"); -const is_test = std.builtin.is_test; -const native_endian = std.Target.current.cpu.arch.endian(); +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const native_endian = builtin.cpu.arch.endian(); // Ported from // https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c diff --git a/lib/std/special/compiler_rt/multi3.zig b/lib/std/special/compiler_rt/multi3.zig index d1c4a3b05d..a05fb3bd6d 100644 --- a/lib/std/special/compiler_rt/multi3.zig +++ b/lib/std/special/compiler_rt/multi3.zig @@ -1,7 +1,8 @@ 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(); +const builtin = @import("builtin"); +const is_test = builtin.is_test; +const native_endian = builtin.cpu.arch.endian(); // Ported from git@github.com:llvm-project/llvm-project-20170507.git // ae684fad6d34858c014c94da69c15e7774a633c3 diff --git a/lib/std/special/compiler_rt/shift.zig b/lib/std/special/compiler_rt/shift.zig index 28109ce9cd..b20516e46c 100644 --- a/lib/std/special/compiler_rt/shift.zig +++ b/lib/std/special/compiler_rt/shift.zig @@ -1,6 +1,6 @@ const std = @import("std"); const Log2Int = std.math.Log2Int; -const native_endian = std.Target.current.cpu.arch.endian(); +const native_endian = @import("builtin").cpu.arch.endian(); fn Dwords(comptime T: type, comptime signed_half: bool) type { return extern union { diff --git a/lib/std/special/compiler_rt/stack_probe.zig b/lib/std/special/compiler_rt/stack_probe.zig index 256207d6e6..90919dcbb8 100644 --- a/lib/std/special/compiler_rt/stack_probe.zig +++ b/lib/std/special/compiler_rt/stack_probe.zig @@ -1,4 +1,4 @@ -const native_arch = @import("std").Target.current.cpu.arch; +const native_arch = @import("builtin").cpu.arch; // Zig's own stack-probe routine (available only on x86 and x86_64) pub fn zig_probe_stack() callconv(.Naked) void { diff --git a/lib/std/special/compiler_rt/udivmod.zig b/lib/std/special/compiler_rt/udivmod.zig index 3d9618f797..b2fe2048d4 100644 --- a/lib/std/special/compiler_rt/udivmod.zig +++ b/lib/std/special/compiler_rt/udivmod.zig @@ -1,6 +1,6 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; -const native_endian = @import("std").Target.current.cpu.arch.endian(); +const native_endian = builtin.cpu.arch.endian(); const low = switch (native_endian) { .Big => 1, diff --git a/lib/std/special/ssp.zig b/lib/std/special/ssp.zig index 94a6676838..b205a09e0a 100644 --- a/lib/std/special/ssp.zig +++ b/lib/std/special/ssp.zig @@ -1,19 +1,18 @@ -// -// Small Zig reimplementation of gcc's libssp. -// -// This library implements most of the builtins required by the stack smashing -// protection as implemented by gcc&clang. -const std = @import("std"); -const builtin = std.builtin; +//! +//! Small Zig reimplementation of gcc's libssp. +//! +//! This library implements most of the builtins required by the stack smashing +//! protection as implemented by gcc&clang. +//! Missing exports: +//! - __gets_chk +//! - __mempcpy_chk +//! - __snprintf_chk +//! - __sprintf_chk +//! - __stpcpy_chk +//! - __vsnprintf_chk +//! - __vsprintf_chk -// Missing exports: -// - __gets_chk -// - __mempcpy_chk -// - __snprintf_chk -// - __sprintf_chk -// - __stpcpy_chk -// - __vsnprintf_chk -// - __vsprintf_chk +const std = @import("std"); extern fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8; extern fn memset(dest: ?[*]u8, c: u8, n: usize) callconv(.C) ?[*]u8; @@ -21,7 +20,7 @@ extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) call extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8; // Avoid dragging in the runtime safety mechanisms into this .o file. -pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { +pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { _ = msg; _ = error_return_trace; @setCold(true); diff --git a/lib/std/std.zig b/lib/std/std.zig index 39991ce305..f94185f2fb 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -95,7 +95,7 @@ comptime { } test { - if (builtin.os.tag == .windows) { + if (@import("builtin").os.tag == .windows) { // We only test the Windows-relevant stuff to save memory because the CI // server is hitting OOM. TODO revert this after stage2 arrives. _ = ChildProcess; diff --git a/lib/std/target.zig b/lib/std/target.zig index 6be8e9d77c..a5b998e29b 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1,6 +1,5 @@ const std = @import("std.zig"); const mem = std.mem; -const builtin = std.builtin; const Version = std.builtin.Version; /// TODO Nearly all the functions in this namespace would be @@ -1017,7 +1016,7 @@ pub const Target = struct { }; } - pub fn endian(arch: Arch) builtin.Endian { + pub fn endian(arch: Arch) std.builtin.Endian { return switch (arch) { .avr, .arm, @@ -1302,7 +1301,8 @@ pub const Target = struct { } }; - pub const current = builtin.target; + /// TODO delete this deprecated declaration after 0.9.0 is released + pub const current = @compileError("instead of std.Target.current, use @import(\"builtin\").target"); pub const stack_align = 16; diff --git a/lib/std/testing.zig b/lib/std/testing.zig index ae3757b513..a3c6b84496 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -1,4 +1,5 @@ const std = @import("std.zig"); +const builtin = @import("builtin"); const math = std.math; const print = std.debug.print; @@ -322,7 +323,7 @@ pub const TmpDir = struct { }; fn getCwdOrWasiPreopen() std.fs.Dir { - if (std.builtin.os.tag == .wasi and !std.builtin.link_libc) { + if (builtin.os.tag == .wasi and !builtin.link_libc) { var preopens = std.fs.wasi.PreopenList.init(allocator); defer preopens.deinit(); preopens.populate() catch @@ -464,7 +465,7 @@ test { /// Given a type, reference all the declarations inside, so that the semantic analyzer sees them. pub fn refAllDecls(comptime T: type) void { - if (!std.builtin.is_test) return; + if (!builtin.is_test) return; inline for (std.meta.declarations(T)) |decl| { _ = decl; } diff --git a/lib/std/time.zig b/lib/std/time.zig index 512838e143..b9580f5f3e 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -1,10 +1,10 @@ const std = @import("std.zig"); -const builtin = std.builtin; +const builtin = @import("builtin"); const assert = std.debug.assert; const testing = std.testing; const os = std.os; const math = std.math; -const is_windows = std.Target.current.os.tag == .windows; +const is_windows = builtin.os.tag == .windows; pub const epoch = @import("time/epoch.zig"); @@ -173,7 +173,7 @@ pub const Timer = struct { .resolution = @divFloor(ns_per_s, freq), .start_time = os.windows.QueryPerformanceCounter(), }; - } else if (comptime std.Target.current.isDarwin()) { + } else if (comptime builtin.target.isDarwin()) { var freq: os.darwin.mach_timebase_info_data = undefined; os.darwin.mach_timebase_info(&freq); @@ -225,7 +225,7 @@ pub const Timer = struct { if (is_windows) { return os.windows.QueryPerformanceCounter(); } - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { return os.darwin.mach_absolute_time(); } var ts: os.timespec = undefined; @@ -237,7 +237,7 @@ pub const Timer = struct { if (is_windows) { return safeMulDiv(duration, ns_per_s, self.frequency); } - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { return safeMulDiv(duration, self.frequency.numer, self.frequency.denom); } return duration; diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 5da7686d66..9585e3c349 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -1,5 +1,4 @@ const std = @import("./std.zig"); -const builtin = std.builtin; const assert = std.debug.assert; const testing = std.testing; const mem = std.mem; diff --git a/lib/std/unicode/throughput_test.zig b/lib/std/unicode/throughput_test.zig index 2117564961..5c2dfda768 100644 --- a/lib/std/unicode/throughput_test.zig +++ b/lib/std/unicode/throughput_test.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const time = std.time; const unicode = std.unicode; diff --git a/lib/std/x/net/tcp.zig b/lib/std/x/net/tcp.zig index 04cfd487e4..cb99940180 100644 --- a/lib/std/x/net/tcp.zig +++ b/lib/std/x/net/tcp.zig @@ -1,4 +1,5 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const io = std.io; const os = std.os; @@ -7,7 +8,7 @@ const ip = std.x.net.ip; const fmt = std.fmt; const mem = std.mem; const testing = std.testing; -const native_os = std.Target.current.os; +const native_os = builtin.os; const IPv4 = std.x.os.IPv4; const IPv6 = std.x.os.IPv6; diff --git a/lib/std/x/os/io.zig b/lib/std/x/os/io.zig index c2d9b27f67..35e7c3e1ed 100644 --- a/lib/std/x/os/io.zig +++ b/lib/std/x/os/io.zig @@ -1,9 +1,10 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const os = std.os; const mem = std.mem; const testing = std.testing; -const native_os = std.Target.current.os; +const native_os = builtin.os; const linux = std.os.linux; /// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig index a529396c3c..c71bc5bd22 100644 --- a/lib/std/x/os/net.zig +++ b/lib/std/x/os/net.zig @@ -1,11 +1,12 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const os = std.os; const fmt = std.fmt; const mem = std.mem; const math = std.math; const testing = std.testing; -const native_os = std.Target.current.os; +const native_os = builtin.os; const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE"); /// Resolves a network interface name into a scope/zone ID. It returns diff --git a/lib/std/x/os/socket.zig b/lib/std/x/os/socket.zig index 529fd19598..ed354681ed 100644 --- a/lib/std/x/os/socket.zig +++ b/lib/std/x/os/socket.zig @@ -1,4 +1,5 @@ const std = @import("../../std.zig"); +const builtin = @import("builtin"); const net = @import("net.zig"); const os = std.os; @@ -6,8 +7,8 @@ const fmt = std.fmt; const mem = std.mem; const time = std.time; const meta = std.meta; -const native_os = std.Target.current.os; -const native_endian = std.Target.current.cpu.arch.endian(); +const native_os = builtin.os; +const native_endian = builtin.cpu.arch.endian(); const Buffer = std.x.os.Buffer; diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 5243d0eb9d..00bfd29a45 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -1,4 +1,5 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const assert = std.debug.assert; const Target = std.Target; const mem = std.mem; @@ -329,7 +330,7 @@ pub const CrossTarget = struct { // This works when doing `zig build` because Zig generates a build executable using // native CPU model & features. However this will not be accurate otherwise, and // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. - return Target.current.cpu; + return builtin.cpu; }, .baseline => { var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); @@ -340,7 +341,7 @@ pub const CrossTarget = struct { // This works when doing `zig build` because Zig generates a build executable using // native CPU model & features. However this will not be accurate otherwise, and // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. - return Target.current.cpu; + return builtin.cpu; } else { var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); self.updateCpuFeatures(&adjusted_baseline.features); @@ -355,7 +356,7 @@ pub const CrossTarget = struct { } pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch { - return self.cpu_arch orelse Target.current.cpu.arch; + return self.cpu_arch orelse builtin.cpu.arch; } pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model { @@ -371,10 +372,10 @@ pub const CrossTarget = struct { /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. pub fn getOs(self: CrossTarget) Target.Os { - // `Target.current.os` works when doing `zig build` because Zig generates a build executable using + // `builtin.os` works when doing `zig build` because Zig generates a build executable using // native OS version range. However this will not be accurate otherwise, and // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. - var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange() else Target.current.os; + var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange() else builtin.os; if (self.os_version_min) |min| switch (min) { .none => {}, @@ -403,7 +404,7 @@ pub const CrossTarget = struct { } pub fn getOsTag(self: CrossTarget) Target.Os.Tag { - return self.os_tag orelse Target.current.os.tag; + return self.os_tag orelse builtin.os.tag; } /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. @@ -430,7 +431,7 @@ pub const CrossTarget = struct { // This works when doing `zig build` because Zig generates a build executable using // native CPU model & features. However this will not be accurate otherwise, and // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. - return Target.current.abi; + return builtin.abi; } return Target.Abi.default(self.getCpuArch(), self.getOs()); @@ -607,12 +608,12 @@ pub const CrossTarget = struct { pub fn getExternalExecutor(self: CrossTarget) Executor { const cpu_arch = self.getCpuArch(); const os_tag = self.getOsTag(); - const os_match = os_tag == Target.current.os.tag; + const os_match = os_tag == builtin.os.tag; // If the OS and CPU arch match, the binary can be considered native. // TODO additionally match the CPU features. This `getExternalExecutor` function should // be moved to std.Target and match any chosen target against the native target. - if (os_match and cpu_arch == Target.current.cpu.arch) { + if (os_match and cpu_arch == builtin.cpu.arch) { // However, we also need to verify that the dynamic linker path is valid. if (self.os_tag == null) { return .native; @@ -664,7 +665,7 @@ pub const CrossTarget = struct { // TODO loosen this check once upstream adds QEMU-based emulation // layer for non-host architectures: // https://github.com/darlinghq/darling/issues/863 - if (cpu_arch != Target.current.cpu.arch) { + if (cpu_arch != builtin.cpu.arch) { return .unavailable; } return Executor{ .darling = "darling" }; @@ -789,7 +790,7 @@ pub const CrossTarget = struct { }; test "CrossTarget.parse" { - if (Target.current.isGnuLibC()) { + if (builtin.target.isGnuLibC()) { var cross_target = try CrossTarget.parse(.{}); cross_target.setGnuLibCVersion(2, 1, 1); @@ -800,7 +801,7 @@ test "CrossTarget.parse" { const triple = std.fmt.bufPrint( buf[0..], "native-native-{s}.2.1.1", - .{@tagName(std.Target.current.abi)}, + .{@tagName(builtin.abi)}, ) catch unreachable; try std.testing.expectEqualSlices(u8, triple, text); diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index a86d6a2d45..316a2d1451 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -1,4 +1,5 @@ const std = @import("../std.zig"); +const builtin = @import("builtin"); const elf = std.elf; const mem = std.mem; const fs = std.fs; @@ -8,7 +9,7 @@ const assert = std.debug.assert; const process = std.process; const Target = std.Target; const CrossTarget = std.zig.CrossTarget; -const native_endian = std.Target.current.cpu.arch.endian(); +const native_endian = builtin.cpu.arch.endian(); const linux = @import("system/linux.zig"); pub const windows = @import("system/windows.zig"); pub const darwin = @import("system/darwin.zig"); @@ -88,7 +89,7 @@ pub const NativePaths = struct { return self; } - if (comptime Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { try self.addIncludeDir("/usr/include"); try self.addIncludeDir("/usr/local/include"); @@ -239,7 +240,7 @@ pub const NativeTargetInfo = struct { pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo { var os = cross_target.getOsTag().defaultVersionRange(); if (cross_target.os_tag == null) { - switch (Target.current.os.tag) { + switch (builtin.target.os.tag) { .linux => { const uts = std.os.uname(); const release = mem.spanZ(&uts.release); @@ -273,7 +274,7 @@ pub const NativeTargetInfo = struct { }, .macos => try darwin.macos.detect(&os), .freebsd, .netbsd, .dragonfly => { - const key = switch (Target.current.os.tag) { + const key = switch (builtin.target.os.tag) { .freebsd => "kern.osreldate", .netbsd, .dragonfly => "kern.osrevision", else => unreachable, @@ -289,7 +290,7 @@ pub const NativeTargetInfo = struct { error.Unexpected => return error.OSVersionDetectionFail, }; - switch (Target.current.os.tag) { + switch (builtin.target.os.tag) { .freebsd => { // https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html // Major * 100,000 has been convention since FreeBSD 2.2 (1997) @@ -445,8 +446,8 @@ pub const NativeTargetInfo = struct { os: Target.Os, cross_target: CrossTarget, ) DetectError!NativeTargetInfo { - const native_target_has_ld = comptime Target.current.hasDynamicLinker(); - const is_linux = Target.current.os.tag == .linux; + const native_target_has_ld = comptime builtin.target.hasDynamicLinker(); + const is_linux = builtin.target.os.tag == .linux; const have_all_info = cross_target.dynamic_linker.get() != null and cross_target.abi != null and (!is_linux or cross_target.abi.?.isGnu()); const os_is_non_native = cross_target.os_tag != null; @@ -463,7 +464,7 @@ pub const NativeTargetInfo = struct { // compiler for target riscv64-linux-musl and provide a tarball for users to download. // A user could then run that zig compiler on riscv64-linux-gnu. This use case is well-defined // and supported by Zig. But that means that we must detect the system ABI here rather than - // relying on `Target.current`. + // relying on `builtin.target`. const all_abis = comptime blk: { assert(@enumToInt(Target.Abi.none) == 0); const fields = std.meta.fields(Target.Abi)[1..]; @@ -524,7 +525,7 @@ pub const NativeTargetInfo = struct { // Look for glibc version. var os_adjusted = os; - if (Target.current.os.tag == .linux and found_ld_info.abi.isGnu() and + if (builtin.target.os.tag == .linux and found_ld_info.abi.isGnu() and cross_target.glibc_version == null) { for (lib_paths) |lib_path| { @@ -740,7 +741,7 @@ pub const NativeTargetInfo = struct { } }, // We only need this for detecting glibc version. - elf.PT_DYNAMIC => if (Target.current.os.tag == .linux and result.target.isGnuLibC() and + elf.PT_DYNAMIC => if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and cross_target.glibc_version == null) { var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset); @@ -787,7 +788,7 @@ pub const NativeTargetInfo = struct { } } - if (Target.current.os.tag == .linux and result.target.isGnuLibC() and cross_target.glibc_version == null) { + if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and cross_target.glibc_version == null) { if (rpath_offset) |rpoff| { const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx); @@ -979,14 +980,14 @@ pub const NativeTargetInfo = struct { // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`, // although it is a runtime value, is guaranteed to be one of the architectures in the set // of the respective switch prong. - switch (std.Target.current.cpu.arch) { + switch (builtin.cpu.arch) { .x86_64, .i386 => { return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, cross_target); }, else => {}, } - switch (std.Target.current.os.tag) { + switch (builtin.os.tag) { .linux => return linux.detectNativeCpuAndFeatures(), .macos => return darwin.macos.detectNativeCpuAndFeatures(), else => {}, diff --git a/lib/std/zig/system/darwin/macos.zig b/lib/std/zig/system/darwin/macos.zig index d374acbc94..eef2f77a62 100644 --- a/lib/std/zig/system/darwin/macos.zig +++ b/lib/std/zig/system/darwin/macos.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const assert = std.debug.assert; const mem = std.mem; const testing = std.testing; @@ -414,7 +415,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu { error.Unexpected => unreachable, // EFAULT: stack should be safe, EISDIR/ENOTDIR: constant, known good value }; - const current_arch = Target.current.cpu.arch; + const current_arch = builtin.cpu.arch; switch (current_arch) { .aarch64, .aarch64_be, .aarch64_32 => { const model = switch (cpu_family) { diff --git a/lib/std/zig/system/linux.zig b/lib/std/zig/system/linux.zig index e7737dfd70..0594ff1e2f 100644 --- a/lib/std/zig/system/linux.zig +++ b/lib/std/zig/system/linux.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const mem = std.mem; const io = std.io; const fs = std.fs; @@ -450,7 +451,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu { }; defer f.close(); - const current_arch = std.Target.current.cpu.arch; + const current_arch = builtin.cpu.arch; switch (current_arch) { .arm, .armeb, .thumb, .thumbeb, .aarch64, .aarch64_be, .aarch64_32 => { return ArmCpuinfoParser.parse(current_arch, f.reader()) catch null; diff --git a/src/Air.zig b/src/Air.zig index f7eccfd5a5..72aa603645 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -4,6 +4,7 @@ //! gets its own `Air` instance. const std = @import("std"); +const builtin = @import("builtin"); const Value = @import("value.zig").Value; const Type = @import("type.zig").Type; const Module = @import("Module.zig"); @@ -484,7 +485,7 @@ pub const Inst = struct { // bigger than expected. Note that in Debug builds, Zig is allowed // to insert a secret field for safety checks. comptime { - if (std.builtin.mode != .Debug) { + if (builtin.mode != .Debug) { assert(@sizeOf(Data) == 8); } } diff --git a/src/Cache.zig b/src/Cache.zig index 8a3b801e71..7d3bfdc3f2 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -4,6 +4,7 @@ hash: HashHelper = .{}, const Cache = @This(); const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const fs = std.fs; const assert = std.debug.assert; @@ -713,7 +714,7 @@ pub const Manifest = struct { /// uses the file contents. Windows supports symlinks but only with elevated privileges, so /// it is treated as not supporting symlinks. pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 { - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return dir.readFile(sub_path, buffer); } else { return dir.readLink(sub_path, buffer); @@ -726,7 +727,7 @@ pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 { /// `data` must be a valid UTF-8 encoded file path and 255 bytes or fewer. pub fn writeSmallFile(dir: fs.Dir, sub_path: []const u8, data: []const u8) !void { assert(data.len <= 255); - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { return dir.writeFile(sub_path, data); } else { return dir.symLink(data, sub_path, .{}); @@ -778,7 +779,7 @@ fn isProblematicTimestamp(fs_clock: i128) bool { } test "cache file and then recall it" { - if (std.Target.current.os.tag == .wasi) { + if (builtin.os.tag == .wasi) { // https://github.com/ziglang/zig/issues/5437 return error.SkipZigTest; } @@ -856,7 +857,7 @@ test "give nonproblematic timestamp" { } test "check that changing a file makes cache fail" { - if (std.Target.current.os.tag == .wasi) { + if (builtin.os.tag == .wasi) { // https://github.com/ziglang/zig/issues/5437 return error.SkipZigTest; } @@ -932,7 +933,7 @@ test "check that changing a file makes cache fail" { } test "no file inputs" { - if (std.Target.current.os.tag == .wasi) { + if (builtin.os.tag == .wasi) { // https://github.com/ziglang/zig/issues/5437 return error.SkipZigTest; } @@ -977,7 +978,7 @@ test "no file inputs" { } test "Manifest with files added after initial hash work" { - if (std.Target.current.os.tag == .wasi) { + if (builtin.os.tag == .wasi) { // https://github.com/ziglang/zig/issues/5437 return error.SkipZigTest; } diff --git a/src/Compilation.zig b/src/Compilation.zig index 8b44d6d51b..3007a5d336 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -937,8 +937,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { }; const darwin_can_use_system_sdk = blk: { - if (comptime !std.Target.current.isDarwin()) break :blk false; - break :blk std.builtin.os.tag == .macos and options.target.isDarwin(); + if (comptime !builtin.target.isDarwin()) break :blk false; + break :blk builtin.os.tag == .macos and options.target.isDarwin(); }; const sysroot = blk: { @@ -3582,7 +3582,7 @@ fn detectLibCIncludeDirs( // native abi, fall back to using the system libc installation. // On windows, instead of the native (mingw) abi, we want to check // for the MSVC abi as a fallback. - const use_system_abi = if (std.Target.current.os.tag == .windows) + const use_system_abi = if (builtin.target.os.tag == .windows) target.abi == .msvc else is_native_abi; diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 7386e426eb..4198e062bb 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -4,6 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. const std = @import("std"); +const builtin = @import("builtin"); const ThreadPool = @This(); lock: std.Thread.Mutex = .{}, @@ -57,7 +58,7 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void { .allocator = allocator, .workers = &[_]Worker{}, }; - if (std.builtin.single_threaded) + if (builtin.single_threaded) return; const worker_count = std.math.max(1, std.Thread.getCpuCount() catch 1); @@ -100,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void { } pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void { - if (std.builtin.single_threaded) { + if (builtin.single_threaded) { @call(.{}, func, args); return; } diff --git a/src/Zir.zig b/src/Zir.zig index e7359f9382..3f3a0dbafe 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -11,6 +11,7 @@ //! inline assembly is not an exception. const std = @import("std"); +const builtin = @import("builtin"); const mem = std.mem; const Allocator = std.mem.Allocator; const assert = std.debug.assert; @@ -2215,7 +2216,7 @@ pub const Inst = struct { // bigger than expected. Note that in Debug builds, Zig is allowed // to insert a secret field for safety checks. comptime { - if (std.builtin.mode != .Debug) { + if (builtin.mode != .Debug) { assert(@sizeOf(Data) == 8); } } diff --git a/src/codegen.zig b/src/codegen.zig index 33492ad2d5..b25e361f76 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const mem = std.mem; const math = std.math; const assert = std.debug.assert; @@ -522,7 +523,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { code: *std.ArrayList(u8), debug_output: DebugInfoOutput, ) GenerateSymbolError!FnResult { - if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) { + if (build_options.skip_non_native and builtin.cpu.arch != arch) { @panic("Attempted to compile for architecture that was disabled by build configuration"); } diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 06db6d3dc8..6fcde5eead 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const assert = std.debug.assert; const mem = std.mem; const log = std.log.scoped(.c); @@ -600,7 +601,7 @@ pub const DeclGen = struct { ); }, .ErrorSet => { - comptime std.debug.assert(Type.initTag(.anyerror).abiSize(std.Target.current) == 2); + comptime std.debug.assert(Type.initTag(.anyerror).abiSize(builtin.target) == 2); try w.writeAll("uint16_t"); }, .ErrorUnion => { diff --git a/src/introspect.zig b/src/introspect.zig index 18cad4cf81..be974d3efe 100644 --- a/src/introspect.zig +++ b/src/introspect.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const mem = std.mem; const fs = std.fs; const Compilation = @import("Compilation.zig"); @@ -71,7 +72,7 @@ pub fn resolveGlobalCacheDir(allocator: *mem.Allocator) ![]u8 { const appname = "zig"; - if (std.Target.current.os.tag != .windows) { + if (builtin.os.tag != .windows) { if (std.os.getenv("XDG_CACHE_HOME")) |cache_root| { return fs.path.join(allocator, &[_][]const u8{ cache_root, appname }); } else if (std.os.getenv("HOME")) |home| { diff --git a/src/libc_installation.zig b/src/libc_installation.zig index d54af71415..65bb2863f8 100644 --- a/src/libc_installation.zig +++ b/src/libc_installation.zig @@ -6,9 +6,9 @@ const Allocator = std.mem.Allocator; const Batch = std.event.Batch; const build_options = @import("build_options"); -const is_darwin = Target.current.isDarwin(); -const is_windows = Target.current.os.tag == .windows; -const is_haiku = Target.current.os.tag == .haiku; +const is_darwin = builtin.target.isDarwin(); +const is_windows = builtin.target.os.tag == .windows; +const is_haiku = builtin.target.os.tag == .haiku; const log = std.log.scoped(.libc_installation); @@ -219,7 +219,7 @@ pub const LibCInstallation = struct { var batch = Batch(FindError!void, 2, .auto_async).init(); errdefer batch.wait() catch {}; batch.add(&async self.findNativeIncludeDirPosix(args)); - switch (Target.current.os.tag) { + switch (builtin.target.os.tag) { .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"), .solaris => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib/64"), .linux => batch.add(&async self.findNativeCrtDirPosix(args)), diff --git a/src/link.zig b/src/link.zig index fe233e060f..9af7fe929c 100644 --- a/src/link.zig +++ b/src/link.zig @@ -292,7 +292,7 @@ pub const File = struct { // make executable, so we don't have to close it. return; } - if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64) { + if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) { if (base.options.target.cpu.arch != .aarch64) return; // If we're not targeting aarch64, nothing to do. // XNU starting with Big Sur running on arm64 is caching inodes of running binaries. // Any change to the binary will effectively invalidate the kernel's cache @@ -711,7 +711,7 @@ pub fn determineMode(options: Options) fs.File.Mode { // with 0o755 permissions, but it works appropriately if the system is configured // more leniently. As another data point, C's fopen seems to open files with the // 666 mode. - const executable_mode = if (std.Target.current.os.tag == .windows) 0 else 0o777; + const executable_mode = if (builtin.target.os.tag == .windows) 0 else 0o777; switch (options.effectiveOutputMode()) { .Lib => return switch (options.link_mode) { .Dynamic => executable_mode, diff --git a/src/link/Elf.zig b/src/link/Elf.zig index a8efa8dab9..705daaf997 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -755,7 +755,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented; const target_endian = self.base.options.target.cpu.arch.endian(); - const foreign_endian = target_endian != std.Target.current.cpu.arch.endian(); + const foreign_endian = target_endian != builtin.cpu.arch.endian(); const ptr_width_bytes: u8 = self.ptrWidthBytes(); const init_len_size: usize = switch (self.ptr_width) { .p32 => 4, @@ -2827,7 +2827,7 @@ pub fn deleteExport(self: *Elf, exp: Export) void { } fn writeProgHeader(self: *Elf, index: usize) !void { - const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian(); + const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian(); const offset = self.program_headers.items[index].p_offset; switch (self.ptr_width) { .p32 => { @@ -2848,7 +2848,7 @@ fn writeProgHeader(self: *Elf, index: usize) !void { } fn writeSectHeader(self: *Elf, index: usize) !void { - const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian(); + const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian(); switch (self.ptr_width) { .p32 => { var shdr: [1]elf.Elf32_Shdr = undefined; @@ -2946,7 +2946,7 @@ fn writeSymbol(self: *Elf, index: usize) !void { syms_sect.sh_size = needed_size; // anticipating adding the global symbols later self.shdr_table_dirty = true; // TODO look into only writing one section } - const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian(); + const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian(); switch (self.ptr_width) { .p32 => { var sym = [1]elf.Elf32_Sym{ @@ -2982,7 +2982,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void { .p32 => @sizeOf(elf.Elf32_Sym), .p64 => @sizeOf(elf.Elf64_Sym), }; - const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian(); + const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian(); const global_syms_off = syms_sect.sh_offset + self.local_symbols.items.len * sym_size; switch (self.ptr_width) { .p32 => { diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 9a2c462d55..81f26af1d5 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -967,7 +967,7 @@ fn resolveSearchDir( if (fs.path.isAbsolute(dir)) { if (syslibroot) |root| { - const common_dir = if (std.Target.current.os.tag == .windows) blk: { + const common_dir = if (builtin.os.tag == .windows) blk: { // We need to check for disk designator and strip it out from dir path so // that we can concat dir with syslibroot. // TODO we should backport this mechanism to 'MachO.Dylib.parseDependentLibs()' diff --git a/src/link/MachO/fat.zig b/src/link/MachO/fat.zig index c911d89535..f6bb598512 100644 --- a/src/link/MachO/fat.zig +++ b/src/link/MachO/fat.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = std.builtin; +const builtin = @import("builtin"); const log = std.log.scoped(.archive); const macho = std.macho; const mem = std.mem; @@ -23,7 +23,7 @@ fn readFatStruct(reader: anytype, comptime T: type) !T { // Fat structures (fat_header & fat_arch) are always written and read to/from // disk in big endian order. var res = try reader.readStruct(T); - if (native_endian != builtin.Endian.Big) { + if (native_endian != std.builtin.Endian.Big) { mem.bswapAllFields(T, &res); } return res; diff --git a/src/main.zig b/src/main.zig index ddccd02b6d..feaea7f435 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const assert = std.debug.assert; const io = std.io; const fs = std.fs; @@ -34,7 +35,7 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn { /// be byte-indexed with a u32 integer. pub const max_src_size = std.math.maxInt(u32); -pub const debug_extensions_enabled = std.builtin.mode == .Debug; +pub const debug_extensions_enabled = builtin.mode == .Debug; pub const Color = enum { auto, @@ -90,7 +91,7 @@ const debug_usage = normal_usage ++ const usage = if (debug_extensions_enabled) debug_usage else normal_usage; -pub const log_level: std.log.Level = switch (std.builtin.mode) { +pub const log_level: std.log.Level = switch (builtin.mode) { .Debug => .debug, .ReleaseSafe, .ReleaseFast => .info, .ReleaseSmall => .crit, @@ -142,7 +143,7 @@ pub fn main() anyerror!void { var gpa_need_deinit = false; const gpa = gpa: { - if (!std.builtin.link_libc) { + if (!builtin.link_libc) { gpa_need_deinit = true; break :gpa &general_purpose_allocator.allocator; } @@ -1688,13 +1689,13 @@ fn buildOutputType( } } - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { // If we want to link against frameworks, we need system headers. if (framework_dirs.items.len > 0 or frameworks.items.len > 0) want_native_include_dirs = true; } - const is_darwin_on_darwin = (comptime std.Target.current.isDarwin()) and cross_target.isDarwin(); + const is_darwin_on_darwin = (comptime builtin.target.isDarwin()) and cross_target.isDarwin(); if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and (system_libs.items.len != 0 or want_native_include_dirs)) @@ -1706,7 +1707,7 @@ fn buildOutputType( warn("{s}", .{warning}); } - const has_sysroot = if (comptime std.Target.current.isDarwin()) outer: { + const has_sysroot = if (comptime builtin.target.isDarwin()) outer: { const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: { const min = target_info.target.os.getVersionRange().semver.min; const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14); @@ -2355,7 +2356,7 @@ fn runOrTest( defer argv.deinit(); if (test_exec_args.len == 0) { - if (!std.Target.current.canExecBinariesOf(target)) { + if (!builtin.target.canExecBinariesOf(target)) { switch (arg_mode) { .zig_test => { warn("created {s} but skipping execution because it is non-native", .{exe_path}); @@ -3915,7 +3916,7 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { const posix = std.os; var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. - if (comptime std.Target.current.isDarwin()) { + if (comptime builtin.target.isDarwin()) { // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`. // According to the man pages for setrlimit(): // setrlimit() now returns with errno set to EINVAL in places that historically succeeded. @@ -3959,7 +3960,7 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s /// check for resource leaks can be accurate. In release builds, this /// calls exit(0), and does not return. pub fn cleanExit() void { - if (std.builtin.mode == .Debug) { + if (builtin.mode == .Debug) { return; } else { process.exit(0); diff --git a/src/tracy.zig b/src/tracy.zig index 9ea15d721b..96f5fd998c 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -1,6 +1,7 @@ -pub const std = @import("std"); +const std = @import("std"); +const builtin = @import("builtin"); -pub const enable = if (std.builtin.is_test) false else @import("build_options").enable_tracy; +pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy; extern fn ___tracy_emit_zone_begin_callstack( srcloc: *const ___tracy_source_location_data, diff --git a/test/assemble_and_link.zig b/test/assemble_and_link.zig index 86209bd034..82d395df1c 100644 --- a/test/assemble_and_link.zig +++ b/test/assemble_and_link.zig @@ -1,8 +1,9 @@ const std = @import("std"); +const builtin = @import("builtin"); const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompareOutputContext) void { - if (std.Target.current.os.tag == .linux and std.Target.current.cpu.arch == .x86_64) { + if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64) { cases.addAsm("hello world linux x86_64", \\.text \\.globl _start diff --git a/test/behavior/asm.zig b/test/behavior/asm.zig index 4b52aff92b..f856f0128e 100644 --- a/test/behavior/asm.zig +++ b/test/behavior/asm.zig @@ -1,7 +1,8 @@ const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; -const is_x86_64_linux = std.Target.current.cpu.arch == .x86_64 and std.Target.current.os.tag == .linux; +const is_x86_64_linux = builtin.cpu.arch == .x86_64 and builtin.os.tag == .linux; comptime { if (is_x86_64_linux) { diff --git a/test/behavior/atomics.zig b/test/behavior/atomics.zig index b22183bdbd..37bc9930a7 100644 --- a/test/behavior/atomics.zig +++ b/test/behavior/atomics.zig @@ -1,7 +1,7 @@ const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -const builtin = @import("builtin"); test "cmpxchg" { try testCmpxchg(); diff --git a/test/behavior/namespace_depends_on_compile_var.zig b/test/behavior/namespace_depends_on_compile_var.zig index 3e8cab3528..84b7e21d38 100644 --- a/test/behavior/namespace_depends_on_compile_var.zig +++ b/test/behavior/namespace_depends_on_compile_var.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const expect = std.testing.expect; test "namespace depends on compile var" { @@ -8,7 +9,7 @@ test "namespace depends on compile var" { try expect(!some_namespace.a_bool); } } -const some_namespace = switch (std.builtin.os.tag) { +const some_namespace = switch (builtin.os.tag) { .linux => @import("namespace_depends_on_compile_var/a.zig"), else => @import("namespace_depends_on_compile_var/b.zig"), }; diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 09bd305c68..a0fe4855cb 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; diff --git a/test/behavior/sizeof_and_typeof_stage1.zig b/test/behavior/sizeof_and_typeof_stage1.zig index 974e79015f..429b530a93 100644 --- a/test/behavior/sizeof_and_typeof_stage1.zig +++ b/test/behavior/sizeof_and_typeof_stage1.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = std.builtin; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 7ab1cd59ed..946aba0949 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -674,7 +674,7 @@ test "saturating subtraction" { test "saturating multiplication" { // TODO: once #9660 has been solved, remove this line - if (std.builtin.target.cpu.arch == .wasm32) return error.SkipZigTest; + if (builtin.target.cpu.arch == .wasm32) return error.SkipZigTest; const S = struct { fn doTheTest() !void { diff --git a/test/cli.zig b/test/cli.zig index 59fb7095af..fb322f0f0e 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const testing = std.testing; const process = std.process; const fs = std.fs; @@ -97,7 +98,7 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void { } fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { - if (std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64) return; + if (builtin.os.tag != .linux or builtin.cpu.arch != .x86_64) return; const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" }); const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" }); diff --git a/test/compare_output.zig b/test/compare_output.zig index 7ff428fb33..35400e2e2a 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -28,7 +28,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.addC("number literals", \\const std = @import("std"); - \\const is_windows = std.Target.current.os.tag == .windows; + \\const builtin = @import("builtin"); + \\const is_windows = builtin.os.tag == .windows; \\const c = @cImport({ \\ if (is_windows) { \\ // See https://github.com/ziglang/zig/issues/515 @@ -207,7 +208,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.addC("casting between float and integer types", \\const std = @import("std"); - \\const is_windows = std.Target.current.os.tag == .windows; + \\const builtin = @import("builtin"); + \\const is_windows = builtin.os.tag == .windows; \\const c = @cImport({ \\ if (is_windows) { \\ // See https://github.com/ziglang/zig/issues/515 diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 4acd563da9..ab0d504e68 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const TestContext = @import("../src/test.zig").TestContext; pub fn addCases(ctx: *TestContext) !void { @@ -2898,7 +2899,7 @@ pub fn addCases(ctx: *TestContext) !void { "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", }); - if (std.Target.current.os.tag == .linux) { + if (builtin.os.tag == .linux) { ctx.testErrStage1("implicit dependency on libc", \\extern "c" fn exit(u8) void; \\export fn entry() void { @@ -8834,9 +8835,10 @@ pub fn addCases(ctx: *TestContext) !void { ctx.objErrStage1("Issue #9165: windows tcp server compilation error", \\const std = @import("std"); + \\const builtin = @import("builtin"); \\pub const io_mode = .evented; \\pub fn main() !void { - \\ if (std.builtin.os.tag == .windows) { + \\ if (builtin.os.tag == .windows) { \\ _ = try (std.net.StreamServer.init(.{})).accept(); \\ } else { \\ @compileError("Unsupported OS"); diff --git a/test/src/compare_output.zig b/test/src/compare_output.zig index 16884bee61..0f824f0650 100644 --- a/test/src/compare_output.zig +++ b/test/src/compare_output.zig @@ -1,14 +1,13 @@ // This is the implementation of the test harness. // For the actual test cases, see test/compare_output.zig. const std = @import("std"); -const builtin = std.builtin; const build = std.build; const ArrayList = std.ArrayList; const fmt = std.fmt; const mem = std.mem; const fs = std.fs; const warn = std.debug.warn; -const Mode = builtin.Mode; +const Mode = std.builtin.Mode; pub const CompareOutputContext = struct { b: *build.Builder, diff --git a/test/standalone.zig b/test/standalone.zig index c5e12f1dcc..f0a783a8a9 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const tests = @import("tests.zig"); pub fn addCases(cases: *tests.StandaloneContext) void { @@ -29,19 +30,19 @@ pub fn addCases(cases: *tests.StandaloneContext) void { cases.addBuildFile("test/standalone/issue_7030/build.zig", .{}); cases.addBuildFile("test/standalone/install_raw_hex/build.zig", .{}); cases.addBuildFile("test/standalone/issue_9812/build.zig", .{}); - if (std.Target.current.os.tag != .wasi) { + if (builtin.os.tag != .wasi) { cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{}); } - if (std.Target.current.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures + if (builtin.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures cases.addBuildFile("test/stage1/c_abi/build.zig", .{}); } cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true }); - if (std.Target.current.os.tag == .windows) { + if (builtin.os.tag == .windows) { cases.addC("test/standalone/issue_9402/main.zig"); } // Try to build and run a PIE executable. - if (std.Target.current.os.tag == .linux) { + if (builtin.os.tag == .linux) { cases.addBuildFile("test/standalone/pie/build.zig", .{}); } // Try to build and run an Objective-C executable. diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index 78c9c45dc0..c1efb160ef 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -1,12 +1,13 @@ const std = @import("std"); +const builtin = @import("builtin"); const Builder = std.build.Builder; const CrossTarget = std.zig.CrossTarget; fn isRunnableTarget(t: CrossTarget) bool { if (t.isNative()) return true; - return (t.getOsTag() == std.Target.current.os.tag and - t.getCpuArch() == std.Target.current.cpu.arch); + return (t.getOsTag() == builtin.os.tag and + t.getCpuArch() == builtin.cpu.arch); } pub fn build(b: *Builder) void { diff --git a/test/standalone/install_raw_hex/build.zig b/test/standalone/install_raw_hex/build.zig index b51920439f..086fafebbc 100644 --- a/test/standalone/install_raw_hex/build.zig +++ b/test/standalone/install_raw_hex/build.zig @@ -28,14 +28,14 @@ pub fn build(b: *Builder) void { const expected_hex = &[_][]const u8{ ":020000021000EC", - ":1000D400D001010001000000D20101000100000074", - ":1000E40028020100010000002402010001000000B8", - ":1000F4003A02010001000000E202010001000000D8", - ":100104000C03010001000000A50202000000000031", + ":1000D400A401010001000000A601010001000000CC", + ":1000E400FC01010001000000F80101000100000012", + ":1000F4000E02010001000000B60201000100000030", + ":10010400E00201000100000079020200000000008A", ":1001140000000000000000000000000000000000DB", ":1001240000000000000000000000000000000000CB", ":1001340000000000000000000000000000000000BB", - ":10014400AF02020098020100090000004D02010004", + ":10014400830202006C020100090000002102010088", ":100154000900000001000000000000000000000091", ":1001640000080002008001010004000010000000EB", ":100174000000000000000000000000001F0000005C", @@ -44,55 +44,52 @@ pub fn build(b: *Builder) void { ":1001A40000000000000000001F000000000000002C", ":1001B400000000000000000000000000000000003B", ":1001C400000000000000000000000000000000002B", - ":1001D400000000000000000000000000000000001B", - ":1001E400000000000000000000000000000000000B", - ":1001F4000000000000000000000000008702010071", - ":1002040010000000200201002C0000006B0201001D", - ":100214001B000000570201001300000072656D61AD", - ":10022400696E646572206469766973696F6E2062B1", - ":1002340079207A65726F206F72206E6567617469C8", - ":1002440076652076616C756500636F727465782DD0", - ":100254006D3400696E646578206F7574206F662054", - ":10026400626F756E647300696E746567657220638E", - ":10027400617374207472756E63617465642062695D", - ":100284007473006469766973696F6E206279207A89", - ":1002940065726F00636F727465785F6D340000007F", - ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A", - ":1002B4000391029007A800F029F803990020069002", - ":1002C40048680490FFE704990698019088420FD289", - ":1002D400FFE7019903980068405C07F8310C17F8B0", - ":1002E400311C07A800F021F8019801300690EAE7D4", - ":1002F400029807A9B1E80C50A0E80C5091E81C50F2", - ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7", - ":1003140040F2DC11C0F20101B1E80C50A0E80C502D", - ":1003240091E81C5080E81C50D0BD80B56F4688B061", - ":1003340006906FF35F2127F80A1C37F80A0C049023", - ":10034400012038B9FFE740F20020C0F2010000218B", - ":10035400FFF7A6FF0498C0F3431027F8020C37F800", - ":100364000A0C0390002038B9FFE7039800F01F003F", - ":100374000290012038B914E040F20820C0F20100D4", - ":100384000021FFF78DFF029800F01F0007F8030C0F", - ":100394000698009037F8020C0146019109280ED303", - ":1003A40006E040F21020C0F201000021FFF778FFC0", - ":1003B40040F21820C0F201000021FFF771FF0099FC", - ":1003C400019A51F8220017F803CC012303FA0CF325", - ":1003D400184341F8220008B080BD81B000F03F000E", - ":1003E4008DF802009DF802000F3000F03F00022853", - ":1003F40004D3FFE700208DF8030003E001208DF80B", - ":100404000300FFE79DF8030001B070470A000000F5", - ":1004140012000000020071001200000066000000DB", - ":1004240003007D0C06000000000000000001110123", - ":10043400250E1305030E10171B0EB44219110112D9", - ":0604440006000002340076", + ":1001D4005B02010010000000F40101002C0000008B", + ":1001E4003F0201001B0000002B020100130000006D", + ":1001F40072656D61696E646572206469766973699C", + ":100204006F6E206279207A65726F206F72206E653E", + ":100214006761746976652076616C756500636F72D9", + ":100224007465782D6D3400696E646578206F75741B", + ":10023400206F6620626F756E647300696E74656703", + ":1002440065722063617374207472756E6361746582", + ":10025400642062697473006469766973696F6E20DF", + ":100264006279207A65726F00636F727465785F6D6E", + ":100274003400000081B00091FFE700BEFDE7D0B577", + ":1002840002AF90B00391029007A800F029F80399F7", + ":100294000020069048680490FFE7049906980190AE", + ":1002A40088420FD2FFE7019903980068405C07F881", + ":1002B400310C17F8311C07A800F021F8019801301F", + ":1002C4000690EAE7029807A9B1E80C50A0E80C50A0", + ":1002D40091E81C5080E81C5010B0D0BDFFE7FEE749", + ":1002E400D0B502AF40F2B011C0F20101B1E80C5038", + ":1002F400A0E80C5091E81C5080E81C50D0BD80B59B", + ":100304006F4688B006906FF35F2127F80A1C37F810", + ":100314000A0C0490012038B9FFE740F2D410C0F26F", + ":1003240001000021FFF7A6FF0498C0F3431027F84B", + ":10033400020C37F80A0C0390002038B9FFE7039841", + ":1003440000F01F000290012038B914E040F2DC10E4", + ":10035400C0F201000021FFF78DFF029800F01F009A", + ":1003640007F8030C0698009037F8020C0146019137", + ":1003740009280ED306E040F2E410C0F20100002187", + ":10038400FFF778FF40F2EC10C0F201000021FFF704", + ":1003940071FF0099019A51F8220017F803CC012348", + ":1003A40003FA0CF3184341F8220008B080BD81B071", + ":1003B40000F03F008DF802009DF802000F3000F0BD", + ":1003C4003F00022804D3FFE700208DF8030003E078", + ":1003D40001208DF80300FFE79DF8030001B070478A", + ":1003E4000A00000012000000020071001200000068", + ":1003F4006600000003007D0C060000000000000001", + ":1004040000011101250E1305030E10171B0EB44233", + ":0A0414001911011206000002340065", ":020000021000EC", - ":1000D400D001010001000000D20101000100000074", - ":1000E40028020100010000002402010001000000B8", - ":1000F4003A02010001000000E202010001000000D8", - ":100104000C03010001000000A50202000000000031", + ":1000D400A401010001000000A601010001000000CC", + ":1000E400FC01010001000000F80101000100000012", + ":1000F4000E02010001000000B60201000100000030", + ":10010400E00201000100000079020200000000008A", ":1001140000000000000000000000000000000000DB", ":1001240000000000000000000000000000000000CB", ":1001340000000000000000000000000000000000BB", - ":10014400AF02020098020100090000004D02010004", + ":10014400830202006C020100090000002102010088", ":100154000900000001000000000000000000000091", ":1001640000080002008001010004000010000000EB", ":100174000000000000000000000000001F0000005C", @@ -101,70 +98,67 @@ pub fn build(b: *Builder) void { ":1001A40000000000000000001F000000000000002C", ":1001B400000000000000000000000000000000003B", ":1001C400000000000000000000000000000000002B", - ":1001D400000000000000000000000000000000001B", - ":1001E400000000000000000000000000000000000B", - ":1001F4000000000000000000000000008702010071", - ":1002040010000000200201002C0000006B0201001D", - ":100214001B000000570201001300000072656D61AD", - ":10022400696E646572206469766973696F6E2062B1", - ":1002340079207A65726F206F72206E6567617469C8", - ":1002440076652076616C756500636F727465782DD0", - ":100254006D3400696E646578206F7574206F662054", - ":10026400626F756E647300696E746567657220638E", - ":10027400617374207472756E63617465642062695D", - ":100284007473006469766973696F6E206279207A89", - ":1002940065726F00636F727465785F6D340000007F", - ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A", - ":1002B4000391029007A800F029F803990020069002", - ":1002C40048680490FFE704990698019088420FD289", - ":1002D400FFE7019903980068405C07F8310C17F8B0", - ":1002E400311C07A800F021F8019801300690EAE7D4", - ":1002F400029807A9B1E80C50A0E80C5091E81C50F2", - ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7", - ":1003140040F2DC11C0F20101B1E80C50A0E80C502D", - ":1003240091E81C5080E81C50D0BD80B56F4688B061", - ":1003340006906FF35F2127F80A1C37F80A0C049023", - ":10034400012038B9FFE740F20020C0F2010000218B", - ":10035400FFF7A6FF0498C0F3431027F8020C37F800", - ":100364000A0C0390002038B9FFE7039800F01F003F", - ":100374000290012038B914E040F20820C0F20100D4", - ":100384000021FFF78DFF029800F01F0007F8030C0F", - ":100394000698009037F8020C0146019109280ED303", - ":1003A40006E040F21020C0F201000021FFF778FFC0", - ":1003B40040F21820C0F201000021FFF771FF0099FC", - ":1003C400019A51F8220017F803CC012303FA0CF325", - ":1003D400184341F8220008B080BD81B000F03F000E", - ":1003E4008DF802009DF802000F3000F03F00022853", - ":1003F40004D3FFE700208DF8030003E001208DF80B", - ":100404000300FFE79DF8030001B070470A000000F5", - ":1004140012000000020071001200000066000000DB", - ":1004240003007D0C06000000000000000001110123", - ":10043400250E1305030E10171B0EB44219110112D9", - ":0604440006000002340076", + ":1001D4005B02010010000000F40101002C0000008B", + ":1001E4003F0201001B0000002B020100130000006D", + ":1001F40072656D61696E646572206469766973699C", + ":100204006F6E206279207A65726F206F72206E653E", + ":100214006761746976652076616C756500636F72D9", + ":100224007465782D6D3400696E646578206F75741B", + ":10023400206F6620626F756E647300696E74656703", + ":1002440065722063617374207472756E6361746582", + ":10025400642062697473006469766973696F6E20DF", + ":100264006279207A65726F00636F727465785F6D6E", + ":100274003400000081B00091FFE700BEFDE7D0B577", + ":1002840002AF90B00391029007A800F029F80399F7", + ":100294000020069048680490FFE7049906980190AE", + ":1002A40088420FD2FFE7019903980068405C07F881", + ":1002B400310C17F8311C07A800F021F8019801301F", + ":1002C4000690EAE7029807A9B1E80C50A0E80C50A0", + ":1002D40091E81C5080E81C5010B0D0BDFFE7FEE749", + ":1002E400D0B502AF40F2B011C0F20101B1E80C5038", + ":1002F400A0E80C5091E81C5080E81C50D0BD80B59B", + ":100304006F4688B006906FF35F2127F80A1C37F810", + ":100314000A0C0490012038B9FFE740F2D410C0F26F", + ":1003240001000021FFF7A6FF0498C0F3431027F84B", + ":10033400020C37F80A0C0390002038B9FFE7039841", + ":1003440000F01F000290012038B914E040F2DC10E4", + ":10035400C0F201000021FFF78DFF029800F01F009A", + ":1003640007F8030C0698009037F8020C0146019137", + ":1003740009280ED306E040F2E410C0F20100002187", + ":10038400FFF778FF40F2EC10C0F201000021FFF704", + ":1003940071FF0099019A51F8220017F803CC012348", + ":1003A40003FA0CF3184341F8220008B080BD81B071", + ":1003B40000F03F008DF802009DF802000F3000F0BD", + ":1003C4003F00022804D3FFE700208DF8030003E078", + ":1003D40001208DF80300FFE79DF8030001B070478A", + ":1003E4000A00000012000000020071001200000068", + ":1003F4006600000003007D0C060000000000000001", + ":1004040000011101250E1305030E10171B0EB44233", + ":0A0414001911011206000002340065", ":020000022000DC", - ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A", - ":1002B4000391029007A800F029F803990020069002", - ":1002C40048680490FFE704990698019088420FD289", - ":1002D400FFE7019903980068405C07F8310C17F8B0", - ":1002E400311C07A800F021F8019801300690EAE7D4", - ":1002F400029807A9B1E80C50A0E80C5091E81C50F2", - ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7", - ":1003140040F2DC11C0F20101B1E80C50A0E80C502D", - ":1003240091E81C5080E81C50D0BD80B56F4688B061", - ":1003340006906FF35F2127F80A1C37F80A0C049023", - ":10034400012038B9FFE740F20020C0F2010000218B", - ":10035400FFF7A6FF0498C0F3431027F8020C37F800", - ":100364000A0C0390002038B9FFE7039800F01F003F", - ":100374000290012038B914E040F20820C0F20100D4", - ":100384000021FFF78DFF029800F01F0007F8030C0F", - ":100394000698009037F8020C0146019109280ED303", - ":1003A40006E040F21020C0F201000021FFF778FFC0", - ":1003B40040F21820C0F201000021FFF771FF0099FC", - ":1003C400019A51F8220017F803CC012303FA0CF325", - ":1003D400184341F8220008B080BD81B000F03F000E", - ":1003E4008DF802009DF802000F3000F03F00022853", - ":1003F40004D3FFE700208DF8030003E001208DF80B", - ":0C0404000300FFE79DF8030001B0704703", + ":1002780081B00091FFE700BEFDE7D0B502AF90B0B6", + ":100288000391029007A800F029F80399002006902E", + ":1002980048680490FFE704990698019088420FD2B5", + ":1002A800FFE7019903980068405C07F8310C17F8DC", + ":1002B800311C07A800F021F8019801300690EAE700", + ":1002C800029807A9B1E80C50A0E80C5091E81C501E", + ":1002D80080E81C5010B0D0BDFFE7FEE7D0B502AFF4", + ":1002E80040F2B011C0F20101B1E80C50A0E80C5086", + ":1002F80091E81C5080E81C50D0BD80B56F4688B08E", + ":1003080006906FF35F2127F80A1C37F80A0C04904F", + ":10031800012038B9FFE740F2D410C0F201000021F3", + ":10032800FFF7A6FF0498C0F3431027F8020C37F82C", + ":100338000A0C0390002038B9FFE7039800F01F006B", + ":100348000290012038B914E040F2DC10C0F201003C", + ":100358000021FFF78DFF029800F01F0007F8030C3B", + ":100368000698009037F8020C0146019109280ED32F", + ":1003780006E040F2E410C0F201000021FFF778FF28", + ":1003880040F2EC10C0F201000021FFF771FF009964", + ":10039800019A51F8220017F803CC012303FA0CF351", + ":1003A800184341F8220008B080BD81B000F03F003A", + ":1003B8008DF802009DF802000F3000F03F0002287F", + ":1003C80004D3FFE700208DF8030003E001208DF837", + ":0C03D8000300FFE79DF8030001B0704730", ":00000001FF", }; diff --git a/test/tests.zig b/test/tests.zig index 0577092845..d84635f03c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = std.builtin; +const builtin = @import("builtin"); const debug = std.debug; const warn = debug.warn; const build = std.build; @@ -9,7 +9,7 @@ const fs = std.fs; const mem = std.mem; const fmt = std.fmt; const ArrayList = std.ArrayList; -const Mode = builtin.Mode; +const Mode = std.builtin.Mode; const LibExeObjStep = build.LibExeObjStep; // Cases @@ -29,7 +29,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput const TestTarget = struct { target: CrossTarget = @as(CrossTarget, .{}), - mode: builtin.Mode = .Debug, + mode: std.builtin.Mode = .Debug, link_libc: bool = false, single_threaded: bool = false, disable_native: bool = false, @@ -532,8 +532,8 @@ pub fn addPkgTests( continue; if (test_target.disable_native and - test_target.target.getOsTag() == std.Target.current.os.tag and - test_target.target.getCpuArch() == std.Target.current.cpu.arch) + test_target.target.getOsTag() == builtin.os.tag and + test_target.target.getCpuArch() == builtin.cpu.arch) { continue; } @@ -785,7 +785,7 @@ pub const StackTracesContext = struct { if (line.len == 0) continue; // offset search past `[drive]:` on windows - var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0; + var pos: usize = if (builtin.os.tag == .windows) 2 else 0; // locate delims/anchor const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" }; var marks = [_]usize{0} ** delims.len; @@ -1055,7 +1055,7 @@ pub const GenHContext = struct { pub fn addCase(self: *GenHContext, case: *const TestCase) void { const b = self.b; - const mode = builtin.Mode.Debug; + const mode = std.builtin.Mode.Debug; const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable; if (self.test_filter) |filter| { if (mem.indexOf(u8, annotated_case_name, filter) == null) return; diff --git a/test/translate_c.zig b/test/translate_c.zig index db665124ba..eb38e4e011 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1,9 +1,10 @@ -const tests = @import("tests.zig"); const std = @import("std"); +const builtin = @import("builtin"); +const tests = @import("tests.zig"); const CrossTarget = std.zig.CrossTarget; pub fn addCases(cases: *tests.TranslateCContext) void { - const default_enum_type = if (std.Target.current.abi == .msvc) "c_int" else "c_uint"; + const default_enum_type = if (builtin.abi == .msvc) "c_int" else "c_uint"; cases.add("field access is grouped if necessary", \\unsigned long foo(unsigned long x) { @@ -1153,7 +1154,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void {} }); - if (std.Target.current.os.tag != .windows) { + if (builtin.os.tag != .windows) { // Windows treats this as an enum with type c_int cases.add("big negative enum init values when C ABI supports long long enums", \\enum EnumWithInits { @@ -1558,7 +1559,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} }); - if (std.Target.current.os.tag != .windows) { + if (builtin.os.tag != .windows) { // sysv_abi not currently supported on windows cases.add("Macro qualified functions", \\void __attribute__((sysv_abi)) foo(void); @@ -2160,7 +2161,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} }); - if (std.Target.current.os.tag != .windows) { + if (builtin.os.tag != .windows) { // When clang uses the -windows-none triple it behaves as MSVC and // interprets the inner `struct Bar` as an anonymous structure cases.add("type referenced struct", @@ -3398,7 +3399,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const FOO = @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.promoteIntLiteral(c_int, 0x8000, .hexadecimal)); }); - if (std.Target.current.abi == .msvc) { + if (builtin.abi == .msvc) { cases.add("nameless struct fields", \\typedef struct NAMED \\{ diff --git a/tools/update_cpu_features.zig b/tools/update_cpu_features.zig index 59107a4317..a03d740844 100644 --- a/tools/update_cpu_features.zig +++ b/tools/update_cpu_features.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const fs = std.fs; const mem = std.mem; const json = std.json; @@ -803,7 +804,7 @@ pub fn main() anyerror!void { const root_progress = try progress.start("", llvm_targets.len); defer root_progress.end(); - if (std.builtin.single_threaded) { + if (builtin.single_threaded) { for (llvm_targets) |llvm_target| { try processOneTarget(Job{ .llvm_tblgen_exe = llvm_tblgen_exe,