authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-04 23:47:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-04 23:48:55-07:00
log6115cf22404467fd13d0290fc022d51d372d139a
tree26c0bab951c81e89b5f0edcc5dc9f4b8e64df7db
parent78902db68bbd400f6d84b65280c31d417105f2a8

migrate from `std.Target.current` to `@import("builtin").target`

closes #9388 closes #9321

147 files changed, 624 insertions(+), 596 deletions(-)

doc/docgen.zig+2-2
...@@ -1334,7 +1334,7 @@ fn genHtml(...@@ -1334,7 +1334,7 @@ fn genHtml(
1334 if (mem.startsWith(u8, triple, "wasm32") or1334 if (mem.startsWith(u8, triple, "wasm32") or
1335 mem.startsWith(u8, triple, "riscv64-linux") or1335 mem.startsWith(u8, triple, "riscv64-linux") or
1336 (mem.startsWith(u8, triple, "x86_64-linux") and1336 (mem.startsWith(u8, triple, "x86_64-linux") and
1337 std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64))1337 builtin.os.tag != .linux or builtin.cpu.arch != .x86_64))
1338 {1338 {
1339 // skip execution1339 // skip execution
1340 break :code_block;1340 break :code_block;
...@@ -1602,7 +1602,7 @@ fn genHtml(...@@ -1602,7 +1602,7 @@ fn genHtml(
1602 Code.Id.Lib => {1602 Code.Id.Lib => {
1603 const bin_basename = try std.zig.binNameAlloc(allocator, .{1603 const bin_basename = try std.zig.binNameAlloc(allocator, .{
1604 .root_name = code.name,1604 .root_name = code.name,
1605 .target = std.Target.current,1605 .target = builtin.target,
1606 .output_mode = .Lib,1606 .output_mode = .Lib,
1607 });1607 });
16081608
doc/langref.html.in+7-4
...@@ -2681,6 +2681,7 @@ test "pointer child type" {...@@ -2681,6 +2681,7 @@ test "pointer child type" {
2681 </p>2681 </p>
2682 {#code_begin|test|variable_alignment#}2682 {#code_begin|test|variable_alignment#}
2683const std = @import("std");2683const std = @import("std");
2684const builtin = @import("builtin");
2684const expect = std.testing.expect;2685const expect = std.testing.expect;
26852686
2686test "variable alignment" {2687test "variable alignment" {
...@@ -2688,7 +2689,7 @@ test "variable alignment" {...@@ -2688,7 +2689,7 @@ test "variable alignment" {
2688 const align_of_i32 = @alignOf(@TypeOf(x));2689 const align_of_i32 = @alignOf(@TypeOf(x));
2689 try expect(@TypeOf(&x) == *i32);2690 try expect(@TypeOf(&x) == *i32);
2690 try expect(*i32 == *align(align_of_i32) i32);2691 try expect(*i32 == *align(align_of_i32) i32);
2691 if (std.Target.current.cpu.arch == .x86_64) {2692 if (builtin.target.cpu.arch == .x86_64) {
2692 try expect(@typeInfo(*i32).Pointer.alignment == 4);2693 try expect(@typeInfo(*i32).Pointer.alignment == 4);
2693 }2694 }
2694}2695}
...@@ -3878,6 +3879,7 @@ test "separate scopes" {...@@ -3878,6 +3879,7 @@ test "separate scopes" {
3878 {#header_open|switch#}3879 {#header_open|switch#}
3879 {#code_begin|test|switch#}3880 {#code_begin|test|switch#}
3880const std = @import("std");3881const std = @import("std");
3882const builtin = @import("builtin");
3881const expect = std.testing.expect;3883const expect = std.testing.expect;
38823884
3883test "switch simple" {3885test "switch simple" {
...@@ -3922,7 +3924,7 @@ test "switch simple" {...@@ -3922,7 +3924,7 @@ test "switch simple" {
3922}3924}
39233925
3924// Switch expressions can be used outside a function:3926// Switch expressions can be used outside a function:
3925const os_msg = switch (std.Target.current.os.tag) {3927const os_msg = switch (builtin.target.os.tag) {
3926 .linux => "we found a linux user",3928 .linux => "we found a linux user",
3927 else => "not a linux user",3929 else => "not a linux user",
3928};3930};
...@@ -3930,7 +3932,7 @@ const os_msg = switch (std.Target.current.os.tag) {...@@ -3930,7 +3932,7 @@ const os_msg = switch (std.Target.current.os.tag) {
3930// Inside a function, switch statements implicitly are compile-time3932// Inside a function, switch statements implicitly are compile-time
3931// evaluated if the target expression is compile-time known.3933// evaluated if the target expression is compile-time known.
3932test "switch inside function" {3934test "switch inside function" {
3933 switch (std.Target.current.os.tag) {3935 switch (builtin.target.os.tag) {
3934 .fuchsia => {3936 .fuchsia => {
3935 // On an OS other than fuchsia, block is not even analyzed,3937 // On an OS other than fuchsia, block is not even analyzed,
3936 // so this compile error is not triggered.3938 // so this compile error is not triggered.
...@@ -5690,6 +5692,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {...@@ -5690,6 +5692,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
5690 </p>5692 </p>
5691 {#code_begin|test|test_integer_widening#}5693 {#code_begin|test|test_integer_widening#}
5692const std = @import("std");5694const std = @import("std");
5695const builtin = @import("builtin");
5693const expect = std.testing.expect;5696const expect = std.testing.expect;
5694const mem = std.mem;5697const mem = std.mem;
56955698
...@@ -5712,7 +5715,7 @@ test "implicit unsigned integer to signed integer" {...@@ -5712,7 +5715,7 @@ test "implicit unsigned integer to signed integer" {
5712test "float widening" {5715test "float widening" {
5713 // Note: there is an open issue preventing this from working on aarch64:5716 // Note: there is an open issue preventing this from working on aarch64:
5714 // https://github.com/ziglang/zig/issues/32825717 // https://github.com/ziglang/zig/issues/3282
5715 if (std.Target.current.cpu.arch == .aarch64) return error.SkipZigTest;5718 if (builtin.target.cpu.arch == .aarch64) return error.SkipZigTest;
57165719
5717 var a: f16 = 12.34;5720 var a: f16 = 12.34;
5718 var b: f32 = a;5721 var b: f32 = a;
lib/std/Progress.zig+4-3
...@@ -7,6 +7,7 @@...@@ -7,6 +7,7 @@
7//! * `initial_delay_ms`7//! * `initial_delay_ms`
88
9const std = @import("std");9const std = @import("std");
10const builtin = @import("builtin");
10const windows = std.os.windows;11const windows = std.os.windows;
11const testing = std.testing;12const testing = std.testing;
12const assert = std.debug.assert;13const assert = std.debug.assert;
...@@ -144,10 +145,10 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) !*...@@ -144,10 +145,10 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) !*
144 if (stderr.supportsAnsiEscapeCodes()) {145 if (stderr.supportsAnsiEscapeCodes()) {
145 self.terminal = stderr;146 self.terminal = stderr;
146 self.supports_ansi_escape_codes = true;147 self.supports_ansi_escape_codes = true;
147 } else if (std.builtin.os.tag == .windows and stderr.isTty()) {148 } else if (builtin.os.tag == .windows and stderr.isTty()) {
148 self.is_windows_terminal = true;149 self.is_windows_terminal = true;
149 self.terminal = stderr;150 self.terminal = stderr;
150 } else if (std.builtin.os.tag != .windows) {151 } else if (builtin.os.tag != .windows) {
151 // we are in a "dumb" terminal like in acme or writing to a file152 // we are in a "dumb" terminal like in acme or writing to a file
152 self.terminal = stderr;153 self.terminal = stderr;
153 }154 }
...@@ -200,7 +201,7 @@ fn refreshWithHeldLock(self: *Progress) void {...@@ -200,7 +201,7 @@ fn refreshWithHeldLock(self: *Progress) void {
200 if (self.supports_ansi_escape_codes) {201 if (self.supports_ansi_escape_codes) {
201 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{d}D", .{self.columns_written}) catch unreachable).len;202 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{d}D", .{self.columns_written}) catch unreachable).len;
202 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;203 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
203 } else if (std.builtin.os.tag == .windows) winapi: {204 } else if (builtin.os.tag == .windows) winapi: {
204 std.debug.assert(self.is_windows_terminal);205 std.debug.assert(self.is_windows_terminal);
205206
206 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;207 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
lib/std/Thread/AutoResetEvent.zig+1-1
...@@ -26,7 +26,7 @@...@@ -26,7 +26,7 @@
26state: usize = UNSET,26state: usize = UNSET,
2727
28const std = @import("../std.zig");28const std = @import("../std.zig");
29const builtin = std.builtin;29const builtin = @import("builtin");
30const testing = std.testing;30const testing = std.testing;
31const assert = std.debug.assert;31const assert = std.debug.assert;
32const StaticResetEvent = std.Thread.StaticResetEvent;32const StaticResetEvent = std.Thread.StaticResetEvent;
lib/std/Thread/Condition.zig+5-4
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5impl: Impl = .{},5impl: Impl = .{},
66
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const builtin = @import("builtin");
8const Condition = @This();9const Condition = @This();
9const windows = std.os.windows;10const windows = std.os.windows;
10const linux = std.os.linux;11const linux = std.os.linux;
...@@ -23,9 +24,9 @@ pub fn broadcast(cond: *Condition) void {...@@ -23,9 +24,9 @@ pub fn broadcast(cond: *Condition) void {
23 cond.impl.broadcast();24 cond.impl.broadcast();
24}25}
2526
26const Impl = if (std.builtin.single_threaded)27const Impl = if (builtin.single_threaded)
27 SingleThreadedCondition28 SingleThreadedCondition
28else if (std.Target.current.os.tag == .windows)29else if (builtin.os.tag == .windows)
29 WindowsCondition30 WindowsCondition
30else if (std.Thread.use_pthreads)31else if (std.Thread.use_pthreads)
31 PthreadCondition32 PthreadCondition
...@@ -101,7 +102,7 @@ pub const AtomicCondition = struct {...@@ -101,7 +102,7 @@ pub const AtomicCondition = struct {
101102
102 fn wait(cond: *@This()) void {103 fn wait(cond: *@This()) void {
103 while (@atomicLoad(i32, &cond.futex, .Acquire) == 0) {104 while (@atomicLoad(i32, &cond.futex, .Acquire) == 0) {
104 switch (std.Target.current.os.tag) {105 switch (builtin.os.tag) {
105 .linux => {106 .linux => {
106 switch (linux.getErrno(linux.futex_wait(107 switch (linux.getErrno(linux.futex_wait(
107 &cond.futex,108 &cond.futex,
...@@ -123,7 +124,7 @@ pub const AtomicCondition = struct {...@@ -123,7 +124,7 @@ pub const AtomicCondition = struct {
123 fn notify(cond: *@This()) void {124 fn notify(cond: *@This()) void {
124 @atomicStore(i32, &cond.futex, 1, .Release);125 @atomicStore(i32, &cond.futex, 1, .Release);
125126
126 switch (std.Target.current.os.tag) {127 switch (builtin.os.tag) {
127 .linux => {128 .linux => {
128 switch (linux.getErrno(linux.futex_wake(129 switch (linux.getErrno(linux.futex_wake(
129 &cond.futex,130 &cond.futex,
lib/std/Thread/Futex.zig+4-3
...@@ -4,10 +4,11 @@...@@ -4,10 +4,11 @@
4//! Using Futex, other Thread synchronization primitives can be built which efficiently wait for cross-thread events or signals. 4//! Using Futex, other Thread synchronization primitives can be built which efficiently wait for cross-thread events or signals.
55
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");
7const Futex = @This();8const Futex = @This();
89
9const target = std.Target.current;10const target = builtin.target;
10const single_threaded = std.builtin.single_threaded;11const single_threaded = builtin.single_threaded;
1112
12const assert = std.debug.assert;13const assert = std.debug.assert;
13const testing = std.testing;14const testing = std.testing;
...@@ -70,7 +71,7 @@ else if (target.os.tag == .linux)...@@ -70,7 +71,7 @@ else if (target.os.tag == .linux)
70 LinuxFutex71 LinuxFutex
71else if (target.isDarwin())72else if (target.isDarwin())
72 DarwinFutex73 DarwinFutex
73else if (std.builtin.link_libc)74else if (builtin.link_libc)
74 PosixFutex75 PosixFutex
75else76else
76 UnsupportedFutex;77 UnsupportedFutex;
lib/std/Thread/Mutex.zig+3-3
...@@ -24,7 +24,7 @@ impl: Impl = .{},...@@ -24,7 +24,7 @@ impl: Impl = .{},
2424
25const Mutex = @This();25const Mutex = @This();
26const std = @import("../std.zig");26const std = @import("../std.zig");
27const builtin = std.builtin;27const builtin = @import("builtin");
28const os = std.os;28const os = std.os;
29const assert = std.debug.assert;29const assert = std.debug.assert;
30const windows = os.windows;30const windows = os.windows;
...@@ -160,7 +160,7 @@ pub const AtomicMutex = struct {...@@ -160,7 +160,7 @@ pub const AtomicMutex = struct {
160 .unlocked => return,160 .unlocked => return,
161 else => {},161 else => {},
162 }162 }
163 switch (std.Target.current.os.tag) {163 switch (builtin.os.tag) {
164 .linux => {164 .linux => {
165 switch (linux.getErrno(linux.futex_wait(165 switch (linux.getErrno(linux.futex_wait(
166 @ptrCast(*const i32, &m.state),166 @ptrCast(*const i32, &m.state),
...@@ -182,7 +182,7 @@ pub const AtomicMutex = struct {...@@ -182,7 +182,7 @@ pub const AtomicMutex = struct {
182 fn unlockSlow(m: *AtomicMutex) void {182 fn unlockSlow(m: *AtomicMutex) void {
183 @setCold(true);183 @setCold(true);
184184
185 switch (std.Target.current.os.tag) {185 switch (builtin.os.tag) {
186 .linux => {186 .linux => {
187 switch (linux.getErrno(linux.futex_wake(187 switch (linux.getErrno(linux.futex_wake(
188 @ptrCast(*const i32, &m.state),188 @ptrCast(*const i32, &m.state),
lib/std/Thread/ResetEvent.zig+2-2
...@@ -8,7 +8,7 @@...@@ -8,7 +8,7 @@
88
9const ResetEvent = @This();9const ResetEvent = @This();
10const std = @import("../std.zig");10const std = @import("../std.zig");
11const builtin = std.builtin;11const builtin = @import("builtin");
12const testing = std.testing;12const testing = std.testing;
13const assert = std.debug.assert;13const assert = std.debug.assert;
14const c = std.c;14const c = std.c;
...@@ -19,7 +19,7 @@ impl: Impl,...@@ -19,7 +19,7 @@ impl: Impl,
1919
20pub const Impl = if (builtin.single_threaded)20pub const Impl = if (builtin.single_threaded)
21 std.Thread.StaticResetEvent.DebugEvent21 std.Thread.StaticResetEvent.DebugEvent
22else if (std.Target.current.isDarwin())22else if (builtin.target.isDarwin())
23 DarwinEvent23 DarwinEvent
24else if (std.Thread.use_pthreads)24else if (std.Thread.use_pthreads)
25 PosixEvent25 PosixEvent
lib/std/Thread/StaticResetEvent.zig+4-3
...@@ -8,6 +8,7 @@...@@ -8,6 +8,7 @@
8//! the logic needs stronger API guarantees.8//! the logic needs stronger API guarantees.
99
10const std = @import("../std.zig");10const std = @import("../std.zig");
11const builtin = @import("builtin");
11const StaticResetEvent = @This();12const StaticResetEvent = @This();
12const assert = std.debug.assert;13const assert = std.debug.assert;
13const os = std.os;14const os = std.os;
...@@ -18,7 +19,7 @@ const testing = std.testing;...@@ -18,7 +19,7 @@ const testing = std.testing;
1819
19impl: Impl = .{},20impl: Impl = .{},
2021
21pub const Impl = if (std.builtin.single_threaded)22pub const Impl = if (builtin.single_threaded)
22 DebugEvent23 DebugEvent
23else24else
24 AtomicEvent;25 AtomicEvent;
...@@ -162,7 +163,7 @@ pub const AtomicEvent = struct {...@@ -162,7 +163,7 @@ pub const AtomicEvent = struct {
162 @atomicStore(u32, &ev.waiters, 0, .Monotonic);163 @atomicStore(u32, &ev.waiters, 0, .Monotonic);
163 }164 }
164165
165 pub const Futex = switch (std.Target.current.os.tag) {166 pub const Futex = switch (builtin.os.tag) {
166 .windows => WindowsFutex,167 .windows => WindowsFutex,
167 .linux => LinuxFutex,168 .linux => LinuxFutex,
168 else => SpinFutex,169 else => SpinFutex,
...@@ -322,7 +323,7 @@ test "basic usage" {...@@ -322,7 +323,7 @@ test "basic usage" {
322 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));323 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
323324
324 // test cross-thread signaling325 // test cross-thread signaling
325 if (std.builtin.single_threaded)326 if (builtin.single_threaded)
326 return;327 return;
327328
328 const Context = struct {329 const Context = struct {
lib/std/array_hash_map.zig-1
...@@ -9,7 +9,6 @@ const trait = meta.trait;...@@ -9,7 +9,6 @@ const trait = meta.trait;
9const autoHash = std.hash.autoHash;9const autoHash = std.hash.autoHash;
10const Wyhash = std.hash.Wyhash;10const Wyhash = std.hash.Wyhash;
11const Allocator = mem.Allocator;11const Allocator = mem.Allocator;
12const builtin = std.builtin;
13const hash_map = @This();12const hash_map = @This();
1413
15/// An ArrayHashMap with default hash and equal functions.14/// An ArrayHashMap with default hash and equal functions.
lib/std/atomic.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const target = std.Target.current;2const target = @import("builtin").target;
33
4pub const Ordering = std.builtin.AtomicOrder;4pub const Ordering = std.builtin.AtomicOrder;
55
lib/std/atomic/Atomic.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
22
3const testing = std.testing;3const testing = std.testing;
4const target = std.Target.current;4const target = @import("builtin").target;
5const Ordering = std.atomic.Ordering;5const Ordering = std.atomic.Ordering;
66
7pub fn Atomic(comptime T: type) type {7pub fn Atomic(comptime T: type) type {
lib/std/atomic/queue.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const expect = std.testing.expect;4const expect = std.testing.expect;
55
lib/std/atomic/stack.zig+2-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
1const assert = std.debug.assert;3const assert = std.debug.assert;
2const builtin = std.builtin;
3const expect = std.testing.expect;4const expect = std.testing.expect;
45
5/// Many reader, many writer, non-allocating, thread-safe6/// Many reader, many writer, non-allocating, thread-safe
...@@ -67,7 +68,6 @@ pub fn Stack(comptime T: type) type {...@@ -67,7 +68,6 @@ pub fn Stack(comptime T: type) type {
67 };68 };
68}69}
6970
70const std = @import("../std.zig");
71const Context = struct {71const Context = struct {
72 allocator: *std.mem.Allocator,72 allocator: *std.mem.Allocator,
73 stack: *Stack(i32),73 stack: *Stack(i32),
lib/std/build.zig+21-21
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const io = std.io;3const io = std.io;
4const fs = std.fs;4const fs = std.fs;
5const mem = std.mem;5const mem = std.mem;
...@@ -62,7 +62,7 @@ pub const Builder = struct {...@@ -62,7 +62,7 @@ pub const Builder = struct {
62 build_root: []const u8,62 build_root: []const u8,
63 cache_root: []const u8,63 cache_root: []const u8,
64 global_cache_root: []const u8,64 global_cache_root: []const u8,
65 release_mode: ?builtin.Mode,65 release_mode: ?std.builtin.Mode,
66 is_release: bool,66 is_release: bool,
67 override_lib_dir: ?[]const u8,67 override_lib_dir: ?[]const u8,
68 vcpkg_root: VcpkgRoot,68 vcpkg_root: VcpkgRoot,
...@@ -633,18 +633,18 @@ pub const Builder = struct {...@@ -633,18 +633,18 @@ pub const Builder = struct {
633 }633 }
634634
635 /// This provides the -Drelease option to the build user and does not give them the choice.635 /// This provides the -Drelease option to the build user and does not give them the choice.
636 pub fn setPreferredReleaseMode(self: *Builder, mode: builtin.Mode) void {636 pub fn setPreferredReleaseMode(self: *Builder, mode: std.builtin.Mode) void {
637 if (self.release_mode != null) {637 if (self.release_mode != null) {
638 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");638 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
639 }639 }
640 const description = self.fmt("Create a release build ({s})", .{@tagName(mode)});640 const description = self.fmt("Create a release build ({s})", .{@tagName(mode)});
641 self.is_release = self.option(bool, "release", description) orelse false;641 self.is_release = self.option(bool, "release", description) orelse false;
642 self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;642 self.release_mode = if (self.is_release) mode else std.builtin.Mode.Debug;
643 }643 }
644644
645 /// If you call this without first calling `setPreferredReleaseMode` then it gives the build user645 /// If you call this without first calling `setPreferredReleaseMode` then it gives the build user
646 /// the choice of what kind of release.646 /// the choice of what kind of release.
647 pub fn standardReleaseOptions(self: *Builder) builtin.Mode {647 pub fn standardReleaseOptions(self: *Builder) std.builtin.Mode {
648 if (self.release_mode) |mode| return mode;648 if (self.release_mode) |mode| return mode;
649649
650 const release_safe = self.option(bool, "release-safe", "Optimizations on and safety on") orelse false;650 const release_safe = self.option(bool, "release-safe", "Optimizations on and safety on") orelse false;
...@@ -652,17 +652,17 @@ pub const Builder = struct {...@@ -652,17 +652,17 @@ pub const Builder = struct {
652 const release_small = self.option(bool, "release-small", "Size optimizations on and safety off") orelse false;652 const release_small = self.option(bool, "release-small", "Size optimizations on and safety off") orelse false;
653653
654 const mode = if (release_safe and !release_fast and !release_small)654 const mode = if (release_safe and !release_fast and !release_small)
655 builtin.Mode.ReleaseSafe655 std.builtin.Mode.ReleaseSafe
656 else if (release_fast and !release_safe and !release_small)656 else if (release_fast and !release_safe and !release_small)
657 builtin.Mode.ReleaseFast657 std.builtin.Mode.ReleaseFast
658 else if (release_small and !release_fast and !release_safe)658 else if (release_small and !release_fast and !release_safe)
659 builtin.Mode.ReleaseSmall659 std.builtin.Mode.ReleaseSmall
660 else if (!release_fast and !release_safe and !release_small)660 else if (!release_fast and !release_safe and !release_small)
661 builtin.Mode.Debug661 std.builtin.Mode.Debug
662 else x: {662 else x: {
663 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)\n\n", .{});663 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)\n\n", .{});
664 self.markInvalidUserInput();664 self.markInvalidUserInput();
665 break :x builtin.Mode.Debug;665 break :x std.builtin.Mode.Debug;
666 };666 };
667 self.is_release = mode != .Debug;667 self.is_release = mode != .Debug;
668 self.release_mode = mode;668 self.release_mode = mode;
...@@ -1290,7 +1290,7 @@ test "builder.findProgram compiles" {...@@ -1290,7 +1290,7 @@ test "builder.findProgram compiles" {
1290}1290}
12911291
1292/// Deprecated. Use `std.builtin.Version`.1292/// Deprecated. Use `std.builtin.Version`.
1293pub const Version = builtin.Version;1293pub const Version = std.builtin.Version;
12941294
1295/// Deprecated. Use `std.zig.CrossTarget`.1295/// Deprecated. Use `std.zig.CrossTarget`.
1296pub const Target = std.zig.CrossTarget;1296pub const Target = std.zig.CrossTarget;
...@@ -1417,8 +1417,8 @@ pub const LibExeObjStep = struct {...@@ -1417,8 +1417,8 @@ pub const LibExeObjStep = struct {
1417 version_script: ?[]const u8 = null,1417 version_script: ?[]const u8 = null,
1418 out_filename: []const u8,1418 out_filename: []const u8,
1419 linkage: ?Linkage = null,1419 linkage: ?Linkage = null,
1420 version: ?Version,1420 version: ?std.builtin.Version,
1421 build_mode: builtin.Mode,1421 build_mode: std.builtin.Mode,
1422 kind: Kind,1422 kind: Kind,
1423 major_only_filename: ?[]const u8,1423 major_only_filename: ?[]const u8,
1424 name_only_filename: ?[]const u8,1424 name_only_filename: ?[]const u8,
...@@ -1447,8 +1447,8 @@ pub const LibExeObjStep = struct {...@@ -1447,8 +1447,8 @@ pub const LibExeObjStep = struct {
1447 filter: ?[]const u8,1447 filter: ?[]const u8,
1448 single_threaded: bool,1448 single_threaded: bool,
1449 test_evented_io: bool = false,1449 test_evented_io: bool = false,
1450 code_model: builtin.CodeModel = .default,1450 code_model: std.builtin.CodeModel = .default,
1451 wasi_exec_model: ?builtin.WasiExecModel = null,1451 wasi_exec_model: ?std.builtin.WasiExecModel = null,
14521452
1453 root_src: ?FileSource,1453 root_src: ?FileSource,
1454 out_h_filename: []const u8,1454 out_h_filename: []const u8,
...@@ -1550,7 +1550,7 @@ pub const LibExeObjStep = struct {...@@ -1550,7 +1550,7 @@ pub const LibExeObjStep = struct {
1550 };1550 };
15511551
1552 const SharedLibKind = union(enum) {1552 const SharedLibKind = union(enum) {
1553 versioned: Version,1553 versioned: std.builtin.Version,
1554 unversioned: void,1554 unversioned: void,
1555 };1555 };
15561556
...@@ -1585,7 +1585,7 @@ pub const LibExeObjStep = struct {...@@ -1585,7 +1585,7 @@ pub const LibExeObjStep = struct {
1585 root_src_raw: ?FileSource,1585 root_src_raw: ?FileSource,
1586 kind: Kind,1586 kind: Kind,
1587 linkage: ?Linkage,1587 linkage: ?Linkage,
1588 ver: ?Version,1588 ver: ?std.builtin.Version,
1589 ) *LibExeObjStep {1589 ) *LibExeObjStep {
1590 const name = builder.dupe(name_raw);1590 const name = builder.dupe(name_raw);
1591 const root_src: ?FileSource = if (root_src_raw) |rsrc| rsrc.dupe(builder) else null;1591 const root_src: ?FileSource = if (root_src_raw) |rsrc| rsrc.dupe(builder) else null;
...@@ -1599,7 +1599,7 @@ pub const LibExeObjStep = struct {...@@ -1599,7 +1599,7 @@ pub const LibExeObjStep = struct {
1599 .builder = builder,1599 .builder = builder,
1600 .verbose_link = false,1600 .verbose_link = false,
1601 .verbose_cc = false,1601 .verbose_cc = false,
1602 .build_mode = builtin.Mode.Debug,1602 .build_mode = std.builtin.Mode.Debug,
1603 .linkage = linkage,1603 .linkage = linkage,
1604 .kind = kind,1604 .kind = kind,
1605 .root_src = root_src,1605 .root_src = root_src,
...@@ -1988,7 +1988,7 @@ pub const LibExeObjStep = struct {...@@ -1988,7 +1988,7 @@ pub const LibExeObjStep = struct {
1988 self.verbose_cc = value;1988 self.verbose_cc = value;
1989 }1989 }
19901990
1991 pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void {1991 pub fn setBuildMode(self: *LibExeObjStep, mode: std.builtin.Mode) void {
1992 self.build_mode = mode;1992 self.build_mode = mode;
1993 }1993 }
19941994
...@@ -2553,7 +2553,7 @@ pub const LibExeObjStep = struct {...@@ -2553,7 +2553,7 @@ pub const LibExeObjStep = struct {
25532553
2554 const resolved_include_path = self.builder.pathFromRoot(include_path);2554 const resolved_include_path = self.builder.pathFromRoot(include_path);
25552555
2556 const common_include_path = if (std.Target.current.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {2556 const common_include_path = if (builtin.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {
2557 // We need to check for disk designator and strip it out from dir path so2557 // We need to check for disk designator and strip it out from dir path so
2558 // that zig/clang can concat resolved_include_path with sysroot.2558 // that zig/clang can concat resolved_include_path with sysroot.
2559 const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path);2559 const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path);
...@@ -3237,7 +3237,7 @@ test "LibExeObjStep.addPackage" {...@@ -3237,7 +3237,7 @@ test "LibExeObjStep.addPackage" {
3237test {3237test {
3238 // The only purpose of this test is to get all these untested functions3238 // The only purpose of this test is to get all these untested functions
3239 // to be referenced to avoid regression so it is okay to skip some targets.3239 // to be referenced to avoid regression so it is okay to skip some targets.
3240 if (comptime std.Target.current.cpu.arch.ptrBitWidth() == 64) {3240 if (comptime builtin.cpu.arch.ptrBitWidth() == 64) {
3241 std.testing.refAllDecls(@This());3241 std.testing.refAllDecls(@This());
3242 std.testing.refAllDecls(Builder);3242 std.testing.refAllDecls(Builder);
32433243
lib/std/build/OptionsStep.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const build = std.build;3const build = std.build;
3const fs = std.fs;4const fs = std.fs;
4const Step = build.Step;5const Step = build.Step;
...@@ -219,7 +220,7 @@ const OptionFileSourceArg = struct {...@@ -219,7 +220,7 @@ const OptionFileSourceArg = struct {
219};220};
220221
221test "OptionsStep" {222test "OptionsStep" {
222 if (std.builtin.os.tag == .wasi) return error.SkipZigTest;223 if (builtin.os.tag == .wasi) return error.SkipZigTest;
223224
224 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);225 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
225 defer arena.deinit();226 defer arena.deinit();
lib/std/build/RunStep.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const build = std.build;3const build = std.build;
4const Step = build.Step;4const Step = build.Step;
5const Builder = build.Builder;5const Builder = build.Builder;
lib/std/builtin.zig+23-22
...@@ -1,26 +1,27 @@...@@ -1,26 +1,27 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
22
3// These are all deprecated.3// TODO delete these after releasing 0.9.0
4pub const zig_version = builtin.zig_version;4
5pub const zig_is_stage2 = builtin.zig_is_stage2;5pub const zig_version = @compileError("get this from @import(\"builtin\") instead of std.builtin");
6pub const output_mode = builtin.output_mode;6pub const zig_is_stage2 = @compileError("get this from @import(\"builtin\") instead of std.builtin");
7pub const link_mode = builtin.link_mode;7pub const output_mode = @compileError("get this from @import(\"builtin\") instead of std.builtin");
8pub const is_test = builtin.is_test;8pub const link_mode = @compileError("get this from @import(\"builtin\") instead of std.builtin");
9pub const single_threaded = builtin.single_threaded;9pub const is_test = @compileError("get this from @import(\"builtin\") instead of std.builtin");
10pub const abi = builtin.abi;10pub const single_threaded = @compileError("get this from @import(\"builtin\") instead of std.builtin");
11pub const cpu = builtin.cpu;11pub const abi = @compileError("get this from @import(\"builtin\") instead of std.builtin");
12pub const os = builtin.os;12pub const cpu = @compileError("get this from @import(\"builtin\") instead of std.builtin");
13pub const target = builtin.target;13pub const os = @compileError("get this from @import(\"builtin\") instead of std.builtin");
14pub const object_format = builtin.object_format;14pub const target = @compileError("get this from @import(\"builtin\") instead of std.builtin");
15pub const mode = builtin.mode;15pub const object_format = @compileError("get this from @import(\"builtin\") instead of std.builtin");
16pub const link_libc = builtin.link_libc;16pub const mode = @compileError("get this from @import(\"builtin\") instead of std.builtin");
17pub const link_libcpp = builtin.link_libcpp;17pub const link_libc = @compileError("get this from @import(\"builtin\") instead of std.builtin");
18pub const have_error_return_tracing = builtin.have_error_return_tracing;18pub const link_libcpp = @compileError("get this from @import(\"builtin\") instead of std.builtin");
19pub const valgrind_support = builtin.valgrind_support;19pub const have_error_return_tracing = @compileError("get this from @import(\"builtin\") instead of std.builtin");
20pub const position_independent_code = builtin.position_independent_code;20pub const valgrind_support = @compileError("get this from @import(\"builtin\") instead of std.builtin");
21pub const position_independent_executable = builtin.position_independent_executable;21pub const position_independent_code = @compileError("get this from @import(\"builtin\") instead of std.builtin");
22pub const strip_debug_info = builtin.strip_debug_info;22pub const position_independent_executable = @compileError("get this from @import(\"builtin\") instead of std.builtin");
23pub const code_model = builtin.code_model;23pub const strip_debug_info = @compileError("get this from @import(\"builtin\") instead of std.builtin");
24pub const code_model = @compileError("get this from @import(\"builtin\") instead of std.builtin");
2425
25/// `explicit_subsystem` is missing when the subsystem is automatically detected,26/// `explicit_subsystem` is missing when the subsystem is automatically detected,
26/// so Zig standard library has the subsystem detection logic here. This should generally be27/// 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...@@ -694,7 +695,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
694 @breakpoint();695 @breakpoint();
695 }696 }
696 }697 }
697 switch (os.tag) {698 switch (builtin.os.tag) {
698 .freestanding => {699 .freestanding => {
699 while (true) {700 while (true) {
700 @breakpoint();701 @breakpoint();
lib/std/c.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const c = @This();3const c = @This();
4const page_size = std.mem.page_size;4const page_size = std.mem.page_size;
5const iovec = std.os.iovec;5const iovec = std.os.iovec;
...@@ -20,7 +20,7 @@ pub const Tokenizer = tokenizer.Tokenizer;...@@ -20,7 +20,7 @@ pub const Tokenizer = tokenizer.Tokenizer;
20/// If linking gnu libc (glibc), the `ok` value will be true if the target20/// If linking gnu libc (glibc), the `ok` value will be true if the target
21/// version is greater than or equal to `glibc_version`.21/// version is greater than or equal to `glibc_version`.
22/// If linking a libc other than these, returns `false`.22/// If linking a libc other than these, returns `false`.
23pub fn versionCheck(glibc_version: builtin.Version) type {23pub fn versionCheck(glibc_version: std.builtin.Version) type {
24 return struct {24 return struct {
25 pub const ok = blk: {25 pub const ok = blk: {
26 if (!builtin.link_libc) break :blk false;26 if (!builtin.link_libc) break :blk false;
lib/std/c/darwin.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const assert = std.debug.assert;
3const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;
4const macho = std.macho;4const macho = std.macho;
5const native_arch = builtin.target.cpu.arch;5const native_arch = builtin.target.cpu.arch;
6const maxInt = std.math.maxInt;6const maxInt = std.math.maxInt;
...@@ -72,7 +72,7 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;...@@ -72,7 +72,7 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
72var dummy_execute_header: mach_hdr = undefined;72var dummy_execute_header: mach_hdr = undefined;
73pub extern var _mh_execute_header: mach_hdr;73pub extern var _mh_execute_header: mach_hdr;
74comptime {74comptime {
75 if (std.Target.current.isDarwin()) {75 if (builtin.target.isDarwin()) {
76 @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .Weak });76 @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .Weak });
77 }77 }
78}78}
lib/std/child_process.zig+4-4
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
2const cstr = std.cstr;3const cstr = std.cstr;
3const unicode = std.unicode;4const unicode = std.unicode;
4const io = std.io;5const io = std.io;
...@@ -12,8 +13,7 @@ const mem = std.mem;...@@ -12,8 +13,7 @@ const mem = std.mem;
12const math = std.math;13const math = std.math;
13const debug = std.debug;14const debug = std.debug;
14const BufMap = std.BufMap;15const BufMap = std.BufMap;
15const builtin = std.builtin;16const Os = std.builtin.Os;
16const Os = builtin.Os;
17const TailQueue = std.TailQueue;17const TailQueue = std.TailQueue;
18const maxInt = std.math.maxInt;18const maxInt = std.math.maxInt;
19const assert = std.debug.assert;19const assert = std.debug.assert;
...@@ -561,9 +561,9 @@ pub const ChildProcess = struct {...@@ -561,9 +561,9 @@ pub const ChildProcess = struct {
561 if (self.env_map) |env_map| {561 if (self.env_map) |env_map| {
562 const envp_buf = try createNullDelimitedEnvMap(arena, env_map);562 const envp_buf = try createNullDelimitedEnvMap(arena, env_map);
563 break :m envp_buf.ptr;563 break :m envp_buf.ptr;
564 } else if (std.builtin.link_libc) {564 } else if (builtin.link_libc) {
565 break :m std.c.environ;565 break :m std.c.environ;
566 } else if (std.builtin.output_mode == .Exe) {566 } else if (builtin.output_mode == .Exe) {
567 // Then we have Zig start code and this works.567 // Then we have Zig start code and this works.
568 // TODO type-safety for null-termination of `os.environ`.568 // TODO type-safety for null-termination of `os.environ`.
569 break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr);569 break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr);
lib/std/coff.zig-1
...@@ -1,4 +1,3 @@...@@ -1,4 +1,3 @@
1const builtin = std.builtin;
2const std = @import("std.zig");1const std = @import("std.zig");
3const io = std.io;2const io = std.io;
4const mem = std.mem;3const mem = std.mem;
lib/std/crypto.zig+1-1
...@@ -163,7 +163,7 @@ const std = @import("std.zig");...@@ -163,7 +163,7 @@ const std = @import("std.zig");
163pub const errors = @import("crypto/errors.zig");163pub const errors = @import("crypto/errors.zig");
164164
165test "crypto" {165test "crypto" {
166 const please_windows_dont_oom = std.Target.current.os.tag == .windows;166 const please_windows_dont_oom = @import("builtin").os.tag == .windows;
167 if (please_windows_dont_oom) return error.SkipZigTest;167 if (please_windows_dont_oom) return error.SkipZigTest;
168168
169 inline for (std.meta.declarations(@This())) |decl| {169 inline for (std.meta.declarations(@This())) |decl| {
lib/std/crypto/aes.zig+7-7
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const testing = std.testing;3const testing = std.testing;
3const builtin = std.builtin;
44
5const has_aesni = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes);5const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes);
6const has_avx = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx);6const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx);
7const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes);7const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes);
8const impl = if (std.Target.current.cpu.arch == .x86_64 and has_aesni and has_avx) impl: {8const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: {
9 break :impl @import("aes/aesni.zig");9 break :impl @import("aes/aesni.zig");
10} else if (std.Target.current.cpu.arch == .aarch64 and has_armaes)10} else if (builtin.cpu.arch == .aarch64 and has_armaes)
11impl: {11impl: {
12 break :impl @import("aes/armcrypto.zig");12 break :impl @import("aes/armcrypto.zig");
13} else impl: {13} else impl: {
...@@ -41,7 +41,7 @@ test "ctr" {...@@ -41,7 +41,7 @@ test "ctr" {
4141
42 var out: [exp_out.len]u8 = undefined;42 var out: [exp_out.len]u8 = undefined;
43 var ctx = Aes128.initEnc(key);43 var ctx = Aes128.initEnc(key);
44 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);44 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.Big);
45 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);45 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
46}46}
4747
lib/std/crypto/aes/aesni.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
2const mem = std.mem;3const mem = std.mem;
3const debug = std.debug;4const debug = std.debug;
4const Vector = std.meta.Vector;5const Vector = std.meta.Vector;
...@@ -97,7 +98,7 @@ pub const Block = struct {...@@ -97,7 +98,7 @@ pub const Block = struct {
97 const cpu = std.Target.x86.cpu;98 const cpu = std.Target.x86.cpu;
9899
99 /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation.100 /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation.
100 pub const optimal_parallel_blocks = switch (std.Target.current.cpu.model) {101 pub const optimal_parallel_blocks = switch (builtin.cpu.model) {
101 &cpu.westmere => 6,102 &cpu.westmere => 6,
102 &cpu.sandybridge, &cpu.ivybridge => 8,103 &cpu.sandybridge, &cpu.ivybridge => 8,
103 &cpu.haswell, &cpu.broadwell => 7,104 &cpu.haswell, &cpu.broadwell => 7,
lib/std/crypto/aes_gcm.zig+2-3
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const builtin = std.builtin;
4const crypto = std.crypto;3const crypto = std.crypto;
5const debug = std.debug;4const debug = std.debug;
6const Ghash = std.crypto.onetimeauth.Ghash;5const Ghash = std.crypto.onetimeauth.Ghash;
...@@ -40,7 +39,7 @@ fn AesGcm(comptime Aes: anytype) type {...@@ -40,7 +39,7 @@ fn AesGcm(comptime Aes: anytype) type {
40 mac.pad();39 mac.pad();
4140
42 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);41 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);
43 modes.ctr(@TypeOf(aes), aes, c, m, j, builtin.Endian.Big);42 modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.Big);
44 mac.update(c[0..m.len][0..]);43 mac.update(c[0..m.len][0..]);
45 mac.pad();44 mac.pad();
4645
...@@ -94,7 +93,7 @@ fn AesGcm(comptime Aes: anytype) type {...@@ -94,7 +93,7 @@ fn AesGcm(comptime Aes: anytype) type {
94 }93 }
9594
96 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);95 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);
97 modes.ctr(@TypeOf(aes), aes, m, c, j, builtin.Endian.Big);96 modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big);
98 }97 }
99 };98 };
100}99}
lib/std/crypto/aes_ocb.zig+4-3
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const crypto = std.crypto;3const crypto = std.crypto;
3const aes = crypto.core.aes;4const aes = crypto.core.aes;
4const assert = std.debug.assert;5const assert = std.debug.assert;
...@@ -100,9 +101,9 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -100,9 +101,9 @@ fn AesOcb(comptime Aes: anytype) type {
100 return offset;101 return offset;
101 }102 }
102103
103 const has_aesni = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes);104 const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes);
104 const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes);105 const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes);
105 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;106 const wb: usize = if ((builtin.cpu.arch == .x86_64 and has_aesni) or (builtin.cpu.arch == .aarch64 and has_armaes)) 4 else 0;
106107
107 /// c: ciphertext: output buffer should be of size m.len108 /// c: ciphertext: output buffer should be of size m.len
108 /// tag: authentication tag: output MAC109 /// tag: authentication tag: output MAC
lib/std/crypto/benchmark.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig
22
3const std = @import("../std.zig");3const std = @import("../std.zig");
4const builtin = std.builtin;4const builtin = @import("builtin");
5const mem = std.mem;5const mem = std.mem;
6const time = std.time;6const time = std.time;
7const Timer = time.Timer;7const Timer = time.Timer;
lib/std/crypto/blake3.zig+2-1
...@@ -2,6 +2,7 @@...@@ -2,6 +2,7 @@
2// Source: https://github.com/BLAKE3-team/BLAKE32// Source: https://github.com/BLAKE3-team/BLAKE3
33
4const std = @import("../std.zig");4const std = @import("../std.zig");
5const builtin = @import("builtin");
5const fmt = std.fmt;6const fmt = std.fmt;
6const math = std.math;7const math = std.math;
7const mem = std.mem;8const mem = std.mem;
...@@ -200,7 +201,7 @@ const CompressGeneric = struct {...@@ -200,7 +201,7 @@ const CompressGeneric = struct {
200 }201 }
201};202};
202203
203const compress = if (std.Target.current.cpu.arch == .x86_64) CompressVectorized.compress else CompressGeneric.compress;204const compress = if (builtin.cpu.arch == .x86_64) CompressVectorized.compress else CompressGeneric.compress;
204205
205fn first8Words(words: [16]u32) [8]u32 {206fn first8Words(words: [16]u32) [8]u32 {
206 return @ptrCast(*const [8]u32, &words).*;207 return @ptrCast(*const [8]u32, &words).*;
lib/std/crypto/chacha20.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1// Based on public domain Supercop by Daniel J. Bernstein1// Based on public domain Supercop by Daniel J. Bernstein
22
3const std = @import("../std.zig");3const std = @import("../std.zig");
4const builtin = @import("builtin");
4const math = std.math;5const math = std.math;
5const mem = std.mem;6const mem = std.mem;
6const assert = std.debug.assert;7const assert = std.debug.assert;
...@@ -359,7 +360,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -359,7 +360,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
359}360}
360361
361fn ChaChaImpl(comptime rounds_nb: usize) type {362fn ChaChaImpl(comptime rounds_nb: usize) type {
362 return if (std.Target.current.cpu.arch == .x86_64) ChaChaVecImpl(rounds_nb) else ChaChaNonVecImpl(rounds_nb);363 return if (builtin.cpu.arch == .x86_64) ChaChaVecImpl(rounds_nb) else ChaChaNonVecImpl(rounds_nb);
363}364}
364365
365fn keyToWords(key: [32]u8) [8]u32 {366fn keyToWords(key: [32]u8) [8]u32 {
lib/std/crypto/ghash.zig+8-7
...@@ -2,6 +2,7 @@...@@ -2,6 +2,7 @@
2// Adapted from BearSSL's ctmul64 implementation originally written by Thomas Pornin <pornin@bolet.org>2// Adapted from BearSSL's ctmul64 implementation originally written by Thomas Pornin <pornin@bolet.org>
33
4const std = @import("../std.zig");4const std = @import("../std.zig");
5const builtin = @import("builtin");
5const assert = std.debug.assert;6const assert = std.debug.assert;
6const math = std.math;7const math = std.math;
7const mem = std.mem;8const mem = std.mem;
...@@ -45,7 +46,7 @@ pub const Ghash = struct {...@@ -45,7 +46,7 @@ pub const Ghash = struct {
45 const h2 = h0 ^ h1;46 const h2 = h0 ^ h1;
46 const h2r = h0r ^ h1r;47 const h2r = h0r ^ h1r;
4748
48 if (std.builtin.mode == .ReleaseSmall) {49 if (builtin.mode == .ReleaseSmall) {
49 return Ghash{50 return Ghash{
50 .h0 = h0,51 .h0 = h0,
51 .h1 = h1,52 .h1 = h1,
...@@ -132,12 +133,12 @@ pub const Ghash = struct {...@@ -132,12 +133,12 @@ pub const Ghash = struct {
132 return z0 | z1 | z2 | z3;133 return z0 | z1 | z2 | z3;
133 }134 }
134135
135 const has_pclmul = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .pclmul);136 const has_pclmul = std.Target.x86.featureSetHas(builtin.cpu.features, .pclmul);
136 const has_avx = std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx);137 const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx);
137 const has_armaes = std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes);138 const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes);
138 const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: {139 const clmul = if (builtin.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: {
139 break :impl clmul_pclmul;140 break :impl clmul_pclmul;
140 } else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) impl: {141 } else if (builtin.cpu.arch == .aarch64 and has_armaes) impl: {
141 break :impl clmul_pmull;142 break :impl clmul_pmull;
142 } else impl: {143 } else impl: {
143 break :impl clmul_soft;144 break :impl clmul_soft;
...@@ -151,7 +152,7 @@ pub const Ghash = struct {...@@ -151,7 +152,7 @@ pub const Ghash = struct {
151 var i: usize = 0;152 var i: usize = 0;
152153
153 // 2-blocks aggregated reduction154 // 2-blocks aggregated reduction
154 if (std.builtin.mode != .ReleaseSmall) {155 if (builtin.mode != .ReleaseSmall) {
155 while (i + 32 <= msg.len) : (i += 32) {156 while (i + 32 <= msg.len) : (i += 32) {
156 // B0 * H^2 unreduced157 // B0 * H^2 unreduced
157 y1 ^= mem.readIntBig(u64, msg[i..][0..8]);158 y1 ^= mem.readIntBig(u64, msg[i..][0..8]);
lib/std/crypto/gimli.zig+11-10
...@@ -1,13 +1,14 @@...@@ -1,13 +1,14 @@
1// Gimli is a 384-bit permutation designed to achieve high security with high1//! Gimli is a 384-bit permutation designed to achieve high security with high
2// performance across a broad range of platforms, including 64-bit Intel/AMD2//! performance across a broad range of platforms, including 64-bit Intel/AMD
3// server CPUs, 64-bit and 32-bit ARM smartphone CPUs, 32-bit ARM3//! server CPUs, 64-bit and 32-bit ARM smartphone CPUs, 32-bit ARM
4// microcontrollers, 8-bit AVR microcontrollers, FPGAs, ASICs without4//! microcontrollers, 8-bit AVR microcontrollers, FPGAs, ASICs without
5// side-channel protection, and ASICs with side-channel protection.5//! side-channel protection, and ASICs with side-channel protection.
6//6//!
7// https://gimli.cr.yp.to/7//! https://gimli.cr.yp.to/
8// https://csrc.nist.gov/CSRC/media/Projects/Lightweight-Cryptography/documents/round-1/spec-doc/gimli-spec.pdf8//! https://csrc.nist.gov/CSRC/media/Projects/Lightweight-Cryptography/documents/round-1/spec-doc/gimli-spec.pdf
99
10const std = @import("../std.zig");10const std = @import("../std.zig");
11const builtin = @import("builtin");
11const mem = std.mem;12const mem = std.mem;
12const math = std.math;13const math = std.math;
13const debug = std.debug;14const debug = std.debug;
...@@ -152,9 +153,9 @@ pub const State = struct {...@@ -152,9 +153,9 @@ pub const State = struct {
152 self.endianSwap();153 self.endianSwap();
153 }154 }
154155
155 pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: {156 pub const permute = if (builtin.cpu.arch == .x86_64) impl: {
156 break :impl permute_vectorized;157 break :impl permute_vectorized;
157 } else if (std.builtin.mode == .ReleaseSmall) impl: {158 } else if (builtin.mode == .ReleaseSmall) impl: {
158 break :impl permute_small;159 break :impl permute_small;
159 } else impl: {160 } else impl: {
160 break :impl permute_unrolled;161 break :impl permute_unrolled;
lib/std/crypto/modes.zig+1-2
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1// Based on Go stdlib implementation1// Based on Go stdlib implementation
22
3const std = @import("../std.zig");3const std = @import("../std.zig");
4const builtin = std.builtin;
5const mem = std.mem;4const mem = std.mem;
6const debug = std.debug;5const debug = std.debug;
76
...@@ -11,7 +10,7 @@ const debug = std.debug;...@@ -11,7 +10,7 @@ const debug = std.debug;
11///10///
12/// Important: the counter mode doesn't provide authenticated encryption: the ciphertext can be trivially modified without this being detected.11/// Important: the counter mode doesn't provide authenticated encryption: the ciphertext can be trivially modified without this being detected.
13/// As a result, applications should generally never use it directly, but only in a construction that includes a MAC.12/// As a result, applications should generally never use it directly, but only in a construction that includes a MAC.
14pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8, src: []const u8, iv: [BlockCipher.block_length]u8, endian: builtin.Endian) void {13pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8, src: []const u8, iv: [BlockCipher.block_length]u8, endian: std.builtin.Endian) void {
15 debug.assert(dst.len >= src.len);14 debug.assert(dst.len >= src.len);
16 const block_length = BlockCipher.block_length;15 const block_length = BlockCipher.block_length;
17 var counter: [BlockCipher.block_length]u8 = undefined;16 var counter: [BlockCipher.block_length]u8 = undefined;
lib/std/crypto/pcurves/common.zig+3-4
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const crypto = std.crypto;2const crypto = std.crypto;
4const debug = std.debug;3const debug = std.debug;
5const mem = std.mem;4const mem = std.mem;
...@@ -51,7 +50,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -51,7 +50,7 @@ pub fn Field(comptime params: FieldParams) type {
51 };50 };
5251
53 /// Reject non-canonical encodings of an element.52 /// Reject non-canonical encodings of an element.
54 pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: builtin.Endian) NonCanonicalError!void {53 pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!void {
55 var s = if (endian == .Little) s_ else orderSwap(s_);54 var s = if (endian == .Little) s_ else orderSwap(s_);
56 const field_order_s = comptime fos: {55 const field_order_s = comptime fos: {
57 var fos: [encoded_length]u8 = undefined;56 var fos: [encoded_length]u8 = undefined;
...@@ -71,7 +70,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -71,7 +70,7 @@ pub fn Field(comptime params: FieldParams) type {
71 }70 }
7271
73 /// Unpack a field element.72 /// Unpack a field element.
74 pub fn fromBytes(s_: [encoded_length]u8, endian: builtin.Endian) NonCanonicalError!Fe {73 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {
75 var s = if (endian == .Little) s_ else orderSwap(s_);74 var s = if (endian == .Little) s_ else orderSwap(s_);
76 try rejectNonCanonical(s, .Little);75 try rejectNonCanonical(s, .Little);
77 var limbs_z: NonMontgomeryDomainFieldElement = undefined;76 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
...@@ -82,7 +81,7 @@ pub fn Field(comptime params: FieldParams) type {...@@ -82,7 +81,7 @@ pub fn Field(comptime params: FieldParams) type {
82 }81 }
8382
84 /// Pack a field element.83 /// Pack a field element.
85 pub fn toBytes(fe: Fe, endian: builtin.Endian) [encoded_length]u8 {84 pub fn toBytes(fe: Fe, endian: std.builtin.Endian) [encoded_length]u8 {
86 var limbs_z: NonMontgomeryDomainFieldElement = undefined;85 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
87 fiat.fromMontgomery(&limbs_z, fe.limbs);86 fiat.fromMontgomery(&limbs_z, fe.limbs);
88 var s: [encoded_length]u8 = undefined;87 var s: [encoded_length]u8 = undefined;
lib/std/crypto/pcurves/p256.zig+4-5
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const crypto = std.crypto;2const crypto = std.crypto;
4const mem = std.mem;3const mem = std.mem;
5const meta = std.meta;4const meta = std.meta;
...@@ -59,7 +58,7 @@ pub const P256 = struct {...@@ -59,7 +58,7 @@ pub const P256 = struct {
59 }58 }
6059
61 /// Create a point from serialized affine coordinates.60 /// Create a point from serialized affine coordinates.
62 pub fn fromSerializedAffineCoordinates(xs: [32]u8, ys: [32]u8, endian: builtin.Endian) (NonCanonicalError || EncodingError)!P256 {61 pub fn fromSerializedAffineCoordinates(xs: [32]u8, ys: [32]u8, endian: std.builtin.Endian) (NonCanonicalError || EncodingError)!P256 {
63 const x = try Fe.fromBytes(xs, endian);62 const x = try Fe.fromBytes(xs, endian);
64 const y = try Fe.fromBytes(ys, endian);63 const y = try Fe.fromBytes(ys, endian);
65 return fromAffineCoordinates(.{ .x = x, .y = y });64 return fromAffineCoordinates(.{ .x = x, .y = y });
...@@ -396,7 +395,7 @@ pub const P256 = struct {...@@ -396,7 +395,7 @@ pub const P256 = struct {
396395
397 /// Multiply an elliptic curve point by a scalar.396 /// Multiply an elliptic curve point by a scalar.
398 /// Return error.IdentityElement if the result is the identity element.397 /// Return error.IdentityElement if the result is the identity element.
399 pub fn mul(p: P256, s_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 {398 pub fn mul(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 {
400 const s = if (endian == .Little) s_ else Fe.orderSwap(s_);399 const s = if (endian == .Little) s_ else Fe.orderSwap(s_);
401 if (p.is_base) {400 if (p.is_base) {
402 return pcMul16(&basePointPc, s, false);401 return pcMul16(&basePointPc, s, false);
...@@ -408,7 +407,7 @@ pub const P256 = struct {...@@ -408,7 +407,7 @@ pub const P256 = struct {
408407
409 /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME*408 /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME*
410 /// This can be used for signature verification.409 /// This can be used for signature verification.
411 pub fn mulPublic(p: P256, s_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 {410 pub fn mulPublic(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 {
412 const s = if (endian == .Little) s_ else Fe.orderSwap(s_);411 const s = if (endian == .Little) s_ else Fe.orderSwap(s_);
413 if (p.is_base) {412 if (p.is_base) {
414 return pcMul16(&basePointPc, s, true);413 return pcMul16(&basePointPc, s, true);
...@@ -420,7 +419,7 @@ pub const P256 = struct {...@@ -420,7 +419,7 @@ pub const P256 = struct {
420419
421 /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME*420 /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME*
422 /// This can be used for signature verification.421 /// This can be used for signature verification.
423 pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: builtin.Endian) IdentityElementError!P256 {422 pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 {
424 const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_);423 const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_);
425 const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_);424 const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_);
426 try p1.rejectIdentity();425 try p1.rejectIdentity();
lib/std/crypto/pcurves/p256/p256_64.zig+1-1
...@@ -18,7 +18,7 @@...@@ -18,7 +18,7 @@
18// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^25618// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256
1919
20const std = @import("std");20const std = @import("std");
21const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels21const mode = @import("builtin").mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels
2222
23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.
24// Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]24// Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
lib/std/crypto/pcurves/p256/p256_scalar_64.zig+1-1
...@@ -18,7 +18,7 @@...@@ -18,7 +18,7 @@
18// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^25618// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256
1919
20const std = @import("std");20const std = @import("std");
21const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels21const mode = @import("builtin").mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels
2222
23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.
24// Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]24// Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
lib/std/crypto/pcurves/p256/scalar.zig+14-15
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const common = @import("../common.zig");2const common = @import("../common.zig");
4const crypto = std.crypto;3const crypto = std.crypto;
5const debug = std.debug;4const debug = std.debug;
...@@ -26,47 +25,47 @@ const Fe = Field(.{...@@ -26,47 +25,47 @@ const Fe = Field(.{
26});25});
2726
28/// Reject a scalar whose encoding is not canonical.27/// Reject a scalar whose encoding is not canonical.
29pub fn rejectNonCanonical(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!void {28pub fn rejectNonCanonical(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!void {
30 return Fe.rejectNonCanonical(s, endian);29 return Fe.rejectNonCanonical(s, endian);
31}30}
3231
33/// Reduce a 48-bytes scalar to the field size.32/// Reduce a 48-bytes scalar to the field size.
34pub fn reduce48(s: [48]u8, endian: builtin.Endian) CompressedScalar {33pub fn reduce48(s: [48]u8, endian: std.builtin.Endian) CompressedScalar {
35 return Scalar.fromBytes48(s, endian).toBytes(endian);34 return Scalar.fromBytes48(s, endian).toBytes(endian);
36}35}
3736
38/// Reduce a 64-bytes scalar to the field size.37/// Reduce a 64-bytes scalar to the field size.
39pub fn reduce64(s: [64]u8, endian: builtin.Endian) CompressedScalar {38pub fn reduce64(s: [64]u8, endian: std.builtin.Endian) CompressedScalar {
40 return ScalarDouble.fromBytes64(s, endian).toBytes(endian);39 return ScalarDouble.fromBytes64(s, endian).toBytes(endian);
41}40}
4241
43/// Return a*b (mod L)42/// Return a*b (mod L)
44pub fn mul(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {43pub fn mul(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar {
45 return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).toBytes(endian);44 return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).toBytes(endian);
46}45}
4746
48/// Return a*b+c (mod L)47/// Return a*b+c (mod L)
49pub fn mulAdd(a: CompressedScalar, b: CompressedScalar, c: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {48pub fn mulAdd(a: CompressedScalar, b: CompressedScalar, c: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar {
50 return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).add(try Scalar.fromBytes(c, endian)).toBytes(endian);49 return (try Scalar.fromBytes(a, endian)).mul(try Scalar.fromBytes(b, endian)).add(try Scalar.fromBytes(c, endian)).toBytes(endian);
51}50}
5251
53/// Return a+b (mod L)52/// Return a+b (mod L)
54pub fn add(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {53pub fn add(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar {
55 return (try Scalar.fromBytes(a, endian)).add(try Scalar.fromBytes(b, endian)).toBytes(endian);54 return (try Scalar.fromBytes(a, endian)).add(try Scalar.fromBytes(b, endian)).toBytes(endian);
56}55}
5756
58/// Return -s (mod L)57/// Return -s (mod L)
59pub fn neg(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {58pub fn neg(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar {
60 return (try Scalar.fromBytes(s, endian)).neg().toBytes(endian);59 return (try Scalar.fromBytes(s, endian)).neg().toBytes(endian);
61}60}
6261
63/// Return (a-b) (mod L)62/// Return (a-b) (mod L)
64pub fn sub(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {63pub fn sub(a: CompressedScalar, b: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!CompressedScalar {
65 return (try Scalar.fromBytes(a, endian)).sub(try Scalar.fromBytes(b.endian)).toBytes(endian);64 return (try Scalar.fromBytes(a, endian)).sub(try Scalar.fromBytes(b.endian)).toBytes(endian);
66}65}
6766
68/// Return a random scalar67/// Return a random scalar
69pub fn random(endian: builtin.Endian) CompressedScalar {68pub fn random(endian: std.builtin.Endian) CompressedScalar {
70 return Scalar.random().toBytes(endian);69 return Scalar.random().toBytes(endian);
71}70}
7271
...@@ -81,24 +80,24 @@ pub const Scalar = struct {...@@ -81,24 +80,24 @@ pub const Scalar = struct {
81 pub const one = Scalar{ .fe = Fe.one };80 pub const one = Scalar{ .fe = Fe.one };
8281
83 /// Unpack a serialized representation of a scalar.82 /// Unpack a serialized representation of a scalar.
84 pub fn fromBytes(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!Scalar {83 pub fn fromBytes(s: CompressedScalar, endian: std.builtin.Endian) NonCanonicalError!Scalar {
85 return Scalar{ .fe = try Fe.fromBytes(s, endian) };84 return Scalar{ .fe = try Fe.fromBytes(s, endian) };
86 }85 }
8786
88 /// Reduce a 384 bit input to the field size.87 /// Reduce a 384 bit input to the field size.
89 pub fn fromBytes48(s: [48]u8, endian: builtin.Endian) Scalar {88 pub fn fromBytes48(s: [48]u8, endian: std.builtin.Endian) Scalar {
90 const t = ScalarDouble.fromBytes(384, s, endian);89 const t = ScalarDouble.fromBytes(384, s, endian);
91 return t.reduce(384);90 return t.reduce(384);
92 }91 }
9392
94 /// Reduce a 512 bit input to the field size.93 /// Reduce a 512 bit input to the field size.
95 pub fn fromBytes64(s: [64]u8, endian: builtin.Endian) Scalar {94 pub fn fromBytes64(s: [64]u8, endian: std.builtin.Endian) Scalar {
96 const t = ScalarDouble.fromBytes(512, s, endian);95 const t = ScalarDouble.fromBytes(512, s, endian);
97 return t.reduce(512);96 return t.reduce(512);
98 }97 }
9998
100 /// Pack a scalar into bytes.99 /// Pack a scalar into bytes.
101 pub fn toBytes(n: Scalar, endian: builtin.Endian) CompressedScalar {100 pub fn toBytes(n: Scalar, endian: std.builtin.Endian) CompressedScalar {
102 return n.fe.toBytes(endian);101 return n.fe.toBytes(endian);
103 }102 }
104103
...@@ -180,7 +179,7 @@ const ScalarDouble = struct {...@@ -180,7 +179,7 @@ const ScalarDouble = struct {
180 x2: Fe,179 x2: Fe,
181 x3: Fe,180 x3: Fe,
182181
183 fn fromBytes(comptime bits: usize, s_: [bits / 8]u8, endian: builtin.Endian) ScalarDouble {182 fn fromBytes(comptime bits: usize, s_: [bits / 8]u8, endian: std.builtin.Endian) ScalarDouble {
184 debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3);183 debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3);
185184
186 var s = s_;185 var s = s_;
lib/std/crypto/salsa20.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const crypto = std.crypto;3const crypto = std.crypto;
3const debug = std.debug;4const debug = std.debug;
4const math = std.math;5const math = std.math;
...@@ -304,7 +305,7 @@ const Salsa20NonVecImpl = struct {...@@ -304,7 +305,7 @@ const Salsa20NonVecImpl = struct {
304 }305 }
305};306};
306307
307const Salsa20Impl = if (std.Target.current.cpu.arch == .x86_64) Salsa20VecImpl else Salsa20NonVecImpl;308const Salsa20Impl = if (builtin.cpu.arch == .x86_64) Salsa20VecImpl else Salsa20NonVecImpl;
308309
309fn keyToWords(key: [32]u8) [8]u32 {310fn keyToWords(key: [32]u8) [8]u32 {
310 var k: [8]u32 = undefined;311 var k: [8]u32 = undefined;
lib/std/crypto/tlcsprng.zig+5-4
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
4//! directly to standard library users.4//! directly to standard library users.
55
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");
7const root = @import("root");8const root = @import("root");
8const mem = std.mem;9const mem = std.mem;
9const os = std.os;10const os = std.os;
...@@ -12,7 +13,7 @@ const os = std.os;...@@ -12,7 +13,7 @@ const os = std.os;
12/// point to thread-local variables.13/// point to thread-local variables.
13pub var interface = std.rand.Random{ .fillFn = tlsCsprngFill };14pub var interface = std.rand.Random{ .fillFn = tlsCsprngFill };
1415
15const os_has_fork = switch (std.Target.current.os.tag) {16const os_has_fork = switch (builtin.os.tag) {
16 .dragonfly,17 .dragonfly,
17 .freebsd,18 .freebsd,
18 .ios,19 .ios,
...@@ -29,10 +30,10 @@ const os_has_fork = switch (std.Target.current.os.tag) {...@@ -29,10 +30,10 @@ const os_has_fork = switch (std.Target.current.os.tag) {
2930
30 else => false,31 else => false,
31};32};
32const os_has_arc4random = std.builtin.link_libc and @hasDecl(std.c, "arc4random_buf");33const os_has_arc4random = builtin.link_libc and @hasDecl(std.c, "arc4random_buf");
33const want_fork_safety = os_has_fork and !os_has_arc4random and34const want_fork_safety = os_has_fork and !os_has_arc4random and
34 (std.meta.globalOption("crypto_fork_safety", bool) orelse true);35 (std.meta.globalOption("crypto_fork_safety", bool) orelse true);
35const maybe_have_wipe_on_fork = std.Target.current.os.isAtLeast(.linux, .{36const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{
36 .major = 4,37 .major = 4,
37 .minor = 14,38 .minor = 14,
38}) orelse true;39}) orelse true;
...@@ -55,7 +56,7 @@ var install_atfork_handler = std.once(struct {...@@ -55,7 +56,7 @@ var install_atfork_handler = std.once(struct {
55threadlocal var wipe_mem: []align(mem.page_size) u8 = &[_]u8{};56threadlocal var wipe_mem: []align(mem.page_size) u8 = &[_]u8{};
5657
57fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {58fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
58 if (std.builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) {59 if (builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) {
59 // arc4random is already a thread-local CSPRNG.60 // arc4random is already a thread-local CSPRNG.
60 return std.c.arc4random_buf(buffer.ptr, buffer.len);61 return std.c.arc4random_buf(buffer.ptr, buffer.len);
61 }62 }
lib/std/cstr.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const mem = std.mem;4const mem = std.mem;
5const testing = std.testing;5const testing = std.testing;
lib/std/debug.zig+11-11
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const math = std.math;3const math = std.math;
4const mem = std.mem;4const mem = std.mem;
5const io = std.io;5const io = std.io;
...@@ -16,8 +16,8 @@ const root = @import("root");...@@ -16,8 +16,8 @@ const root = @import("root");
16const maxInt = std.math.maxInt;16const maxInt = std.math.maxInt;
17const File = std.fs.File;17const File = std.fs.File;
18const windows = std.os.windows;18const windows = std.os.windows;
19const native_arch = std.Target.current.cpu.arch;19const native_arch = builtin.cpu.arch;
20const native_os = std.Target.current.os.tag;20const native_os = builtin.os.tag;
21const native_endian = native_arch.endian();21const native_endian = native_arch.endian();
2222
23pub const runtime_safety = switch (builtin.mode) {23pub const runtime_safety = switch (builtin.mode) {
...@@ -150,7 +150,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {...@@ -150,7 +150,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
150/// capture that many stack frames exactly, and then look for the first address,150/// capture that many stack frames exactly, and then look for the first address,
151/// chopping off the irrelevant frames and shifting so that the returned addresses pointer151/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
152/// equals the passed in addresses pointer.152/// equals the passed in addresses pointer.
153pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {153pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackTrace) void {
154 if (native_os == .windows) {154 if (native_os == .windows) {
155 const addrs = stack_trace.instruction_addresses;155 const addrs = stack_trace.instruction_addresses;
156 const u32_addrs_len = @intCast(u32, addrs.len);156 const u32_addrs_len = @intCast(u32, addrs.len);
...@@ -194,7 +194,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace...@@ -194,7 +194,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
194194
195/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.195/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
196/// TODO multithreaded awareness196/// TODO multithreaded awareness
197pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {197pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
198 nosuspend {198 nosuspend {
199 const stderr = io.getStdErr().writer();199 const stderr = io.getStdErr().writer();
200 if (builtin.strip_debug_info) {200 if (builtin.strip_debug_info) {
...@@ -235,7 +235,7 @@ pub fn panic(comptime format: []const u8, args: anytype) noreturn {...@@ -235,7 +235,7 @@ pub fn panic(comptime format: []const u8, args: anytype) noreturn {
235/// `panicExtra` is useful when you want to print out an `@errorReturnTrace`235/// `panicExtra` is useful when you want to print out an `@errorReturnTrace`
236/// and also print out some values.236/// and also print out some values.
237pub fn panicExtra(237pub fn panicExtra(
238 trace: ?*builtin.StackTrace,238 trace: ?*std.builtin.StackTrace,
239 comptime format: []const u8,239 comptime format: []const u8,
240 args: anytype,240 args: anytype,
241) noreturn {241) noreturn {
...@@ -253,7 +253,7 @@ pub fn panicExtra(...@@ -253,7 +253,7 @@ pub fn panicExtra(
253 break :blk &buf;253 break :blk &buf;
254 },254 },
255 };255 };
256 builtin.panic(msg, trace);256 std.builtin.panic(msg, trace);
257}257}
258258
259/// Non-zero whenever the program triggered a panic.259/// Non-zero whenever the program triggered a panic.
...@@ -269,7 +269,7 @@ threadlocal var panic_stage: usize = 0;...@@ -269,7 +269,7 @@ threadlocal var panic_stage: usize = 0;
269269
270// `panicImpl` could be useful in implementing a custom panic handler which270// `panicImpl` could be useful in implementing a custom panic handler which
271// calls the default handler (on supported platforms)271// calls the default handler (on supported platforms)
272pub fn panicImpl(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {272pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {
273 @setCold(true);273 @setCold(true);
274274
275 if (enable_segfault_handler) {275 if (enable_segfault_handler) {
...@@ -339,7 +339,7 @@ const DIM = "\x1b[2m";...@@ -339,7 +339,7 @@ const DIM = "\x1b[2m";
339const RESET = "\x1b[0m";339const RESET = "\x1b[0m";
340340
341pub fn writeStackTrace(341pub fn writeStackTrace(
342 stack_trace: builtin.StackTrace,342 stack_trace: std.builtin.StackTrace,
343 out_stream: anytype,343 out_stream: anytype,
344 allocator: *mem.Allocator,344 allocator: *mem.Allocator,
345 debug_info: *DebugInfo,345 debug_info: *DebugInfo,
...@@ -764,7 +764,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI...@@ -764,7 +764,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
764 if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic;764 if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic;
765 if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;765 if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
766766
767 const endian: builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) {767 const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) {
768 elf.ELFDATA2LSB => .Little,768 elf.ELFDATA2LSB => .Little,
769 elf.ELFDATA2MSB => .Big,769 elf.ELFDATA2MSB => .Big,
770 else => return error.InvalidElfEndian,770 else => return error.InvalidElfEndian,
...@@ -1002,7 +1002,7 @@ pub const DebugInfo = struct {...@@ -1002,7 +1002,7 @@ pub const DebugInfo = struct {
1002 }1002 }
10031003
1004 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {1004 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1005 if (comptime std.Target.current.isDarwin()) {1005 if (comptime builtin.target.isDarwin()) {
1006 return self.lookupModuleDyld(address);1006 return self.lookupModuleDyld(address);
1007 } else if (native_os == .windows) {1007 } else if (native_os == .windows) {
1008 return self.lookupModuleWin32(address);1008 return self.lookupModuleWin32(address);
lib/std/dwarf.zig+7-8
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;
3const debug = std.debug;2const debug = std.debug;
4const fs = std.fs;3const fs = std.fs;
5const io = std.io;4const io = std.io;
...@@ -454,7 +453,7 @@ const LineNumberProgram = struct {...@@ -454,7 +453,7 @@ const LineNumberProgram = struct {
454 }453 }
455};454};
456455
457fn readUnitLength(in_stream: anytype, endian: builtin.Endian, is_64: *bool) !u64 {456fn readUnitLength(in_stream: anytype, endian: std.builtin.Endian, is_64: *bool) !u64 {
458 const first_32_bits = try in_stream.readInt(u32, endian);457 const first_32_bits = try in_stream.readInt(u32, endian);
459 is_64.* = (first_32_bits == 0xffffffff);458 is_64.* = (first_32_bits == 0xffffffff);
460 if (is_64.*) {459 if (is_64.*) {
...@@ -475,7 +474,7 @@ fn readAllocBytes(allocator: *mem.Allocator, in_stream: anytype, size: usize) ![...@@ -475,7 +474,7 @@ fn readAllocBytes(allocator: *mem.Allocator, in_stream: anytype, size: usize) ![
475}474}
476475
477// TODO the nosuspends here are workarounds476// TODO the nosuspends here are workarounds
478fn readAddress(in_stream: anytype, endian: builtin.Endian, is_64: bool) !u64 {477fn readAddress(in_stream: anytype, endian: std.builtin.Endian, is_64: bool) !u64 {
479 return nosuspend if (is_64)478 return nosuspend if (is_64)
480 try in_stream.readInt(u64, endian)479 try in_stream.readInt(u64, endian)
481 else480 else
...@@ -488,12 +487,12 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: anytype, size: u...@@ -488,12 +487,12 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: anytype, size: u
488}487}
489488
490// TODO the nosuspends here are workarounds489// TODO the nosuspends here are workarounds
491fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: usize) !FormValue {490fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: usize) !FormValue {
492 const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);491 const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);
493 return parseFormValueBlockLen(allocator, in_stream, block_len);492 return parseFormValueBlockLen(allocator, in_stream, block_len);
494}493}
495494
496fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {495fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: std.builtin.Endian, comptime size: i32) !FormValue {
497 _ = allocator;496 _ = allocator;
498 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.497 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
499 // `nosuspend` should be removed from all the function calls once it is fixed.498 // `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:...@@ -521,7 +520,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed:
521}520}
522521
523// TODO the nosuspends here are workarounds522// TODO the nosuspends here are workarounds
524fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue {523fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: i32) !FormValue {
525 _ = allocator;524 _ = allocator;
526 return FormValue{525 return FormValue{
527 .Ref = switch (size) {526 .Ref = switch (size) {
...@@ -536,7 +535,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: buil...@@ -536,7 +535,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: buil
536}535}
537536
538// TODO the nosuspends here are workarounds537// TODO the nosuspends here are workarounds
539fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue {538fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: std.builtin.Endian, is_64: bool) anyerror!FormValue {
540 return switch (form_id) {539 return switch (form_id) {
541 FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },540 FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },
542 FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1),541 FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1),
...@@ -593,7 +592,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con...@@ -593,7 +592,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con
593}592}
594593
595pub const DwarfInfo = struct {594pub const DwarfInfo = struct {
596 endian: builtin.Endian,595 endian: std.builtin.Endian,
597 // No memory is owned by the DwarfInfo596 // No memory is owned by the DwarfInfo
598 debug_info: []const u8,597 debug_info: []const u8,
599 debug_abbrev: []const u8,598 debug_abbrev: []const u8,
lib/std/dynamic_library.zig+1-2
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const builtin = std.builtin;
2
3const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
4const mem = std.mem;3const mem = std.mem;
5const os = std.os;4const os = std.os;
6const assert = std.debug.assert;5const assert = std.debug.assert;
lib/std/event/channel.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;4const testing = std.testing;
5const Loop = std.event.Loop;5const Loop = std.event.Loop;
lib/std/event/future.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const testing = std.testing;4const testing = std.testing;
4const builtin = std.builtin;
5const Lock = std.event.Lock;5const Lock = std.event.Lock;
66
7/// This is a value that starts out unavailable, until resolve() is called7/// This is a value that starts out unavailable, until resolve() is called
lib/std/event/group.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const Lock = std.event.Lock;3const Lock = std.event.Lock;
4const testing = std.testing;4const testing = std.testing;
5const Allocator = std.mem.Allocator;5const Allocator = std.mem.Allocator;
lib/std/event/lock.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;4const testing = std.testing;
5const mem = std.mem;5const mem = std.mem;
lib/std/event/loop.zig+4-4
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const root = @import("root");3const root = @import("root");
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const testing = std.testing;5const testing = std.testing;
...@@ -9,7 +9,7 @@ const windows = os.windows;...@@ -9,7 +9,7 @@ const windows = os.windows;
9const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
10const Thread = std.Thread;10const Thread = std.Thread;
1111
12const is_windows = std.Target.current.os.tag == .windows;12const is_windows = builtin.os.tag == .windows;
1313
14pub const Loop = struct {14pub const Loop = struct {
15 next_tick_queue: std.atomic.Queue(anyframe),15 next_tick_queue: std.atomic.Queue(anyframe),
...@@ -191,7 +191,7 @@ pub const Loop = struct {...@@ -191,7 +191,7 @@ pub const Loop = struct {
191 self.fs_thread.join();191 self.fs_thread.join();
192 };192 };
193193
194 if (!std.builtin.single_threaded)194 if (!builtin.single_threaded)
195 try self.delay_queue.init();195 try self.delay_queue.init();
196 }196 }
197197
...@@ -825,7 +825,7 @@ pub const Loop = struct {...@@ -825,7 +825,7 @@ pub const Loop = struct {
825 }825 }
826826
827 pub fn sleep(self: *Loop, nanoseconds: u64) void {827 pub fn sleep(self: *Loop, nanoseconds: u64) void {
828 if (std.builtin.single_threaded)828 if (builtin.single_threaded)
829 @compileError("TODO: integrate timers with epoll/kevent/iocp for single-threaded");829 @compileError("TODO: integrate timers with epoll/kevent/iocp for single-threaded");
830830
831 suspend {831 suspend {
lib/std/event/rwlock.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;4const testing = std.testing;
5const mem = std.mem;5const mem = std.mem;
lib/std/event/wait_group.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const Loop = std.event.Loop;3const Loop = std.event.Loop;
44
5/// A WaitGroup keeps track and waits for a group of async tasks to finish.5/// A WaitGroup keeps track and waits for a group of async tasks to finish.
lib/std/fs.zig+5-5
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const root = @import("root");
2const builtin = std.builtin;
3const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
3const root = @import("root");
4const os = std.os;4const os = std.os;
5const mem = std.mem;5const mem = std.mem;
6const base64 = std.base64;6const base64 = std.base64;
...@@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator;...@@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator;
9const assert = std.debug.assert;9const assert = std.debug.assert;
10const math = std.math;10const math = std.math;
1111
12const is_darwin = std.Target.current.os.tag.isDarwin();12const is_darwin = builtin.os.tag.isDarwin();
1313
14pub const path = @import("fs/path.zig");14pub const path = @import("fs/path.zig");
15pub const File = @import("fs/file.zig").File;15pub const File = @import("fs/file.zig").File;
...@@ -2607,7 +2607,7 @@ const CopyFileError = error{SystemResources} || os.CopyFileRangeError || os.Send...@@ -2607,7 +2607,7 @@ const CopyFileError = error{SystemResources} || os.CopyFileRangeError || os.Send
2607// The copy starts at offset 0, the initial offsets are preserved.2607// The copy starts at offset 0, the initial offsets are preserved.
2608// No metadata is transferred over.2608// No metadata is transferred over.
2609fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {2609fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
2610 if (comptime std.Target.current.isDarwin()) {2610 if (comptime builtin.target.isDarwin()) {
2611 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);2611 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
2612 switch (os.errno(rc)) {2612 switch (os.errno(rc)) {
2613 .SUCCESS => return,2613 .SUCCESS => return,
...@@ -2620,7 +2620,7 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {...@@ -2620,7 +2620,7 @@ fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void {
2620 }2620 }
2621 }2621 }
26222622
2623 if (std.Target.current.os.tag == .linux) {2623 if (builtin.os.tag == .linux) {
2624 // Try copy_file_range first as that works at the FS level and is the2624 // Try copy_file_range first as that works at the FS level and is the
2625 // most efficient method (if available).2625 // most efficient method (if available).
2626 var offset: u64 = 0;2626 var offset: u64 = 0;
lib/std/fs/file.zig+3-3
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const os = std.os;3const os = std.os;
4const io = std.io;4const io = std.io;
5const mem = std.mem;5const mem = std.mem;
6const math = std.math;6const math = std.math;
7const assert = std.debug.assert;7const assert = std.debug.assert;
8const windows = os.windows;8const windows = os.windows;
9const Os = builtin.Os;9const Os = std.builtin.Os;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
11const is_windows = std.Target.current.os.tag == .windows;11const is_windows = builtin.os.tag == .windows;
1212
13pub const File = struct {13pub const File = struct {
14 /// The OS-specific file descriptor or file handle.14 /// The OS-specific file descriptor or file handle.
lib/std/fs/get_app_data_dir.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const unicode = std.unicode;3const unicode = std.unicode;
4const mem = std.mem;4const mem = std.mem;
5const fs = std.fs;5const fs = std.fs;
lib/std/fs/test.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const testing = std.testing;3const testing = std.testing;
3const builtin = std.builtin;
4const fs = std.fs;4const fs = std.fs;
5const mem = std.mem;5const mem = std.mem;
6const wasi = std.os.wasi;6const wasi = std.os.wasi;
lib/std/fs/wasi.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const os = std.os;3const os = std.os;
3const mem = std.mem;4const mem = std.mem;
4const math = std.math;5const math = std.math;
...@@ -165,7 +166,7 @@ pub const PreopenList = struct {...@@ -165,7 +166,7 @@ pub const PreopenList = struct {
165};166};
166167
167test "extracting WASI preopens" {168test "extracting WASI preopens" {
168 if (std.builtin.os.tag != .wasi or std.builtin.link_libc) return error.SkipZigTest;169 if (builtin.os.tag != .wasi or builtin.link_libc) return error.SkipZigTest;
169170
170 var preopens = PreopenList.init(std.testing.allocator);171 var preopens = PreopenList.init(std.testing.allocator);
171 defer preopens.deinit();172 defer preopens.deinit();
lib/std/fs/watch.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const event = std.event;3const event = std.event;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const testing = std.testing;5const testing = std.testing;
...@@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type {...@@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type {
250 };250 };
251251
252 // @TODO Can I close this fd and get an error from bsdWaitKev?252 // @TODO Can I close this fd and get an error from bsdWaitKev?
253 const flags = if (comptime std.Target.current.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0;253 const flags = if (comptime builtin.target.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0;
254 const fd = try os.open(realpath, flags, 0);254 const fd = try os.open(realpath, flags, 0);
255 gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*);255 gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*);
256 return null;256 return null;
lib/std/hash/auto_hash.zig+1-2
...@@ -2,7 +2,6 @@ const std = @import("std");...@@ -2,7 +2,6 @@ const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const mem = std.mem;3const mem = std.mem;
4const meta = std.meta;4const meta = std.meta;
5const builtin = std.builtin;
65
7/// Describes how pointer types should be hashed.6/// Describes how pointer types should be hashed.
8pub const HashStrategy = enum {7pub const HashStrategy = enum {
...@@ -233,7 +232,7 @@ fn testHashDeepRecursive(key: anytype) u64 {...@@ -233,7 +232,7 @@ fn testHashDeepRecursive(key: anytype) u64 {
233232
234test "typeContainsSlice" {233test "typeContainsSlice" {
235 comptime {234 comptime {
236 try testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));235 try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
237236
238 try testing.expect(typeContainsSlice([]const u8));237 try testing.expect(typeContainsSlice([]const u8));
239 try testing.expect(!typeContainsSlice(u8));238 try testing.expect(!typeContainsSlice(u8));
lib/std/hash/benchmark.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig
22
3const builtin = std.builtin;
4const std = @import("std");3const std = @import("std");
4const builtin = @import("builtin");
5const time = std.time;5const time = std.time;
6const Timer = time.Timer;6const Timer = time.Timer;
7const hash = std.hash;7const hash = std.hash;
lib/std/hash/cityhash.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
32
4inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {3inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {
5 // ptr + offset doesn't work at comptime so we need this instead.4 // ptr + offset doesn't work at comptime so we need this instead.
lib/std/hash/crc.zig+2-1
...@@ -6,6 +6,7 @@...@@ -6,6 +6,7 @@
6// still moderately fast just slow relative to the slicing approach.6// still moderately fast just slow relative to the slicing approach.
77
8const std = @import("../std.zig");8const std = @import("../std.zig");
9const builtin = @import("builtin");
9const debug = std.debug;10const debug = std.debug;
10const testing = std.testing;11const testing = std.testing;
1112
...@@ -97,7 +98,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {...@@ -97,7 +98,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
97 };98 };
98}99}
99100
100const please_windows_dont_oom = std.Target.current.os.tag == .windows;101const please_windows_dont_oom = builtin.os.tag == .windows;
101102
102test "crc32 ieee" {103test "crc32 ieee" {
103 if (please_windows_dont_oom) return error.SkipZigTest;104 if (please_windows_dont_oom) return error.SkipZigTest;
lib/std/heap.zig+10-10
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
2const root = @import("root");3const root = @import("root");
3const debug = std.debug;4const debug = std.debug;
4const assert = debug.assert;5const assert = debug.assert;
5const testing = std.testing;6const testing = std.testing;
6const mem = std.mem;7const mem = std.mem;
7const os = std.os;8const os = std.os;
8const builtin = std.builtin;
9const c = std.c;9const c = std.c;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1111
...@@ -209,9 +209,9 @@ fn rawCResize(...@@ -209,9 +209,9 @@ fn rawCResize(
209209
210/// This allocator makes a syscall directly for every allocation and free.210/// This allocator makes a syscall directly for every allocation and free.
211/// Thread-safe and lock-free.211/// Thread-safe and lock-free.
212pub const page_allocator = if (std.Target.current.isWasm())212pub const page_allocator = if (builtin.target.isWasm())
213 &wasm_page_allocator_state213 &wasm_page_allocator_state
214else if (std.Target.current.os.tag == .freestanding)214else if (builtin.target.os.tag == .freestanding)
215 root.os.heap.page_allocator215 root.os.heap.page_allocator
216else216else
217 &page_allocator_state;217 &page_allocator_state;
...@@ -402,7 +402,7 @@ const PageAllocator = struct {...@@ -402,7 +402,7 @@ const PageAllocator = struct {
402402
403const WasmPageAllocator = struct {403const WasmPageAllocator = struct {
404 comptime {404 comptime {
405 if (!std.Target.current.isWasm()) {405 if (!builtin.target.isWasm()) {
406 @compileError("WasmPageAllocator is only available for wasm32 arch");406 @compileError("WasmPageAllocator is only available for wasm32 arch");
407 }407 }
408 }408 }
...@@ -608,11 +608,11 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -608,11 +608,11 @@ pub const HeapAllocator = switch (builtin.os.tag) {
608 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);608 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
609609
610 const amt = n + ptr_align - 1 + @sizeOf(usize);610 const amt = n + ptr_align - 1 + @sizeOf(usize);
611 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst);611 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst);
612 const heap_handle = optional_heap_handle orelse blk: {612 const heap_handle = optional_heap_handle orelse blk: {
613 const options = if (builtin.single_threaded) os.windows.HEAP_NO_SERIALIZE else 0;613 const options = if (builtin.single_threaded) os.windows.HEAP_NO_SERIALIZE else 0;
614 const hh = os.windows.kernel32.HeapCreate(options, amt, 0) orelse return error.OutOfMemory;614 const hh = os.windows.kernel32.HeapCreate(options, amt, 0) orelse return error.OutOfMemory;
615 const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse break :blk hh;615 const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, .SeqCst, .SeqCst) orelse break :blk hh;
616 os.windows.HeapDestroy(hh);616 os.windows.HeapDestroy(hh);
617 break :blk other_hh.?; // can't be null because of the cmpxchg617 break :blk other_hh.?; // can't be null because of the cmpxchg
618 };618 };
...@@ -792,7 +792,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: {...@@ -792,7 +792,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: {
792 _ = len_align;792 _ = len_align;
793 _ = ra;793 _ = ra;
794 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);794 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
795 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);795 var end_index = @atomicLoad(usize, &self.end_index, .SeqCst);
796 while (true) {796 while (true) {
797 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse797 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse
798 return error.OutOfMemory;798 return error.OutOfMemory;
...@@ -801,7 +801,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: {...@@ -801,7 +801,7 @@ pub const ThreadSafeFixedBufferAllocator = blk: {
801 if (new_end_index > self.buffer.len) {801 if (new_end_index > self.buffer.len) {
802 return error.OutOfMemory;802 return error.OutOfMemory;
803 }803 }
804 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];804 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .SeqCst, .SeqCst) orelse return self.buffer[adjusted_index..new_end_index];
805 }805 }
806 }806 }
807807
...@@ -884,7 +884,7 @@ test "raw_c_allocator" {...@@ -884,7 +884,7 @@ test "raw_c_allocator" {
884}884}
885885
886test "WasmPageAllocator internals" {886test "WasmPageAllocator internals" {
887 if (comptime std.Target.current.isWasm()) {887 if (comptime builtin.target.isWasm()) {
888 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;888 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
889 const initial = try page_allocator.alloc(u8, mem.page_size);889 const initial = try page_allocator.alloc(u8, mem.page_size);
890 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.890 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" {...@@ -924,7 +924,7 @@ test "PageAllocator" {
924 const allocator = page_allocator;924 const allocator = page_allocator;
925 try testAllocator(allocator);925 try testAllocator(allocator);
926 try testAllocatorAligned(allocator);926 try testAllocatorAligned(allocator);
927 if (!std.Target.current.isWasm()) {927 if (!builtin.target.isWasm()) {
928 try testAllocatorLargeAlignment(allocator);928 try testAllocatorLargeAlignment(allocator);
929 try testAllocatorAlignedShrink(allocator);929 try testAllocatorAlignedShrink(allocator);
930 }930 }
lib/std/heap/general_purpose_allocator.zig+8-7
...@@ -93,6 +93,7 @@...@@ -93,6 +93,7 @@
93//! in a `std.HashMap` using the backing allocator.93//! in a `std.HashMap` using the backing allocator.
9494
95const std = @import("std");95const std = @import("std");
96const builtin = @import("builtin");
96const log = std.log.scoped(.gpa);97const log = std.log.scoped(.gpa);
97const math = std.math;98const math = std.math;
98const assert = std.debug.assert;99const assert = std.debug.assert;
...@@ -104,7 +105,7 @@ const StackTrace = std.builtin.StackTrace;...@@ -104,7 +105,7 @@ const StackTrace = std.builtin.StackTrace;
104/// Integer type for pointing to slots in a small allocation105/// Integer type for pointing to slots in a small allocation
105const SlotIndex = std.meta.Int(.unsigned, math.log2(page_size) + 1);106const SlotIndex = std.meta.Int(.unsigned, math.log2(page_size) + 1);
106107
107const sys_can_stack_trace = switch (std.Target.current.cpu.arch) {108const sys_can_stack_trace = switch (builtin.cpu.arch) {
108 // Observed to go into an infinite loop.109 // Observed to go into an infinite loop.
109 // TODO: Make this work.110 // TODO: Make this work.
110 .mips,111 .mips,
...@@ -115,13 +116,13 @@ const sys_can_stack_trace = switch (std.Target.current.cpu.arch) {...@@ -115,13 +116,13 @@ const sys_can_stack_trace = switch (std.Target.current.cpu.arch) {
115 // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".116 // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".
116 .wasm32,117 .wasm32,
117 .wasm64,118 .wasm64,
118 => std.Target.current.os.tag == .emscripten,119 => builtin.os.tag == .emscripten,
119120
120 else => true,121 else => true,
121};122};
122const default_test_stack_trace_frames: usize = if (std.builtin.is_test) 8 else 4;123const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;
123const default_sys_stack_trace_frames: usize = if (sys_can_stack_trace) default_test_stack_trace_frames else 0;124const default_sys_stack_trace_frames: usize = if (sys_can_stack_trace) default_test_stack_trace_frames else 0;
124const default_stack_trace_frames: usize = switch (std.builtin.mode) {125const default_stack_trace_frames: usize = switch (builtin.mode) {
125 .Debug => default_sys_stack_trace_frames,126 .Debug => default_sys_stack_trace_frames,
126 else => 0,127 else => 0,
127};128};
...@@ -141,7 +142,7 @@ pub const Config = struct {...@@ -141,7 +142,7 @@ pub const Config = struct {
141 safety: bool = std.debug.runtime_safety,142 safety: bool = std.debug.runtime_safety,
142143
143 /// Whether the allocator may be used simultaneously from multiple threads.144 /// Whether the allocator may be used simultaneously from multiple threads.
144 thread_safe: bool = !std.builtin.single_threaded,145 thread_safe: bool = !builtin.single_threaded,
145146
146 /// What type of mutex you'd like to use, for thread safety.147 /// What type of mutex you'd like to use, for thread safety.
147 /// when specfied, the mutex type must have the same shape as `std.Thread.Mutex` and148 /// 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" {...@@ -988,7 +989,7 @@ test "shrink large object to large object with larger alignment" {
988 var slice = try allocator.alignedAlloc(u8, 16, alloc_size);989 var slice = try allocator.alignedAlloc(u8, 16, alloc_size);
989 defer allocator.free(slice);990 defer allocator.free(slice);
990991
991 const big_alignment: usize = switch (std.Target.current.os.tag) {992 const big_alignment: usize = switch (builtin.os.tag) {
992 .windows => page_size * 32, // Windows aligns to 64K.993 .windows => page_size * 32, // Windows aligns to 64K.
993 else => page_size * 2,994 else => page_size * 2,
994 };995 };
...@@ -1058,7 +1059,7 @@ test "realloc large object to larger alignment" {...@@ -1058,7 +1059,7 @@ test "realloc large object to larger alignment" {
1058 var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50);1059 var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50);
1059 defer allocator.free(slice);1060 defer allocator.free(slice);
10601061
1061 const big_alignment: usize = switch (std.Target.current.os.tag) {1062 const big_alignment: usize = switch (builtin.os.tag) {
1062 .windows => page_size * 32, // Windows aligns to 64K.1063 .windows => page_size * 32, // Windows aligns to 64K.
1063 else => page_size * 2,1064 else => page_size * 2,
1064 };1065 };
lib/std/io.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const root = @import("root");3const root = @import("root");
4const c = std.c;4const c = std.c;
55
lib/std/io/bit_reader.zig+2-3
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;
3const io = std.io;2const io = std.io;
4const assert = std.debug.assert;3const assert = std.debug.assert;
5const testing = std.testing;4const testing = std.testing;
...@@ -8,7 +7,7 @@ const meta = std.meta;...@@ -8,7 +7,7 @@ const meta = std.meta;
8const math = std.math;7const math = std.math;
98
10/// Creates a stream which allows for reading bit fields from another stream9/// Creates a stream which allows for reading bit fields from another stream
11pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {10pub fn BitReader(endian: std.builtin.Endian, comptime ReaderType: type) type {
12 return struct {11 return struct {
13 forward_reader: ReaderType,12 forward_reader: ReaderType,
14 bit_buffer: u7,13 bit_buffer: u7,
...@@ -162,7 +161,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {...@@ -162,7 +161,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {
162}161}
163162
164pub fn bitReader(163pub fn bitReader(
165 comptime endian: builtin.Endian,164 comptime endian: std.builtin.Endian,
166 underlying_stream: anytype,165 underlying_stream: anytype,
167) BitReader(endian, @TypeOf(underlying_stream)) {166) BitReader(endian, @TypeOf(underlying_stream)) {
168 return BitReader(endian, @TypeOf(underlying_stream)).init(underlying_stream);167 return BitReader(endian, @TypeOf(underlying_stream)).init(underlying_stream);
lib/std/io/bit_writer.zig+2-3
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;
3const io = std.io;2const io = std.io;
4const testing = std.testing;3const testing = std.testing;
5const assert = std.debug.assert;4const assert = std.debug.assert;
...@@ -8,7 +7,7 @@ const meta = std.meta;...@@ -8,7 +7,7 @@ const meta = std.meta;
8const math = std.math;7const math = std.math;
98
10/// Creates a stream which allows for writing bit fields to another stream9/// Creates a stream which allows for writing bit fields to another stream
11pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {10pub fn BitWriter(endian: std.builtin.Endian, comptime WriterType: type) type {
12 return struct {11 return struct {
13 forward_writer: WriterType,12 forward_writer: WriterType,
14 bit_buffer: u8,13 bit_buffer: u8,
...@@ -138,7 +137,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {...@@ -138,7 +137,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {
138}137}
139138
140pub fn bitWriter(139pub fn bitWriter(
141 comptime endian: builtin.Endian,140 comptime endian: std.builtin.Endian,
142 underlying_stream: anytype,141 underlying_stream: anytype,
143) BitWriter(endian, @TypeOf(underlying_stream)) {142) BitWriter(endian, @TypeOf(underlying_stream)) {
144 return BitWriter(endian, @TypeOf(underlying_stream)).init(underlying_stream);143 return BitWriter(endian, @TypeOf(underlying_stream)).init(underlying_stream);
lib/std/io/c_writer.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const io = std.io;3const io = std.io;
4const testing = std.testing;4const testing = std.testing;
5const os = std.os;5const os = std.os;
lib/std/io/reader.zig+4-5
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;
3const math = std.math;2const math = std.math;
4const assert = std.debug.assert;3const assert = std.debug.assert;
5const mem = std.mem;4const mem = std.mem;
...@@ -265,12 +264,12 @@ pub fn Reader(...@@ -265,12 +264,12 @@ pub fn Reader(
265 return mem.readIntBig(T, &bytes);264 return mem.readIntBig(T, &bytes);
266 }265 }
267266
268 pub fn readInt(self: Self, comptime T: type, endian: builtin.Endian) !T {267 pub fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) !T {
269 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);268 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
270 return mem.readInt(T, &bytes, endian);269 return mem.readInt(T, &bytes, endian);
271 }270 }
272271
273 pub fn readVarInt(self: Self, comptime ReturnType: type, endian: builtin.Endian, size: usize) !ReturnType {272 pub fn readVarInt(self: Self, comptime ReturnType: type, endian: std.builtin.Endian, size: usize) !ReturnType {
274 assert(size <= @sizeOf(ReturnType));273 assert(size <= @sizeOf(ReturnType));
275 var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined;274 var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined;
276 const bytes = bytes_buf[0..size];275 const bytes = bytes_buf[0..size];
...@@ -310,7 +309,7 @@ pub fn Reader(...@@ -310,7 +309,7 @@ pub fn Reader(
310309
311 pub fn readStruct(self: Self, comptime T: type) !T {310 pub fn readStruct(self: Self, comptime T: type) !T {
312 // Only extern and packed structs have defined in-memory layout.311 // Only extern and packed structs have defined in-memory layout.
313 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);312 comptime assert(@typeInfo(T).Struct.layout != std.builtin.TypeInfo.ContainerLayout.Auto);
314 var res: [1]T = undefined;313 var res: [1]T = undefined;
315 try self.readNoEof(mem.sliceAsBytes(res[0..]));314 try self.readNoEof(mem.sliceAsBytes(res[0..]));
316 return res[0];315 return res[0];
...@@ -319,7 +318,7 @@ pub fn Reader(...@@ -319,7 +318,7 @@ pub fn Reader(
319 /// Reads an integer with the same size as the given enum's tag type. If the integer matches318 /// Reads an integer with the same size as the given enum's tag type. If the integer matches
320 /// an enum tag, casts the integer to the enum tag and returns it. Otherwise, returns an error.319 /// an enum tag, casts the integer to the enum tag and returns it. Otherwise, returns an error.
321 /// TODO optimization taking advantage of most fields being in order320 /// TODO optimization taking advantage of most fields being in order
322 pub fn readEnum(self: Self, comptime Enum: type, endian: builtin.Endian) !Enum {321 pub fn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) !Enum {
323 const E = error{322 const E = error{
324 /// An integer was read, but it did not match any of the tags in the supplied enum.323 /// An integer was read, but it did not match any of the tags in the supplied enum.
325 InvalidValue,324 InvalidValue,
lib/std/io/stream_source.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const io = std.io;3const io = std.io;
34
4/// Provides `io.Reader`, `io.Writer`, and `io.SeekableStream` for in-memory buffers as5/// Provides `io.Reader`, `io.Writer`, and `io.SeekableStream` for in-memory buffers as
...@@ -6,7 +7,7 @@ const io = std.io;...@@ -6,7 +7,7 @@ const io = std.io;
6/// For memory sources, if the supplied byte buffer is const, then `io.Writer` is not available.7/// For memory sources, if the supplied byte buffer is const, then `io.Writer` is not available.
7/// The error set of the stream functions is the error set of the corresponding file functions.8/// The error set of the stream functions is the error set of the corresponding file functions.
8pub const StreamSource = union(enum) {9pub const StreamSource = union(enum) {
9 const has_file = (std.builtin.os.tag != .freestanding);10 const has_file = (builtin.os.tag != .freestanding);
1011
11 /// The stream access is redirected to this buffer.12 /// The stream access is redirected to this buffer.
12 buffer: io.FixedBufferStream([]u8),13 buffer: io.FixedBufferStream([]u8),
lib/std/io/writer.zig+2-3
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const builtin = std.builtin;
4const mem = std.mem;3const mem = std.mem;
54
6pub fn Writer(5pub fn Writer(
...@@ -77,7 +76,7 @@ pub fn Writer(...@@ -77,7 +76,7 @@ pub fn Writer(
77 }76 }
7877
79 /// TODO audit non-power-of-two int sizes78 /// TODO audit non-power-of-two int sizes
80 pub fn writeInt(self: Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {79 pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void {
81 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;80 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
82 mem.writeInt(T, &bytes, value, endian);81 mem.writeInt(T, &bytes, value, endian);
83 return self.writeAll(&bytes);82 return self.writeAll(&bytes);
...@@ -85,7 +84,7 @@ pub fn Writer(...@@ -85,7 +84,7 @@ pub fn Writer(
8584
86 pub fn writeStruct(self: Self, value: anytype) Error!void {85 pub fn writeStruct(self: Self, value: anytype) Error!void {
87 // Only extern and packed structs have defined in-memory layout.86 // Only extern and packed structs have defined in-memory layout.
88 comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);87 comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != std.builtin.TypeInfo.ContainerLayout.Auto);
89 return self.writeAll(mem.asBytes(&value));88 return self.writeAll(mem.asBytes(&value));
90 }89 }
91 };90 };
lib/std/log.zig+2-2
...@@ -69,7 +69,7 @@...@@ -69,7 +69,7 @@
69//! ```69//! ```
7070
71const std = @import("std.zig");71const std = @import("std.zig");
72const builtin = std.builtin;72const builtin = @import("builtin");
73const root = @import("root");73const root = @import("root");
7474
75pub const Level = enum {75pub const Level = enum {
...@@ -170,7 +170,7 @@ pub fn defaultLog(...@@ -170,7 +170,7 @@ pub fn defaultLog(
170 comptime format: []const u8,170 comptime format: []const u8,
171 args: anytype,171 args: anytype,
172) void {172) void {
173 if (std.Target.current.os.tag == .freestanding) {173 if (builtin.os.tag == .freestanding) {
174 // On freestanding one must provide a log function; we do not have174 // On freestanding one must provide a log function; we do not have
175 // any I/O configured.175 // any I/O configured.
176 return;176 return;
lib/std/mem.zig+4-3
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
2const debug = std.debug;3const debug = std.debug;
3const assert = debug.assert;4const assert = debug.assert;
4const math = std.math;5const math = std.math;
...@@ -7,13 +8,13 @@ const meta = std.meta;...@@ -7,13 +8,13 @@ const meta = std.meta;
7const trait = meta.trait;8const trait = meta.trait;
8const testing = std.testing;9const testing = std.testing;
9const Endian = std.builtin.Endian;10const Endian = std.builtin.Endian;
10const native_endian = std.Target.current.cpu.arch.endian();11const native_endian = builtin.cpu.arch.endian();
1112
12/// Compile time known minimum page size.13/// Compile time known minimum page size.
13/// https://github.com/ziglang/zig/issues/408214/// https://github.com/ziglang/zig/issues/4082
14pub const page_size = switch (std.Target.current.cpu.arch) {15pub const page_size = switch (builtin.cpu.arch) {
15 .wasm32, .wasm64 => 64 * 1024,16 .wasm32, .wasm64 => 64 * 1024,
16 .aarch64 => switch (std.Target.current.os.tag) {17 .aarch64 => switch (builtin.os.tag) {
17 .macos, .ios, .watchos, .tvos => 16 * 1024,18 .macos, .ios, .watchos, .tvos => 16 * 1024,
18 else => 4 * 1024,19 else => 4 * 1024,
19 },20 },
lib/std/meta.zig+2-3
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;
3const debug = std.debug;2const debug = std.debug;
4const mem = std.mem;3const mem = std.mem;
5const math = std.math;4const math = std.math;
...@@ -9,7 +8,7 @@ const root = @import("root");...@@ -9,7 +8,7 @@ const root = @import("root");
9pub const trait = @import("meta/trait.zig");8pub const trait = @import("meta/trait.zig");
10pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;9pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;
1110
12const TypeInfo = builtin.TypeInfo;11const TypeInfo = std.builtin.TypeInfo;
1312
14pub fn tagName(v: anytype) []const u8 {13pub fn tagName(v: anytype) []const u8 {
15 const T = @TypeOf(v);14 const T = @TypeOf(v);
...@@ -858,7 +857,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De...@@ -858,7 +857,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
858857
859pub const IntType = @compileError("replaced by std.meta.Int");858pub const IntType = @compileError("replaced by std.meta.Int");
860859
861pub fn Int(comptime signedness: builtin.Signedness, comptime bit_count: u16) type {860pub fn Int(comptime signedness: std.builtin.Signedness, comptime bit_count: u16) type {
862 return @Type(TypeInfo{861 return @Type(TypeInfo{
863 .Int = .{862 .Int = .{
864 .signedness = signedness,863 .signedness = signedness,
lib/std/meta/trait.zig+3-4
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;
3const mem = std.mem;2const mem = std.mem;
4const debug = std.debug;3const debug = std.debug;
5const testing = std.testing;4const testing = std.testing;
...@@ -98,7 +97,7 @@ test "std.meta.trait.hasField" {...@@ -98,7 +97,7 @@ test "std.meta.trait.hasField" {
98 try testing.expect(!hasField("value")(u8));97 try testing.expect(!hasField("value")(u8));
99}98}
10099
101pub fn is(comptime id: builtin.TypeId) TraitFn {100pub fn is(comptime id: std.builtin.TypeId) TraitFn {
102 const Closure = struct {101 const Closure = struct {
103 pub fn trait(comptime T: type) bool {102 pub fn trait(comptime T: type) bool {
104 return id == @typeInfo(T);103 return id == @typeInfo(T);
...@@ -115,7 +114,7 @@ test "std.meta.trait.is" {...@@ -115,7 +114,7 @@ test "std.meta.trait.is" {
115 try testing.expect(!is(.Optional)(anyerror));114 try testing.expect(!is(.Optional)(anyerror));
116}115}
117116
118pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {117pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn {
119 const Closure = struct {118 const Closure = struct {
120 pub fn trait(comptime T: type) bool {119 pub fn trait(comptime T: type) bool {
121 if (!comptime isSingleItemPtr(T)) return false;120 if (!comptime isSingleItemPtr(T)) return false;
...@@ -131,7 +130,7 @@ test "std.meta.trait.isPtrTo" {...@@ -131,7 +130,7 @@ test "std.meta.trait.isPtrTo" {
131 try testing.expect(!isPtrTo(.Struct)(**struct {}));130 try testing.expect(!isPtrTo(.Struct)(**struct {}));
132}131}
133132
134pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {133pub fn isSliceOf(comptime id: std.builtin.TypeId) TraitFn {
135 const Closure = struct {134 const Closure = struct {
136 pub fn trait(comptime T: type) bool {135 pub fn trait(comptime T: type) bool {
137 if (!comptime isSlice(T)) return false;136 if (!comptime isSlice(T)) return false;
lib/std/net.zig+3-3
...@@ -12,7 +12,7 @@ const native_endian = builtin.target.cpu.arch.endian();...@@ -12,7 +12,7 @@ const native_endian = builtin.target.cpu.arch.endian();
12// first release to support them.12// first release to support them.
13pub const has_unix_sockets = @hasDecl(os.sockaddr, "un") and13pub const has_unix_sockets = @hasDecl(os.sockaddr, "un") and
14 (builtin.target.os.tag != .windows or14 (builtin.target.os.tag != .windows or
15 std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);15 builtin.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
1616
17pub const Address = extern union {17pub const Address = extern union {
18 any: os.sockaddr,18 any: os.sockaddr,
...@@ -1623,7 +1623,7 @@ pub const Stream = struct {...@@ -1623,7 +1623,7 @@ pub const Stream = struct {
1623 }1623 }
16241624
1625 pub fn read(self: Stream, buffer: []u8) ReadError!usize {1625 pub fn read(self: Stream, buffer: []u8) ReadError!usize {
1626 if (std.Target.current.os.tag == .windows) {1626 if (builtin.os.tag == .windows) {
1627 return os.windows.ReadFile(self.handle, buffer, null, io.default_mode);1627 return os.windows.ReadFile(self.handle, buffer, null, io.default_mode);
1628 }1628 }
16291629
...@@ -1638,7 +1638,7 @@ pub const Stream = struct {...@@ -1638,7 +1638,7 @@ pub const Stream = struct {
1638 /// file system thread instead of non-blocking. It needs to be reworked to properly1638 /// file system thread instead of non-blocking. It needs to be reworked to properly
1639 /// use non-blocking I/O.1639 /// use non-blocking I/O.
1640 pub fn write(self: Stream, buffer: []const u8) WriteError!usize {1640 pub fn write(self: Stream, buffer: []const u8) WriteError!usize {
1641 if (std.Target.current.os.tag == .windows) {1641 if (builtin.os.tag == .windows) {
1642 return os.windows.WriteFile(self.handle, buffer, null, io.default_mode);1642 return os.windows.WriteFile(self.handle, buffer, null, io.default_mode);
1643 }1643 }
16441644
lib/std/net/test.zig+12-12
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const net = std.net;3const net = std.net;
4const mem = std.mem;4const mem = std.mem;
5const testing = std.testing;5const testing = std.testing;
...@@ -35,7 +35,7 @@ test "parse and render IPv6 addresses" {...@@ -35,7 +35,7 @@ test "parse and render IPv6 addresses" {
35 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;35 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
36 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));36 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3737
38 if (std.builtin.os.tag == .linux) {38 if (builtin.os.tag == .linux) {
39 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;39 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
40 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;40 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
41 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));41 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" {...@@ -49,7 +49,7 @@ test "parse and render IPv6 addresses" {
49 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));49 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
50 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));50 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
51 // TODO Make this test pass on other operating systems.51 // TODO Make this test pass on other operating systems.
52 if (std.builtin.os.tag == .linux) {52 if (builtin.os.tag == .linux) {
53 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));53 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
54 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));54 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
55 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));55 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
...@@ -57,7 +57,7 @@ test "parse and render IPv6 addresses" {...@@ -57,7 +57,7 @@ test "parse and render IPv6 addresses" {
57}57}
5858
59test "invalid but parseable IPv6 scope ids" {59test "invalid but parseable IPv6 scope ids" {
60 if (std.builtin.os.tag != .linux) {60 if (builtin.os.tag != .linux) {
61 // Currently, resolveIp6 with alphanumerical scope IDs only works on Linux.61 // Currently, resolveIp6 with alphanumerical scope IDs only works on Linux.
62 // TODO Make this test pass on other operating systems.62 // TODO Make this test pass on other operating systems.
63 return error.SkipZigTest;63 return error.SkipZigTest;
...@@ -106,11 +106,11 @@ test "parse and render UNIX addresses" {...@@ -106,11 +106,11 @@ test "parse and render UNIX addresses" {
106test "resolve DNS" {106test "resolve DNS" {
107 if (builtin.os.tag == .wasi) return error.SkipZigTest;107 if (builtin.os.tag == .wasi) return error.SkipZigTest;
108108
109 if (std.builtin.os.tag == .windows) {109 if (builtin.os.tag == .windows) {
110 _ = try std.os.windows.WSAStartup(2, 2);110 _ = try std.os.windows.WSAStartup(2, 2);
111 }111 }
112 defer {112 defer {
113 if (std.builtin.os.tag == .windows) {113 if (builtin.os.tag == .windows) {
114 std.os.windows.WSACleanup() catch unreachable;114 std.os.windows.WSACleanup() catch unreachable;
115 }115 }
116 }116 }
...@@ -143,11 +143,11 @@ test "listen on a port, send bytes, receive bytes" {...@@ -143,11 +143,11 @@ test "listen on a port, send bytes, receive bytes" {
143 if (builtin.single_threaded) return error.SkipZigTest;143 if (builtin.single_threaded) return error.SkipZigTest;
144 if (builtin.os.tag == .wasi) return error.SkipZigTest;144 if (builtin.os.tag == .wasi) return error.SkipZigTest;
145145
146 if (std.builtin.os.tag == .windows) {146 if (builtin.os.tag == .windows) {
147 _ = try std.os.windows.WSAStartup(2, 2);147 _ = try std.os.windows.WSAStartup(2, 2);
148 }148 }
149 defer {149 defer {
150 if (std.builtin.os.tag == .windows) {150 if (builtin.os.tag == .windows) {
151 std.os.windows.WSACleanup() catch unreachable;151 std.os.windows.WSACleanup() catch unreachable;
152 }152 }
153 }153 }
...@@ -185,7 +185,7 @@ test "listen on a port, send bytes, receive bytes" {...@@ -185,7 +185,7 @@ test "listen on a port, send bytes, receive bytes" {
185test "listen on a port, send bytes, receive bytes" {185test "listen on a port, send bytes, receive bytes" {
186 if (!std.io.is_async) return error.SkipZigTest;186 if (!std.io.is_async) return error.SkipZigTest;
187187
188 if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) {188 if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) {
189 // TODO build abstractions for other operating systems189 // TODO build abstractions for other operating systems
190 return error.SkipZigTest;190 return error.SkipZigTest;
191 }191 }
...@@ -207,7 +207,7 @@ test "listen on a port, send bytes, receive bytes" {...@@ -207,7 +207,7 @@ test "listen on a port, send bytes, receive bytes" {
207test "listen on ipv4 try connect on ipv6 then ipv4" {207test "listen on ipv4 try connect on ipv6 then ipv4" {
208 if (!std.io.is_async) return error.SkipZigTest;208 if (!std.io.is_async) return error.SkipZigTest;
209209
210 if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) {210 if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) {
211 // TODO build abstractions for other operating systems211 // TODO build abstractions for other operating systems
212 return error.SkipZigTest;212 return error.SkipZigTest;
213 }213 }
...@@ -267,11 +267,11 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -267,11 +267,11 @@ test "listen on a unix socket, send bytes, receive bytes" {
267 if (builtin.single_threaded) return error.SkipZigTest;267 if (builtin.single_threaded) return error.SkipZigTest;
268 if (!net.has_unix_sockets) return error.SkipZigTest;268 if (!net.has_unix_sockets) return error.SkipZigTest;
269269
270 if (std.builtin.os.tag == .windows) {270 if (builtin.os.tag == .windows) {
271 _ = try std.os.windows.WSAStartup(2, 2);271 _ = try std.os.windows.WSAStartup(2, 2);
272 }272 }
273 defer {273 defer {
274 if (std.builtin.os.tag == .windows) {274 if (builtin.os.tag == .windows) {
275 std.os.windows.WSACleanup() catch unreachable;275 std.os.windows.WSACleanup() catch unreachable;
276 }276 }
277 }277 }
lib/std/once.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const testing = std.testing;3const testing = std.testing;
44
5pub fn once(comptime f: fn () void) Once(f) {5pub fn once(comptime f: fn () void) Once(f) {
lib/std/os.zig+26-26
...@@ -240,7 +240,7 @@ pub fn close(fd: fd_t) void {...@@ -240,7 +240,7 @@ pub fn close(fd: fd_t) void {
240 _ = wasi.fd_close(fd);240 _ = wasi.fd_close(fd);
241 return;241 return;
242 }242 }
243 if (comptime std.Target.current.isDarwin()) {243 if (comptime builtin.target.isDarwin()) {
244 // This avoids the EINTR problem.244 // This avoids the EINTR problem.
245 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {245 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
246 .BADF => unreachable, // Always a race condition.246 .BADF => unreachable, // Always a race condition.
...@@ -487,7 +487,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -487,7 +487,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
487 }487 }
488488
489 // Prevents EINVAL.489 // Prevents EINVAL.
490 const max_count = switch (std.Target.current.os.tag) {490 const max_count = switch (builtin.os.tag) {
491 .linux => 0x7ffff000,491 .linux => 0x7ffff000,
492 .macos, .ios, .watchos, .tvos => math.maxInt(i32),492 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
493 else => math.maxInt(isize),493 else => math.maxInt(isize),
...@@ -525,7 +525,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -525,7 +525,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
525/// * Windows525/// * Windows
526/// On these systems, the read races with concurrent writes to the same file descriptor.526/// On these systems, the read races with concurrent writes to the same file descriptor.
527pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {527pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
528 if (std.Target.current.os.tag == .windows) {528 if (builtin.os.tag == .windows) {
529 // TODO improve this to use ReadFileScatter529 // TODO improve this to use ReadFileScatter
530 if (iov.len == 0) return @as(usize, 0);530 if (iov.len == 0) return @as(usize, 0);
531 const first = iov[0];531 const first = iov[0];
...@@ -616,7 +616,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -616,7 +616,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
616 }616 }
617617
618 // Prevent EINVAL.618 // Prevent EINVAL.
619 const max_count = switch (std.Target.current.os.tag) {619 const max_count = switch (builtin.os.tag) {
620 .linux => 0x7ffff000,620 .linux => 0x7ffff000,
621 .macos, .ios, .watchos, .tvos => math.maxInt(i32),621 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
622 else => math.maxInt(isize),622 else => math.maxInt(isize),
...@@ -662,7 +662,7 @@ pub const TruncateError = error{...@@ -662,7 +662,7 @@ pub const TruncateError = error{
662} || UnexpectedError;662} || UnexpectedError;
663663
664pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {664pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
665 if (std.Target.current.os.tag == .windows) {665 if (builtin.os.tag == .windows) {
666 var io_status_block: windows.IO_STATUS_BLOCK = undefined;666 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
667 var eof_info = windows.FILE_END_OF_FILE_INFORMATION{667 var eof_info = windows.FILE_END_OF_FILE_INFORMATION{
668 .EndOfFile = @bitCast(windows.LARGE_INTEGER, length),668 .EndOfFile = @bitCast(windows.LARGE_INTEGER, length),
...@@ -683,7 +683,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -683,7 +683,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
683 else => return windows.unexpectedStatus(rc),683 else => return windows.unexpectedStatus(rc),
684 }684 }
685 }685 }
686 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {686 if (builtin.os.tag == .wasi and !builtin.link_libc) {
687 switch (wasi.fd_filestat_set_size(fd, length)) {687 switch (wasi.fd_filestat_set_size(fd, length)) {
688 .SUCCESS => return,688 .SUCCESS => return,
689 .INTR => unreachable,689 .INTR => unreachable,
...@@ -733,7 +733,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -733,7 +733,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
733/// * Windows733/// * Windows
734/// On these systems, the read races with concurrent writes to the same file descriptor.734/// On these systems, the read races with concurrent writes to the same file descriptor.
735pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {735pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
736 const have_pread_but_not_preadv = switch (std.Target.current.os.tag) {736 const have_pread_but_not_preadv = switch (builtin.os.tag) {
737 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,737 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,
738 else => false,738 else => false,
739 };739 };
...@@ -868,7 +868,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -868,7 +868,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
868 }868 }
869 }869 }
870870
871 const max_count = switch (std.Target.current.os.tag) {871 const max_count = switch (builtin.os.tag) {
872 .linux => 0x7ffff000,872 .linux => 0x7ffff000,
873 .macos, .ios, .watchos, .tvos => math.maxInt(i32),873 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
874 else => math.maxInt(isize),874 else => math.maxInt(isize),
...@@ -916,7 +916,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -916,7 +916,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
916///916///
917/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.917/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.
918pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {918pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
919 if (std.Target.current.os.tag == .windows) {919 if (builtin.os.tag == .windows) {
920 // TODO improve this to use WriteFileScatter920 // TODO improve this to use WriteFileScatter
921 if (iov.len == 0) return @as(usize, 0);921 if (iov.len == 0) return @as(usize, 0);
922 const first = iov[0];922 const first = iov[0];
...@@ -991,7 +991,7 @@ pub const PWriteError = WriteError || error{Unseekable};...@@ -991,7 +991,7 @@ pub const PWriteError = WriteError || error{Unseekable};
991/// The limit on Darwin is `0x7fffffff`, trying to write more than that returns EINVAL.991/// The limit on Darwin is `0x7fffffff`, trying to write more than that returns EINVAL.
992/// The corresponding POSIX limit is `math.maxInt(isize)`.992/// The corresponding POSIX limit is `math.maxInt(isize)`.
993pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {993pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
994 if (std.Target.current.os.tag == .windows) {994 if (builtin.os.tag == .windows) {
995 return windows.WriteFile(fd, bytes, offset, std.io.default_mode);995 return windows.WriteFile(fd, bytes, offset, std.io.default_mode);
996 }996 }
997 if (builtin.os.tag == .wasi and !builtin.link_libc) {997 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 {...@@ -1024,7 +1024,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
1024 }1024 }
10251025
1026 // Prevent EINVAL.1026 // Prevent EINVAL.
1027 const max_count = switch (std.Target.current.os.tag) {1027 const max_count = switch (builtin.os.tag) {
1028 .linux => 0x7ffff000,1028 .linux => 0x7ffff000,
1029 .macos, .ios, .watchos, .tvos => math.maxInt(i32),1029 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
1030 else => math.maxInt(isize),1030 else => math.maxInt(isize),
...@@ -1083,7 +1083,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -1083,7 +1083,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
1083///1083///
1084/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.1084/// If `iov.len` is larger than `IOV_MAX`, a partial write will occur.
1085pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize {1085pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize {
1086 const have_pwrite_but_not_pwritev = switch (std.Target.current.os.tag) {1086 const have_pwrite_but_not_pwritev = switch (builtin.os.tag) {
1087 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,1087 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,
1088 else => false,1088 else => false,
1089 };1089 };
...@@ -1199,7 +1199,7 @@ pub const OpenError = error{...@@ -1199,7 +1199,7 @@ pub const OpenError = error{
1199/// Open and possibly create a file. Keeps trying if it gets interrupted.1199/// Open and possibly create a file. Keeps trying if it gets interrupted.
1200/// See also `openZ`.1200/// See also `openZ`.
1201pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {1201pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {
1202 if (std.Target.current.os.tag == .windows) {1202 if (builtin.os.tag == .windows) {
1203 const file_path_w = try windows.sliceToPrefixedFileW(file_path);1203 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
1204 return openW(file_path_w.span(), flags, perm);1204 return openW(file_path_w.span(), flags, perm);
1205 }1205 }
...@@ -1212,7 +1212,7 @@ pub const openC = @compileError("deprecated: renamed to openZ");...@@ -1212,7 +1212,7 @@ pub const openC = @compileError("deprecated: renamed to openZ");
1212/// Open and possibly create a file. Keeps trying if it gets interrupted.1212/// Open and possibly create a file. Keeps trying if it gets interrupted.
1213/// See also `open`.1213/// See also `open`.
1214pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t {1214pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t {
1215 if (std.Target.current.os.tag == .windows) {1215 if (builtin.os.tag == .windows) {
1216 const file_path_w = try windows.cStrToPrefixedFileW(file_path);1216 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
1217 return openW(file_path_w.span(), flags, perm);1217 return openW(file_path_w.span(), flags, perm);
1218 }1218 }
...@@ -2900,7 +2900,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t...@@ -2900,7 +2900,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
2900 return rc;2900 return rc;
2901 }2901 }
29022902
2903 const have_sock_flags = comptime !std.Target.current.isDarwin();2903 const have_sock_flags = comptime !builtin.target.isDarwin();
2904 const filtered_sock_type = if (!have_sock_flags)2904 const filtered_sock_type = if (!have_sock_flags)
2905 socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)2905 socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
2906 else2906 else
...@@ -3199,7 +3199,7 @@ pub fn accept(...@@ -3199,7 +3199,7 @@ pub fn accept(
3199 /// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful.3199 /// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful.
3200 flags: u32,3200 flags: u32,
3201) AcceptError!socket_t {3201) AcceptError!socket_t {
3202 const have_accept4 = comptime !(std.Target.current.isDarwin() or builtin.os.tag == .windows);3202 const have_accept4 = comptime !(builtin.target.isDarwin() or builtin.os.tag == .windows);
3203 assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)3203 assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
32043204
3205 const accepted_sock = while (true) {3205 const accepted_sock = while (true) {
...@@ -4807,7 +4807,7 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;...@@ -4807,7 +4807,7 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
4807/// TODO: change this to return the timespec as a return value4807/// TODO: change this to return the timespec as a return value
4808/// TODO: look into making clk_id an enum4808/// TODO: look into making clk_id an enum
4809pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {4809pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4810 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {4810 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4811 var ts: timestamp_t = undefined;4811 var ts: timestamp_t = undefined;
4812 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {4812 switch (system.clock_time_get(@bitCast(u32, clk_id), 1, &ts)) {
4813 .SUCCESS => {4813 .SUCCESS => {
...@@ -4821,7 +4821,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4821,7 +4821,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4821 }4821 }
4822 return;4822 return;
4823 }4823 }
4824 if (std.Target.current.os.tag == .windows) {4824 if (builtin.os.tag == .windows) {
4825 if (clk_id == CLOCK.REALTIME) {4825 if (clk_id == CLOCK.REALTIME) {
4826 var ft: windows.FILETIME = undefined;4826 var ft: windows.FILETIME = undefined;
4827 windows.kernel32.GetSystemTimeAsFileTime(&ft);4827 windows.kernel32.GetSystemTimeAsFileTime(&ft);
...@@ -4848,7 +4848,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -4848,7 +4848,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
4848}4848}
48494849
4850pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {4850pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
4851 if (std.Target.current.os.tag == .wasi and !builtin.link_libc) {4851 if (builtin.os.tag == .wasi and !builtin.link_libc) {
4852 var ts: timestamp_t = undefined;4852 var ts: timestamp_t = undefined;
4853 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {4853 switch (system.clock_res_get(@bitCast(u32, clk_id), &ts)) {
4854 .SUCCESS => res.* = .{4854 .SUCCESS => res.* = .{
...@@ -5416,19 +5416,19 @@ pub fn sendfile(...@@ -5416,19 +5416,19 @@ pub fn sendfile(
54165416
5417 // Prevents EOVERFLOW.5417 // Prevents EOVERFLOW.
5418 const size_t = std.meta.Int(.unsigned, @typeInfo(usize).Int.bits - 1);5418 const size_t = std.meta.Int(.unsigned, @typeInfo(usize).Int.bits - 1);
5419 const max_count = switch (std.Target.current.os.tag) {5419 const max_count = switch (builtin.os.tag) {
5420 .linux => 0x7ffff000,5420 .linux => 0x7ffff000,
5421 .macos, .ios, .watchos, .tvos => math.maxInt(i32),5421 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
5422 else => math.maxInt(size_t),5422 else => math.maxInt(size_t),
5423 };5423 };
54245424
5425 switch (std.Target.current.os.tag) {5425 switch (builtin.os.tag) {
5426 .linux => sf: {5426 .linux => sf: {
5427 // sendfile() first appeared in Linux 2.2, glibc 2.1.5427 // sendfile() first appeared in Linux 2.2, glibc 2.1.
5428 const call_sf = comptime if (builtin.link_libc)5428 const call_sf = comptime if (builtin.link_libc)
5429 std.c.versionCheck(.{ .major = 2, .minor = 1 }).ok5429 std.c.versionCheck(.{ .major = 2, .minor = 1 }).ok
5430 else5430 else
5431 std.Target.current.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2 }) != .lt;5431 builtin.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2 }) != .lt;
5432 if (!call_sf) break :sf;5432 if (!call_sf) break :sf;
54335433
5434 if (headers.len != 0) {5434 if (headers.len != 0) {
...@@ -5719,13 +5719,13 @@ var has_copy_file_range_syscall = std.atomic.Atomic(bool).init(true);...@@ -5719,13 +5719,13 @@ var has_copy_file_range_syscall = std.atomic.Atomic(bool).init(true);
5719///5719///
5720/// Maximum offsets on Linux are `math.maxInt(i64)`.5720/// Maximum offsets on Linux are `math.maxInt(i64)`.
5721pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {5721pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
5722 const call_cfr = comptime if (std.Target.current.os.tag == .wasi)5722 const call_cfr = comptime if (builtin.os.tag == .wasi)
5723 // WASI-libc doesn't have copy_file_range.5723 // WASI-libc doesn't have copy_file_range.
5724 false5724 false
5725 else if (builtin.link_libc)5725 else if (builtin.link_libc)
5726 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok5726 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok
5727 else5727 else
5728 std.Target.current.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true;5728 builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse true;
57295729
5730 if (call_cfr and has_copy_file_range_syscall.load(.Monotonic)) {5730 if (call_cfr and has_copy_file_range_syscall.load(.Monotonic)) {
5731 var off_in_copy = @bitCast(i64, off_in);5731 var off_in_copy = @bitCast(i64, off_in);
...@@ -6179,7 +6179,7 @@ pub fn syncfs(fd: fd_t) SyncError!void {...@@ -6179,7 +6179,7 @@ pub fn syncfs(fd: fd_t) SyncError!void {
61796179
6180/// Write all pending file contents and metadata modifications for the specified file descriptor to the underlying filesystem.6180/// Write all pending file contents and metadata modifications for the specified file descriptor to the underlying filesystem.
6181pub fn fsync(fd: fd_t) SyncError!void {6181pub fn fsync(fd: fd_t) SyncError!void {
6182 if (std.Target.current.os.tag == .windows) {6182 if (builtin.os.tag == .windows) {
6183 if (windows.kernel32.FlushFileBuffers(fd) != 0)6183 if (windows.kernel32.FlushFileBuffers(fd) != 0)
6184 return;6184 return;
6185 switch (windows.kernel32.GetLastError()) {6185 switch (windows.kernel32.GetLastError()) {
...@@ -6203,7 +6203,7 @@ pub fn fsync(fd: fd_t) SyncError!void {...@@ -6203,7 +6203,7 @@ pub fn fsync(fd: fd_t) SyncError!void {
62036203
6204/// Write all pending file contents for the specified file descriptor to the underlying filesystem, but not necessarily the metadata.6204/// Write all pending file contents for the specified file descriptor to the underlying filesystem, but not necessarily the metadata.
6205pub fn fdatasync(fd: fd_t) SyncError!void {6205pub fn fdatasync(fd: fd_t) SyncError!void {
6206 if (std.Target.current.os.tag == .windows) {6206 if (builtin.os.tag == .windows) {
6207 return fsync(fd) catch |err| switch (err) {6207 return fsync(fd) catch |err| switch (err) {
6208 SyncError.AccessDenied => return, // fdatasync doesn't promise that the access time was synced6208 SyncError.AccessDenied => return, // fdatasync doesn't promise that the access time was synced
6209 else => return err,6209 else => return err,
lib/std/os/linux.zig+9-8
...@@ -6,12 +6,13 @@...@@ -6,12 +6,13 @@
6//! provide `rename` when only the `renameat` syscall exists.6//! provide `rename` when only the `renameat` syscall exists.
7//! * Does not support POSIX thread cancellation.7//! * Does not support POSIX thread cancellation.
8const std = @import("../std.zig");8const std = @import("../std.zig");
9const builtin = @import("builtin");
9const assert = std.debug.assert;10const assert = std.debug.assert;
10const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
11const elf = std.elf;12const elf = std.elf;
12const vdso = @import("linux/vdso.zig");13const vdso = @import("linux/vdso.zig");
13const dl = @import("../dynamic_library.zig");14const dl = @import("../dynamic_library.zig");
14const native_arch = std.Target.current.cpu.arch;15const native_arch = builtin.cpu.arch;
15const native_endian = native_arch.endian();16const native_endian = native_arch.endian();
16const is_mips = native_arch.isMIPS();17const is_mips = native_arch.isMIPS();
17const is_ppc = native_arch.isPPC();18const is_ppc = native_arch.isPPC();
...@@ -21,7 +22,7 @@ const iovec = std.os.iovec;...@@ -21,7 +22,7 @@ const iovec = std.os.iovec;
21const iovec_const = std.os.iovec_const;22const iovec_const = std.os.iovec_const;
2223
23test {24test {
24 if (std.Target.current.os.tag == .linux) {25 if (builtin.os.tag == .linux) {
25 _ = @import("linux/test.zig");26 _ = @import("linux/test.zig");
26 }27 }
27}28}
...@@ -150,10 +151,10 @@ pub fn getauxval(index: usize) usize {...@@ -150,10 +151,10 @@ pub fn getauxval(index: usize) usize {
150// Some architectures (and some syscalls) require 64bit parameters to be passed151// Some architectures (and some syscalls) require 64bit parameters to be passed
151// in a even-aligned register pair.152// in a even-aligned register pair.
152const require_aligned_register_pair =153const require_aligned_register_pair =
153 std.Target.current.cpu.arch.isPPC() or154 builtin.cpu.arch.isPPC() or
154 std.Target.current.cpu.arch.isMIPS() or155 builtin.cpu.arch.isMIPS() or
155 std.Target.current.cpu.arch.isARM() or156 builtin.cpu.arch.isARM() or
156 std.Target.current.cpu.arch.isThumb();157 builtin.cpu.arch.isThumb();
157158
158// Split a 64bit value into a {LSB,MSB} pair.159// Split a 64bit value into a {LSB,MSB} pair.
159// The LE/BE variants specify the endianness to assume.160// 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,...@@ -1579,7 +1580,7 @@ pub fn process_vm_writev(pid: pid_t, local: [*]const iovec, local_count: usize,
1579}1580}
15801581
1581pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {1582pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
1582 if (comptime std.Target.current.cpu.arch.isMIPS()) {1583 if (comptime builtin.cpu.arch.isMIPS()) {
1583 // MIPS requires a 7 argument syscall1584 // MIPS requires a 7 argument syscall
15841585
1585 const offset_halves = splitValue64(offset);1586 const offset_halves = splitValue64(offset);
...@@ -1595,7 +1596,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {...@@ -1595,7 +1596,7 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
1595 length_halves[1],1596 length_halves[1],
1596 advice,1597 advice,
1597 );1598 );
1598 } else if (comptime std.Target.current.cpu.arch.isARM()) {1599 } else if (comptime builtin.cpu.arch.isARM()) {
1599 // ARM reorders the arguments1600 // ARM reorders the arguments
16001601
1601 const offset_halves = splitValue64(offset);1602 const offset_halves = splitValue64(offset);
lib/std/os/linux/bpf/kern.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../../../std.zig");1const std = @import("../../../std.zig");
2const builtin = @import("builtin");
23
3const in_bpf_program = switch (std.builtin.cpu.arch) {4const in_bpf_program = switch (builtin.cpu.arch) {
4 .bpfel, .bpfeb => true,5 .bpfel, .bpfeb => true,
5 else => false,6 else => false,
6};7};
lib/std/os/linux/io_uring.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const builtin = std.builtin;
4const mem = std.mem;4const mem = std.mem;
5const net = std.net;5const net = std.net;
6const os = std.os;6const os = std.os;
lib/std/os/linux/start_pie.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const elf = std.elf;3const elf = std.elf;
3const builtin = std.builtin;
4const assert = std.debug.assert;4const assert = std.debug.assert;
55
6const R_AMD64_RELATIVE = 8;6const R_AMD64_RELATIVE = 8;
lib/std/os/linux/test.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const linux = std.os.linux;3const linux = std.os.linux;
4const mem = std.mem;4const mem = std.mem;
5const elf = std.elf;5const elf = std.elf;
lib/std/os/linux/tls.zig+1-1
...@@ -4,7 +4,7 @@ const mem = std.mem;...@@ -4,7 +4,7 @@ const mem = std.mem;
4const elf = std.elf;4const elf = std.elf;
5const math = std.math;5const math = std.math;
6const assert = std.debug.assert;6const assert = std.debug.assert;
7const native_arch = std.Target.current.cpu.arch;7const native_arch = @import("builtin").cpu.arch;
88
9// This file implements the two TLS variants [1] used by ELF-based systems.9// This file implements the two TLS variants [1] used by ELF-based systems.
10//10//
lib/std/os/windows/user32.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
34
4const windows = std.os.windows;5const windows = std.os.windows;
...@@ -29,7 +30,7 @@ const HBRUSH = windows.HBRUSH;...@@ -29,7 +30,7 @@ const HBRUSH = windows.HBRUSH;
2930
30fn selectSymbol(comptime function_static: anytype, function_dynamic: @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) @TypeOf(function_static) {31fn selectSymbol(comptime function_static: anytype, function_dynamic: @TypeOf(function_static), comptime os: std.Target.Os.WindowsVersion) @TypeOf(function_static) {
31 comptime {32 comptime {
32 const sym_ok = std.Target.current.os.isAtLeast(.windows, os);33 const sym_ok = builtin.os.isAtLeast(.windows, os);
33 if (sym_ok == true) return function_static;34 if (sym_ok == true) return function_static;
34 if (sym_ok == null) return function_dynamic;35 if (sym_ok == null) return function_dynamic;
35 if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required");36 if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required");
lib/std/pdb.zig-1
...@@ -1,4 +1,3 @@...@@ -1,4 +1,3 @@
1const builtin = std.builtin;
2const std = @import("std.zig");1const std = @import("std.zig");
3const io = std.io;2const io = std.io;
4const math = std.math;3const math = std.math;
lib/std/process.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const os = std.os;3const os = std.os;
4const fs = std.fs;4const fs = std.fs;
5const BufMap = std.BufMap;5const BufMap = std.BufMap;
...@@ -863,9 +863,9 @@ pub fn execve(...@@ -863,9 +863,9 @@ pub fn execve(
863 if (env_map) |m| {863 if (env_map) |m| {
864 const envp_buf = try child_process.createNullDelimitedEnvMap(arena, m);864 const envp_buf = try child_process.createNullDelimitedEnvMap(arena, m);
865 break :m envp_buf.ptr;865 break :m envp_buf.ptr;
866 } else if (std.builtin.link_libc) {866 } else if (builtin.link_libc) {
867 break :m std.c.environ;867 break :m std.c.environ;
868 } else if (std.builtin.output_mode == .Exe) {868 } else if (builtin.output_mode == .Exe) {
869 // Then we have Zig start code and this works.869 // Then we have Zig start code and this works.
870 // TODO type-safety for null-termination of `os.environ`.870 // TODO type-safety for null-termination of `os.environ`.
871 break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr);871 break :m @ptrCast([*:null]?[*:0]u8, os.environ.ptr);
lib/std/rand.zig-1
...@@ -7,7 +7,6 @@...@@ -7,7 +7,6 @@
7//! TODO(tiehuis): Benchmark these against other reference implementations.7//! TODO(tiehuis): Benchmark these against other reference implementations.
88
9const std = @import("std.zig");9const std = @import("std.zig");
10const builtin = std.builtin;
11const assert = std.debug.assert;10const assert = std.debug.assert;
12const expect = std.testing.expect;11const expect = std.testing.expect;
13const expectEqual = std.testing.expectEqual;12const expectEqual = std.testing.expectEqual;
lib/std/rand/ziggurat.zig+11-10
...@@ -1,14 +1,15 @@...@@ -1,14 +1,15 @@
1// Implements ZIGNOR [1].1//! Implements ZIGNOR [1].
2//2//!
3// [1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to Generate Normal Random Samples*]3//! [1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to Generate Normal Random Samples*]
4// (https://www.doornik.com/research/ziggurat.pdf). Nuffield College, Oxford.4//! (https://www.doornik.com/research/ziggurat.pdf). Nuffield College, Oxford.
5//5//!
6// rust/rand used as a reference;6//! rust/rand used as a reference;
7//7//!
8// NOTE: This seems interesting but reference code is a bit hard to grok:8//! NOTE: This seems interesting but reference code is a bit hard to grok:
9// https://sbarral.github.io/etf.9//! https://sbarral.github.io/etf.
1010
11const std = @import("../std.zig");11const std = @import("../std.zig");
12const builtin = @import("builtin");
12const math = std.math;13const math = std.math;
13const Random = std.rand.Random;14const Random = std.rand.Random;
1415
...@@ -126,7 +127,7 @@ fn norm_zero_case(random: *Random, u: f64) f64 {...@@ -126,7 +127,7 @@ fn norm_zero_case(random: *Random, u: f64) f64 {
126 }127 }
127}128}
128129
129const please_windows_dont_oom = std.Target.current.os.tag == .windows;130const please_windows_dont_oom = builtin.os.tag == .windows;
130131
131test "normal dist sanity" {132test "normal dist sanity" {
132 if (please_windows_dont_oom) return error.SkipZigTest;133 if (please_windows_dont_oom) return error.SkipZigTest;
lib/std/sort.zig-1
...@@ -3,7 +3,6 @@ const assert = std.debug.assert;...@@ -3,7 +3,6 @@ const assert = std.debug.assert;
3const testing = std.testing;3const testing = std.testing;
4const mem = std.mem;4const mem = std.mem;
5const math = std.math;5const math = std.math;
6const builtin = std.builtin;
76
8pub fn binarySearch(7pub fn binarySearch(
9 comptime T: type,8 comptime T: type,
lib/std/special/compiler_rt.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
4const os_tag = std.Target.current.os.tag;4const os_tag = builtin.os.tag;
5const arch = builtin.stage2_arch;5const arch = builtin.stage2_arch;
6const abi = std.Target.current.abi;6const abi = builtin.abi;
77
8const is_gnu = abi.isGnu();8const is_gnu = abi.isGnu();
9const is_mingw = os_tag == .windows and is_gnu;9const is_mingw = os_tag == .windows and is_gnu;
lib/std/special/compiler_rt/atomics.zig+5-5
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const arch = std.Target.current.cpu.arch;3const arch = builtin.cpu.arch;
44
5const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
66
7// This parameter is true iff the target architecture supports the bare minimum7// This parameter is true iff the target architecture supports the bare minimum
8// to implement the atomic load/store intrinsics.8// to implement the atomic load/store intrinsics.
...@@ -16,7 +16,7 @@ const supports_atomic_ops = switch (arch) {...@@ -16,7 +16,7 @@ const supports_atomic_ops = switch (arch) {
16 // operations (unless we're targeting Linux, the kernel provides a way to16 // operations (unless we're targeting Linux, the kernel provides a way to
17 // perform CAS operations).17 // perform CAS operations).
18 // XXX: The Linux code path is not implemented yet.18 // XXX: The Linux code path is not implemented yet.
19 !std.Target.arm.featureSetHas(std.Target.current.cpu.features, .has_v6m),19 !std.Target.arm.featureSetHas(builtin.cpu.features, .has_v6m),
20 else => true,20 else => true,
21};21};
2222
...@@ -257,7 +257,7 @@ comptime {...@@ -257,7 +257,7 @@ comptime {
257 }257 }
258}258}
259259
260fn fetchFn(comptime T: type, comptime op: builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T {260fn fetchFn(comptime T: type, comptime op: std.builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T {
261 return struct {261 return struct {
262 pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T {262 pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T {
263 _ = model;263 _ = model;
lib/std/special/compiler_rt/clear_cache.zig+4-3
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const arch = std.builtin.cpu.arch;2const builtin = @import("builtin");
3const os = std.builtin.os.tag;3const arch = builtin.cpu.arch;
4const os = builtin.os.tag;
45
5// Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c286// Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28
67
...@@ -156,7 +157,7 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {...@@ -156,7 +157,7 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
156 }157 }
157}158}
158159
159const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;160const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;
160161
161fn exportIt() void {162fn exportIt() void {
162 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });163 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
lib/std/special/compiler_rt/count0bits.zig+8-8
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
33
4// clz - count leading zeroes4// clz - count leading zeroes
5// - clzXi2_generic for little endian5// - clzXi2_generic for little endian
...@@ -118,18 +118,18 @@ fn __clzsi2_arm32() callconv(.Naked) void {...@@ -118,18 +118,18 @@ fn __clzsi2_arm32() callconv(.Naked) void {
118}118}
119119
120pub const __clzsi2 = impl: {120pub const __clzsi2 = impl: {
121 switch (std.Target.current.cpu.arch) {121 switch (builtin.cpu.arch) {
122 .arm, .armeb, .thumb, .thumbeb => {122 .arm, .armeb, .thumb, .thumbeb => {
123 const use_thumb1 =123 const use_thumb1 =
124 (std.Target.current.cpu.arch.isThumb() or124 (builtin.cpu.arch.isThumb() or
125 std.Target.arm.featureSetHas(std.Target.current.cpu.features, .noarm)) and125 std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and
126 !std.Target.arm.featureSetHas(std.Target.current.cpu.features, .thumb2);126 !std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2);
127127
128 if (use_thumb1) {128 if (use_thumb1) {
129 break :impl __clzsi2_thumb1;129 break :impl __clzsi2_thumb1;
130 }130 }
131 // From here on we're either targeting Thumb2 or ARM.131 // From here on we're either targeting Thumb2 or ARM.
132 else if (!std.Target.current.cpu.arch.isThumb()) {132 else if (!builtin.cpu.arch.isThumb()) {
133 break :impl __clzsi2_arm32;133 break :impl __clzsi2_arm32;
134 }134 }
135 // Use the generic implementation otherwise.135 // Use the generic implementation otherwise.
...@@ -140,14 +140,14 @@ pub const __clzsi2 = impl: {...@@ -140,14 +140,14 @@ pub const __clzsi2 = impl: {
140};140};
141141
142pub const __clzdi2 = impl: {142pub const __clzdi2 = impl: {
143 switch (std.Target.current.cpu.arch) {143 switch (builtin.cpu.arch) {
144 // TODO architecture optimised versions144 // TODO architecture optimised versions
145 else => break :impl clzXi2_generic(i64),145 else => break :impl clzXi2_generic(i64),
146 }146 }
147};147};
148148
149pub const __clzti2 = impl: {149pub const __clzti2 = impl: {
150 switch (std.Target.current.cpu.arch) {150 switch (builtin.cpu.arch) {
151 // TODO architecture optimised versions151 // TODO architecture optimised versions
152 else => break :impl clzXi2_generic(i128),152 else => break :impl clzXi2_generic(i128),
153 }153 }
lib/std/special/compiler_rt/emutls.zig+2-1
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5//5//
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
89
9const abort = std.os.abort;10const abort = std.os.abort;
10const assert = std.debug.assert;11const assert = std.debug.assert;
...@@ -15,7 +16,7 @@ const expect = std.testing.expect;...@@ -15,7 +16,7 @@ const expect = std.testing.expect;
15const gcc_word = usize;16const gcc_word = usize;
1617
17comptime {18comptime {
18 assert(std.builtin.link_libc);19 assert(builtin.link_libc);
19}20}
2021
21/// public entrypoint for generated code using EmulatedTLS22/// public entrypoint for generated code using EmulatedTLS
lib/std/special/compiler_rt/muldi3.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const is_test = std.builtin.is_test;2const builtin = @import("builtin");
3const native_endian = std.Target.current.cpu.arch.endian();3const is_test = builtin.is_test;
4const native_endian = builtin.cpu.arch.endian();
45
5// Ported from6// Ported from
6// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c7// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
lib/std/special/compiler_rt/multi3.zig+3-2
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1const compiler_rt = @import("../compiler_rt.zig");1const compiler_rt = @import("../compiler_rt.zig");
2const std = @import("std");2const std = @import("std");
3const is_test = std.builtin.is_test;3const builtin = @import("builtin");
4const native_endian = std.Target.current.cpu.arch.endian();4const is_test = builtin.is_test;
5const native_endian = builtin.cpu.arch.endian();
56
6// Ported from git@github.com:llvm-project/llvm-project-20170507.git7// Ported from git@github.com:llvm-project/llvm-project-20170507.git
7// ae684fad6d34858c014c94da69c15e7774a633c38// ae684fad6d34858c014c94da69c15e7774a633c3
lib/std/special/compiler_rt/shift.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const Log2Int = std.math.Log2Int;2const Log2Int = std.math.Log2Int;
3const native_endian = std.Target.current.cpu.arch.endian();3const native_endian = @import("builtin").cpu.arch.endian();
44
5fn Dwords(comptime T: type, comptime signed_half: bool) type {5fn Dwords(comptime T: type, comptime signed_half: bool) type {
6 return extern union {6 return extern union {
lib/std/special/compiler_rt/stack_probe.zig+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const native_arch = @import("std").Target.current.cpu.arch;1const native_arch = @import("builtin").cpu.arch;
22
3// Zig's own stack-probe routine (available only on x86 and x86_64)3// Zig's own stack-probe routine (available only on x86 and x86_64)
4pub fn zig_probe_stack() callconv(.Naked) void {4pub fn zig_probe_stack() callconv(.Naked) void {
lib/std/special/compiler_rt/udivmod.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const native_endian = @import("std").Target.current.cpu.arch.endian();3const native_endian = builtin.cpu.arch.endian();
44
5const low = switch (native_endian) {5const low = switch (native_endian) {
6 .Big => 1,6 .Big => 1,
lib/std/special/ssp.zig+15-16
...@@ -1,19 +1,18 @@...@@ -1,19 +1,18 @@
1//1//!
2// Small Zig reimplementation of gcc's libssp.2//! Small Zig reimplementation of gcc's libssp.
3//3//!
4// This library implements most of the builtins required by the stack smashing4//! This library implements most of the builtins required by the stack smashing
5// protection as implemented by gcc&clang.5//! protection as implemented by gcc&clang.
6const std = @import("std");6//! Missing exports:
7const builtin = std.builtin;7//! - __gets_chk
8//! - __mempcpy_chk
9//! - __snprintf_chk
10//! - __sprintf_chk
11//! - __stpcpy_chk
12//! - __vsnprintf_chk
13//! - __vsprintf_chk
814
9// Missing exports:15const std = @import("std");
10// - __gets_chk
11// - __mempcpy_chk
12// - __snprintf_chk
13// - __sprintf_chk
14// - __stpcpy_chk
15// - __vsnprintf_chk
16// - __vsprintf_chk
1716
18extern fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8;17extern fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8;
19extern fn memset(dest: ?[*]u8, c: u8, n: usize) callconv(.C) ?[*]u8;18extern 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...@@ -21,7 +20,7 @@ extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) call
21extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8;20extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8;
2221
23// Avoid dragging in the runtime safety mechanisms into this .o file.22// Avoid dragging in the runtime safety mechanisms into this .o file.
24pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {23pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
25 _ = msg;24 _ = msg;
26 _ = error_return_trace;25 _ = error_return_trace;
27 @setCold(true);26 @setCold(true);
lib/std/std.zig+1-1
...@@ -95,7 +95,7 @@ comptime {...@@ -95,7 +95,7 @@ comptime {
95}95}
9696
97test {97test {
98 if (builtin.os.tag == .windows) {98 if (@import("builtin").os.tag == .windows) {
99 // We only test the Windows-relevant stuff to save memory because the CI99 // We only test the Windows-relevant stuff to save memory because the CI
100 // server is hitting OOM. TODO revert this after stage2 arrives.100 // server is hitting OOM. TODO revert this after stage2 arrives.
101 _ = ChildProcess;101 _ = ChildProcess;
lib/std/target.zig+3-3
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const mem = std.mem;2const mem = std.mem;
3const builtin = std.builtin;
4const Version = std.builtin.Version;3const Version = std.builtin.Version;
54
6/// TODO Nearly all the functions in this namespace would be5/// TODO Nearly all the functions in this namespace would be
...@@ -1017,7 +1016,7 @@ pub const Target = struct {...@@ -1017,7 +1016,7 @@ pub const Target = struct {
1017 };1016 };
1018 }1017 }
10191018
1020 pub fn endian(arch: Arch) builtin.Endian {1019 pub fn endian(arch: Arch) std.builtin.Endian {
1021 return switch (arch) {1020 return switch (arch) {
1022 .avr,1021 .avr,
1023 .arm,1022 .arm,
...@@ -1302,7 +1301,8 @@ pub const Target = struct {...@@ -1302,7 +1301,8 @@ pub const Target = struct {
1302 }1301 }
1303 };1302 };
13041303
1305 pub const current = builtin.target;1304 /// TODO delete this deprecated declaration after 0.9.0 is released
1305 pub const current = @compileError("instead of std.Target.current, use @import(\"builtin\").target");
13061306
1307 pub const stack_align = 16;1307 pub const stack_align = 16;
13081308
lib/std/testing.zig+3-2
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");
23
3const math = std.math;4const math = std.math;
4const print = std.debug.print;5const print = std.debug.print;
...@@ -322,7 +323,7 @@ pub const TmpDir = struct {...@@ -322,7 +323,7 @@ pub const TmpDir = struct {
322};323};
323324
324fn getCwdOrWasiPreopen() std.fs.Dir {325fn getCwdOrWasiPreopen() std.fs.Dir {
325 if (std.builtin.os.tag == .wasi and !std.builtin.link_libc) {326 if (builtin.os.tag == .wasi and !builtin.link_libc) {
326 var preopens = std.fs.wasi.PreopenList.init(allocator);327 var preopens = std.fs.wasi.PreopenList.init(allocator);
327 defer preopens.deinit();328 defer preopens.deinit();
328 preopens.populate() catch329 preopens.populate() catch
...@@ -464,7 +465,7 @@ test {...@@ -464,7 +465,7 @@ test {
464465
465/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.466/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.
466pub fn refAllDecls(comptime T: type) void {467pub fn refAllDecls(comptime T: type) void {
467 if (!std.builtin.is_test) return;468 if (!builtin.is_test) return;
468 inline for (std.meta.declarations(T)) |decl| {469 inline for (std.meta.declarations(T)) |decl| {
469 _ = decl;470 _ = decl;
470 }471 }
lib/std/time.zig+5-5
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;4const testing = std.testing;
5const os = std.os;5const os = std.os;
6const math = std.math;6const math = std.math;
7const is_windows = std.Target.current.os.tag == .windows;7const is_windows = builtin.os.tag == .windows;
88
9pub const epoch = @import("time/epoch.zig");9pub const epoch = @import("time/epoch.zig");
1010
...@@ -173,7 +173,7 @@ pub const Timer = struct {...@@ -173,7 +173,7 @@ pub const Timer = struct {
173 .resolution = @divFloor(ns_per_s, freq),173 .resolution = @divFloor(ns_per_s, freq),
174 .start_time = os.windows.QueryPerformanceCounter(),174 .start_time = os.windows.QueryPerformanceCounter(),
175 };175 };
176 } else if (comptime std.Target.current.isDarwin()) {176 } else if (comptime builtin.target.isDarwin()) {
177 var freq: os.darwin.mach_timebase_info_data = undefined;177 var freq: os.darwin.mach_timebase_info_data = undefined;
178 os.darwin.mach_timebase_info(&freq);178 os.darwin.mach_timebase_info(&freq);
179179
...@@ -225,7 +225,7 @@ pub const Timer = struct {...@@ -225,7 +225,7 @@ pub const Timer = struct {
225 if (is_windows) {225 if (is_windows) {
226 return os.windows.QueryPerformanceCounter();226 return os.windows.QueryPerformanceCounter();
227 }227 }
228 if (comptime std.Target.current.isDarwin()) {228 if (comptime builtin.target.isDarwin()) {
229 return os.darwin.mach_absolute_time();229 return os.darwin.mach_absolute_time();
230 }230 }
231 var ts: os.timespec = undefined;231 var ts: os.timespec = undefined;
...@@ -237,7 +237,7 @@ pub const Timer = struct {...@@ -237,7 +237,7 @@ pub const Timer = struct {
237 if (is_windows) {237 if (is_windows) {
238 return safeMulDiv(duration, ns_per_s, self.frequency);238 return safeMulDiv(duration, ns_per_s, self.frequency);
239 }239 }
240 if (comptime std.Target.current.isDarwin()) {240 if (comptime builtin.target.isDarwin()) {
241 return safeMulDiv(duration, self.frequency.numer, self.frequency.denom);241 return safeMulDiv(duration, self.frequency.numer, self.frequency.denom);
242 }242 }
243 return duration;243 return duration;
lib/std/unicode.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("./std.zig");1const std = @import("./std.zig");
2const builtin = std.builtin;
3const assert = std.debug.assert;2const assert = std.debug.assert;
4const testing = std.testing;3const testing = std.testing;
5const mem = std.mem;4const mem = std.mem;
lib/std/unicode/throughput_test.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const time = std.time;2const time = std.time;
4const unicode = std.unicode;3const unicode = std.unicode;
54
lib/std/x/net/tcp.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
23
3const io = std.io;4const io = std.io;
4const os = std.os;5const os = std.os;
...@@ -7,7 +8,7 @@ const ip = std.x.net.ip;...@@ -7,7 +8,7 @@ const ip = std.x.net.ip;
7const fmt = std.fmt;8const fmt = std.fmt;
8const mem = std.mem;9const mem = std.mem;
9const testing = std.testing;10const testing = std.testing;
10const native_os = std.Target.current.os;11const native_os = builtin.os;
1112
12const IPv4 = std.x.os.IPv4;13const IPv4 = std.x.os.IPv4;
13const IPv6 = std.x.os.IPv6;14const IPv6 = std.x.os.IPv6;
lib/std/x/os/io.zig+2-1
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
23
3const os = std.os;4const os = std.os;
4const mem = std.mem;5const mem = std.mem;
5const testing = std.testing;6const testing = std.testing;
6const native_os = std.Target.current.os;7const native_os = builtin.os;
7const linux = std.os.linux;8const linux = std.os.linux;
89
9/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering10/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering
lib/std/x/os/net.zig+2-1
...@@ -1,11 +1,12 @@...@@ -1,11 +1,12 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
23
3const os = std.os;4const os = std.os;
4const fmt = std.fmt;5const fmt = std.fmt;
5const mem = std.mem;6const mem = std.mem;
6const math = std.math;7const math = std.math;
7const testing = std.testing;8const testing = std.testing;
8const native_os = std.Target.current.os;9const native_os = builtin.os;
9const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");10const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");
1011
11/// Resolves a network interface name into a scope/zone ID. It returns12/// Resolves a network interface name into a scope/zone ID. It returns
lib/std/x/os/socket.zig+3-2
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
2const net = @import("net.zig");3const net = @import("net.zig");
34
4const os = std.os;5const os = std.os;
...@@ -6,8 +7,8 @@ const fmt = std.fmt;...@@ -6,8 +7,8 @@ const fmt = std.fmt;
6const mem = std.mem;7const mem = std.mem;
7const time = std.time;8const time = std.time;
8const meta = std.meta;9const meta = std.meta;
9const native_os = std.Target.current.os;10const native_os = builtin.os;
10const native_endian = std.Target.current.cpu.arch.endian();11const native_endian = builtin.cpu.arch.endian();
1112
12const Buffer = std.x.os.Buffer;13const Buffer = std.x.os.Buffer;
1314
lib/std/zig/cross_target.zig+13-12
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const Target = std.Target;4const Target = std.Target;
4const mem = std.mem;5const mem = std.mem;
...@@ -329,7 +330,7 @@ pub const CrossTarget = struct {...@@ -329,7 +330,7 @@ pub const CrossTarget = struct {
329 // This works when doing `zig build` because Zig generates a build executable using330 // This works when doing `zig build` because Zig generates a build executable using
330 // native CPU model & features. However this will not be accurate otherwise, and331 // native CPU model & features. However this will not be accurate otherwise, and
331 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.332 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
332 return Target.current.cpu;333 return builtin.cpu;
333 },334 },
334 .baseline => {335 .baseline => {
335 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());336 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
...@@ -340,7 +341,7 @@ pub const CrossTarget = struct {...@@ -340,7 +341,7 @@ pub const CrossTarget = struct {
340 // This works when doing `zig build` because Zig generates a build executable using341 // This works when doing `zig build` because Zig generates a build executable using
341 // native CPU model & features. However this will not be accurate otherwise, and342 // native CPU model & features. However this will not be accurate otherwise, and
342 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.343 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
343 return Target.current.cpu;344 return builtin.cpu;
344 } else {345 } else {
345 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());346 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
346 self.updateCpuFeatures(&adjusted_baseline.features);347 self.updateCpuFeatures(&adjusted_baseline.features);
...@@ -355,7 +356,7 @@ pub const CrossTarget = struct {...@@ -355,7 +356,7 @@ pub const CrossTarget = struct {
355 }356 }
356357
357 pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch {358 pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch {
358 return self.cpu_arch orelse Target.current.cpu.arch;359 return self.cpu_arch orelse builtin.cpu.arch;
359 }360 }
360361
361 pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model {362 pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model {
...@@ -371,10 +372,10 @@ pub const CrossTarget = struct {...@@ -371,10 +372,10 @@ pub const CrossTarget = struct {
371372
372 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.373 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
373 pub fn getOs(self: CrossTarget) Target.Os {374 pub fn getOs(self: CrossTarget) Target.Os {
374 // `Target.current.os` works when doing `zig build` because Zig generates a build executable using375 // `builtin.os` works when doing `zig build` because Zig generates a build executable using
375 // native OS version range. However this will not be accurate otherwise, and376 // native OS version range. However this will not be accurate otherwise, and
376 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.377 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
377 var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange() else Target.current.os;378 var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange() else builtin.os;
378379
379 if (self.os_version_min) |min| switch (min) {380 if (self.os_version_min) |min| switch (min) {
380 .none => {},381 .none => {},
...@@ -403,7 +404,7 @@ pub const CrossTarget = struct {...@@ -403,7 +404,7 @@ pub const CrossTarget = struct {
403 }404 }
404405
405 pub fn getOsTag(self: CrossTarget) Target.Os.Tag {406 pub fn getOsTag(self: CrossTarget) Target.Os.Tag {
406 return self.os_tag orelse Target.current.os.tag;407 return self.os_tag orelse builtin.os.tag;
407 }408 }
408409
409 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.410 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
...@@ -430,7 +431,7 @@ pub const CrossTarget = struct {...@@ -430,7 +431,7 @@ pub const CrossTarget = struct {
430 // This works when doing `zig build` because Zig generates a build executable using431 // This works when doing `zig build` because Zig generates a build executable using
431 // native CPU model & features. However this will not be accurate otherwise, and432 // native CPU model & features. However this will not be accurate otherwise, and
432 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.433 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
433 return Target.current.abi;434 return builtin.abi;
434 }435 }
435436
436 return Target.Abi.default(self.getCpuArch(), self.getOs());437 return Target.Abi.default(self.getCpuArch(), self.getOs());
...@@ -607,12 +608,12 @@ pub const CrossTarget = struct {...@@ -607,12 +608,12 @@ pub const CrossTarget = struct {
607 pub fn getExternalExecutor(self: CrossTarget) Executor {608 pub fn getExternalExecutor(self: CrossTarget) Executor {
608 const cpu_arch = self.getCpuArch();609 const cpu_arch = self.getCpuArch();
609 const os_tag = self.getOsTag();610 const os_tag = self.getOsTag();
610 const os_match = os_tag == Target.current.os.tag;611 const os_match = os_tag == builtin.os.tag;
611612
612 // If the OS and CPU arch match, the binary can be considered native.613 // If the OS and CPU arch match, the binary can be considered native.
613 // TODO additionally match the CPU features. This `getExternalExecutor` function should614 // TODO additionally match the CPU features. This `getExternalExecutor` function should
614 // be moved to std.Target and match any chosen target against the native target.615 // be moved to std.Target and match any chosen target against the native target.
615 if (os_match and cpu_arch == Target.current.cpu.arch) {616 if (os_match and cpu_arch == builtin.cpu.arch) {
616 // However, we also need to verify that the dynamic linker path is valid.617 // However, we also need to verify that the dynamic linker path is valid.
617 if (self.os_tag == null) {618 if (self.os_tag == null) {
618 return .native;619 return .native;
...@@ -664,7 +665,7 @@ pub const CrossTarget = struct {...@@ -664,7 +665,7 @@ pub const CrossTarget = struct {
664 // TODO loosen this check once upstream adds QEMU-based emulation665 // TODO loosen this check once upstream adds QEMU-based emulation
665 // layer for non-host architectures:666 // layer for non-host architectures:
666 // https://github.com/darlinghq/darling/issues/863667 // https://github.com/darlinghq/darling/issues/863
667 if (cpu_arch != Target.current.cpu.arch) {668 if (cpu_arch != builtin.cpu.arch) {
668 return .unavailable;669 return .unavailable;
669 }670 }
670 return Executor{ .darling = "darling" };671 return Executor{ .darling = "darling" };
...@@ -789,7 +790,7 @@ pub const CrossTarget = struct {...@@ -789,7 +790,7 @@ pub const CrossTarget = struct {
789};790};
790791
791test "CrossTarget.parse" {792test "CrossTarget.parse" {
792 if (Target.current.isGnuLibC()) {793 if (builtin.target.isGnuLibC()) {
793 var cross_target = try CrossTarget.parse(.{});794 var cross_target = try CrossTarget.parse(.{});
794 cross_target.setGnuLibCVersion(2, 1, 1);795 cross_target.setGnuLibCVersion(2, 1, 1);
795796
...@@ -800,7 +801,7 @@ test "CrossTarget.parse" {...@@ -800,7 +801,7 @@ test "CrossTarget.parse" {
800 const triple = std.fmt.bufPrint(801 const triple = std.fmt.bufPrint(
801 buf[0..],802 buf[0..],
802 "native-native-{s}.2.1.1",803 "native-native-{s}.2.1.1",
803 .{@tagName(std.Target.current.abi)},804 .{@tagName(builtin.abi)},
804 ) catch unreachable;805 ) catch unreachable;
805806
806 try std.testing.expectEqualSlices(u8, triple, text);807 try std.testing.expectEqualSlices(u8, triple, text);
lib/std/zig/system.zig+14-13
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const elf = std.elf;3const elf = std.elf;
3const mem = std.mem;4const mem = std.mem;
4const fs = std.fs;5const fs = std.fs;
...@@ -8,7 +9,7 @@ const assert = std.debug.assert;...@@ -8,7 +9,7 @@ const assert = std.debug.assert;
8const process = std.process;9const process = std.process;
9const Target = std.Target;10const Target = std.Target;
10const CrossTarget = std.zig.CrossTarget;11const CrossTarget = std.zig.CrossTarget;
11const native_endian = std.Target.current.cpu.arch.endian();12const native_endian = builtin.cpu.arch.endian();
12const linux = @import("system/linux.zig");13const linux = @import("system/linux.zig");
13pub const windows = @import("system/windows.zig");14pub const windows = @import("system/windows.zig");
14pub const darwin = @import("system/darwin.zig");15pub const darwin = @import("system/darwin.zig");
...@@ -88,7 +89,7 @@ pub const NativePaths = struct {...@@ -88,7 +89,7 @@ pub const NativePaths = struct {
88 return self;89 return self;
89 }90 }
9091
91 if (comptime Target.current.isDarwin()) {92 if (comptime builtin.target.isDarwin()) {
92 try self.addIncludeDir("/usr/include");93 try self.addIncludeDir("/usr/include");
93 try self.addIncludeDir("/usr/local/include");94 try self.addIncludeDir("/usr/local/include");
9495
...@@ -239,7 +240,7 @@ pub const NativeTargetInfo = struct {...@@ -239,7 +240,7 @@ pub const NativeTargetInfo = struct {
239 pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {240 pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
240 var os = cross_target.getOsTag().defaultVersionRange();241 var os = cross_target.getOsTag().defaultVersionRange();
241 if (cross_target.os_tag == null) {242 if (cross_target.os_tag == null) {
242 switch (Target.current.os.tag) {243 switch (builtin.target.os.tag) {
243 .linux => {244 .linux => {
244 const uts = std.os.uname();245 const uts = std.os.uname();
245 const release = mem.spanZ(&uts.release);246 const release = mem.spanZ(&uts.release);
...@@ -273,7 +274,7 @@ pub const NativeTargetInfo = struct {...@@ -273,7 +274,7 @@ pub const NativeTargetInfo = struct {
273 },274 },
274 .macos => try darwin.macos.detect(&os),275 .macos => try darwin.macos.detect(&os),
275 .freebsd, .netbsd, .dragonfly => {276 .freebsd, .netbsd, .dragonfly => {
276 const key = switch (Target.current.os.tag) {277 const key = switch (builtin.target.os.tag) {
277 .freebsd => "kern.osreldate",278 .freebsd => "kern.osreldate",
278 .netbsd, .dragonfly => "kern.osrevision",279 .netbsd, .dragonfly => "kern.osrevision",
279 else => unreachable,280 else => unreachable,
...@@ -289,7 +290,7 @@ pub const NativeTargetInfo = struct {...@@ -289,7 +290,7 @@ pub const NativeTargetInfo = struct {
289 error.Unexpected => return error.OSVersionDetectionFail,290 error.Unexpected => return error.OSVersionDetectionFail,
290 };291 };
291292
292 switch (Target.current.os.tag) {293 switch (builtin.target.os.tag) {
293 .freebsd => {294 .freebsd => {
294 // https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html295 // https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html
295 // Major * 100,000 has been convention since FreeBSD 2.2 (1997)296 // Major * 100,000 has been convention since FreeBSD 2.2 (1997)
...@@ -445,8 +446,8 @@ pub const NativeTargetInfo = struct {...@@ -445,8 +446,8 @@ pub const NativeTargetInfo = struct {
445 os: Target.Os,446 os: Target.Os,
446 cross_target: CrossTarget,447 cross_target: CrossTarget,
447 ) DetectError!NativeTargetInfo {448 ) DetectError!NativeTargetInfo {
448 const native_target_has_ld = comptime Target.current.hasDynamicLinker();449 const native_target_has_ld = comptime builtin.target.hasDynamicLinker();
449 const is_linux = Target.current.os.tag == .linux;450 const is_linux = builtin.target.os.tag == .linux;
450 const have_all_info = cross_target.dynamic_linker.get() != null and451 const have_all_info = cross_target.dynamic_linker.get() != null and
451 cross_target.abi != null and (!is_linux or cross_target.abi.?.isGnu());452 cross_target.abi != null and (!is_linux or cross_target.abi.?.isGnu());
452 const os_is_non_native = cross_target.os_tag != null;453 const os_is_non_native = cross_target.os_tag != null;
...@@ -463,7 +464,7 @@ pub const NativeTargetInfo = struct {...@@ -463,7 +464,7 @@ pub const NativeTargetInfo = struct {
463 // compiler for target riscv64-linux-musl and provide a tarball for users to download.464 // compiler for target riscv64-linux-musl and provide a tarball for users to download.
464 // A user could then run that zig compiler on riscv64-linux-gnu. This use case is well-defined465 // A user could then run that zig compiler on riscv64-linux-gnu. This use case is well-defined
465 // and supported by Zig. But that means that we must detect the system ABI here rather than466 // and supported by Zig. But that means that we must detect the system ABI here rather than
466 // relying on `Target.current`.467 // relying on `builtin.target`.
467 const all_abis = comptime blk: {468 const all_abis = comptime blk: {
468 assert(@enumToInt(Target.Abi.none) == 0);469 assert(@enumToInt(Target.Abi.none) == 0);
469 const fields = std.meta.fields(Target.Abi)[1..];470 const fields = std.meta.fields(Target.Abi)[1..];
...@@ -524,7 +525,7 @@ pub const NativeTargetInfo = struct {...@@ -524,7 +525,7 @@ pub const NativeTargetInfo = struct {
524525
525 // Look for glibc version.526 // Look for glibc version.
526 var os_adjusted = os;527 var os_adjusted = os;
527 if (Target.current.os.tag == .linux and found_ld_info.abi.isGnu() and528 if (builtin.target.os.tag == .linux and found_ld_info.abi.isGnu() and
528 cross_target.glibc_version == null)529 cross_target.glibc_version == null)
529 {530 {
530 for (lib_paths) |lib_path| {531 for (lib_paths) |lib_path| {
...@@ -740,7 +741,7 @@ pub const NativeTargetInfo = struct {...@@ -740,7 +741,7 @@ pub const NativeTargetInfo = struct {
740 }741 }
741 },742 },
742 // We only need this for detecting glibc version.743 // We only need this for detecting glibc version.
743 elf.PT_DYNAMIC => if (Target.current.os.tag == .linux and result.target.isGnuLibC() and744 elf.PT_DYNAMIC => if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and
744 cross_target.glibc_version == null)745 cross_target.glibc_version == null)
745 {746 {
746 var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);747 var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
...@@ -787,7 +788,7 @@ pub const NativeTargetInfo = struct {...@@ -787,7 +788,7 @@ pub const NativeTargetInfo = struct {
787 }788 }
788 }789 }
789790
790 if (Target.current.os.tag == .linux and result.target.isGnuLibC() and cross_target.glibc_version == null) {791 if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and cross_target.glibc_version == null) {
791 if (rpath_offset) |rpoff| {792 if (rpath_offset) |rpoff| {
792 const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx);793 const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx);
793794
...@@ -979,14 +980,14 @@ pub const NativeTargetInfo = struct {...@@ -979,14 +980,14 @@ pub const NativeTargetInfo = struct {
979 // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,980 // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,
980 // although it is a runtime value, is guaranteed to be one of the architectures in the set981 // although it is a runtime value, is guaranteed to be one of the architectures in the set
981 // of the respective switch prong.982 // of the respective switch prong.
982 switch (std.Target.current.cpu.arch) {983 switch (builtin.cpu.arch) {
983 .x86_64, .i386 => {984 .x86_64, .i386 => {
984 return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, cross_target);985 return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, cross_target);
985 },986 },
986 else => {},987 else => {},
987 }988 }
988989
989 switch (std.Target.current.os.tag) {990 switch (builtin.os.tag) {
990 .linux => return linux.detectNativeCpuAndFeatures(),991 .linux => return linux.detectNativeCpuAndFeatures(),
991 .macos => return darwin.macos.detectNativeCpuAndFeatures(),992 .macos => return darwin.macos.detectNativeCpuAndFeatures(),
992 else => {},993 else => {},
lib/std/zig/system/darwin/macos.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const mem = std.mem;4const mem = std.mem;
4const testing = std.testing;5const testing = std.testing;
...@@ -414,7 +415,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {...@@ -414,7 +415,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
414 error.Unexpected => unreachable, // EFAULT: stack should be safe, EISDIR/ENOTDIR: constant, known good value415 error.Unexpected => unreachable, // EFAULT: stack should be safe, EISDIR/ENOTDIR: constant, known good value
415 };416 };
416417
417 const current_arch = Target.current.cpu.arch;418 const current_arch = builtin.cpu.arch;
418 switch (current_arch) {419 switch (current_arch) {
419 .aarch64, .aarch64_be, .aarch64_32 => {420 .aarch64, .aarch64_be, .aarch64_32 => {
420 const model = switch (cpu_family) {421 const model = switch (cpu_family) {
lib/std/zig/system/linux.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const mem = std.mem;3const mem = std.mem;
3const io = std.io;4const io = std.io;
4const fs = std.fs;5const fs = std.fs;
...@@ -450,7 +451,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {...@@ -450,7 +451,7 @@ pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
450 };451 };
451 defer f.close();452 defer f.close();
452453
453 const current_arch = std.Target.current.cpu.arch;454 const current_arch = builtin.cpu.arch;
454 switch (current_arch) {455 switch (current_arch) {
455 .arm, .armeb, .thumb, .thumbeb, .aarch64, .aarch64_be, .aarch64_32 => {456 .arm, .armeb, .thumb, .thumbeb, .aarch64, .aarch64_be, .aarch64_32 => {
456 return ArmCpuinfoParser.parse(current_arch, f.reader()) catch null;457 return ArmCpuinfoParser.parse(current_arch, f.reader()) catch null;
src/Air.zig+2-1
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
4//! gets its own `Air` instance.4//! gets its own `Air` instance.
55
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");
7const Value = @import("value.zig").Value;8const Value = @import("value.zig").Value;
8const Type = @import("type.zig").Type;9const Type = @import("type.zig").Type;
9const Module = @import("Module.zig");10const Module = @import("Module.zig");
...@@ -484,7 +485,7 @@ pub const Inst = struct {...@@ -484,7 +485,7 @@ pub const Inst = struct {
484 // bigger than expected. Note that in Debug builds, Zig is allowed485 // bigger than expected. Note that in Debug builds, Zig is allowed
485 // to insert a secret field for safety checks.486 // to insert a secret field for safety checks.
486 comptime {487 comptime {
487 if (std.builtin.mode != .Debug) {488 if (builtin.mode != .Debug) {
488 assert(@sizeOf(Data) == 8);489 assert(@sizeOf(Data) == 8);
489 }490 }
490 }491 }
src/Cache.zig+7-6
...@@ -4,6 +4,7 @@ hash: HashHelper = .{},...@@ -4,6 +4,7 @@ hash: HashHelper = .{},
44
5const Cache = @This();5const Cache = @This();
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");
7const crypto = std.crypto;8const crypto = std.crypto;
8const fs = std.fs;9const fs = std.fs;
9const assert = std.debug.assert;10const assert = std.debug.assert;
...@@ -713,7 +714,7 @@ pub const Manifest = struct {...@@ -713,7 +714,7 @@ pub const Manifest = struct {
713/// uses the file contents. Windows supports symlinks but only with elevated privileges, so714/// uses the file contents. Windows supports symlinks but only with elevated privileges, so
714/// it is treated as not supporting symlinks.715/// it is treated as not supporting symlinks.
715pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {716pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
716 if (std.Target.current.os.tag == .windows) {717 if (builtin.os.tag == .windows) {
717 return dir.readFile(sub_path, buffer);718 return dir.readFile(sub_path, buffer);
718 } else {719 } else {
719 return dir.readLink(sub_path, buffer);720 return dir.readLink(sub_path, buffer);
...@@ -726,7 +727,7 @@ pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {...@@ -726,7 +727,7 @@ pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
726/// `data` must be a valid UTF-8 encoded file path and 255 bytes or fewer.727/// `data` must be a valid UTF-8 encoded file path and 255 bytes or fewer.
727pub fn writeSmallFile(dir: fs.Dir, sub_path: []const u8, data: []const u8) !void {728pub fn writeSmallFile(dir: fs.Dir, sub_path: []const u8, data: []const u8) !void {
728 assert(data.len <= 255);729 assert(data.len <= 255);
729 if (std.Target.current.os.tag == .windows) {730 if (builtin.os.tag == .windows) {
730 return dir.writeFile(sub_path, data);731 return dir.writeFile(sub_path, data);
731 } else {732 } else {
732 return dir.symLink(data, sub_path, .{});733 return dir.symLink(data, sub_path, .{});
...@@ -778,7 +779,7 @@ fn isProblematicTimestamp(fs_clock: i128) bool {...@@ -778,7 +779,7 @@ fn isProblematicTimestamp(fs_clock: i128) bool {
778}779}
779780
780test "cache file and then recall it" {781test "cache file and then recall it" {
781 if (std.Target.current.os.tag == .wasi) {782 if (builtin.os.tag == .wasi) {
782 // https://github.com/ziglang/zig/issues/5437783 // https://github.com/ziglang/zig/issues/5437
783 return error.SkipZigTest;784 return error.SkipZigTest;
784 }785 }
...@@ -856,7 +857,7 @@ test "give nonproblematic timestamp" {...@@ -856,7 +857,7 @@ test "give nonproblematic timestamp" {
856}857}
857858
858test "check that changing a file makes cache fail" {859test "check that changing a file makes cache fail" {
859 if (std.Target.current.os.tag == .wasi) {860 if (builtin.os.tag == .wasi) {
860 // https://github.com/ziglang/zig/issues/5437861 // https://github.com/ziglang/zig/issues/5437
861 return error.SkipZigTest;862 return error.SkipZigTest;
862 }863 }
...@@ -932,7 +933,7 @@ test "check that changing a file makes cache fail" {...@@ -932,7 +933,7 @@ test "check that changing a file makes cache fail" {
932}933}
933934
934test "no file inputs" {935test "no file inputs" {
935 if (std.Target.current.os.tag == .wasi) {936 if (builtin.os.tag == .wasi) {
936 // https://github.com/ziglang/zig/issues/5437937 // https://github.com/ziglang/zig/issues/5437
937 return error.SkipZigTest;938 return error.SkipZigTest;
938 }939 }
...@@ -977,7 +978,7 @@ test "no file inputs" {...@@ -977,7 +978,7 @@ test "no file inputs" {
977}978}
978979
979test "Manifest with files added after initial hash work" {980test "Manifest with files added after initial hash work" {
980 if (std.Target.current.os.tag == .wasi) {981 if (builtin.os.tag == .wasi) {
981 // https://github.com/ziglang/zig/issues/5437982 // https://github.com/ziglang/zig/issues/5437
982 return error.SkipZigTest;983 return error.SkipZigTest;
983 }984 }
src/Compilation.zig+3-3
...@@ -937,8 +937,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -937,8 +937,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
937 };937 };
938938
939 const darwin_can_use_system_sdk = blk: {939 const darwin_can_use_system_sdk = blk: {
940 if (comptime !std.Target.current.isDarwin()) break :blk false;940 if (comptime !builtin.target.isDarwin()) break :blk false;
941 break :blk std.builtin.os.tag == .macos and options.target.isDarwin();941 break :blk builtin.os.tag == .macos and options.target.isDarwin();
942 };942 };
943943
944 const sysroot = blk: {944 const sysroot = blk: {
...@@ -3582,7 +3582,7 @@ fn detectLibCIncludeDirs(...@@ -3582,7 +3582,7 @@ fn detectLibCIncludeDirs(
3582 // native abi, fall back to using the system libc installation.3582 // native abi, fall back to using the system libc installation.
3583 // On windows, instead of the native (mingw) abi, we want to check3583 // On windows, instead of the native (mingw) abi, we want to check
3584 // for the MSVC abi as a fallback.3584 // for the MSVC abi as a fallback.
3585 const use_system_abi = if (std.Target.current.os.tag == .windows)3585 const use_system_abi = if (builtin.target.os.tag == .windows)
3586 target.abi == .msvc3586 target.abi == .msvc
3587 else3587 else
3588 is_native_abi;3588 is_native_abi;
src/ThreadPool.zig+3-2
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");
7const ThreadPool = @This();8const ThreadPool = @This();
89
9lock: std.Thread.Mutex = .{},10lock: std.Thread.Mutex = .{},
...@@ -57,7 +58,7 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void {...@@ -57,7 +58,7 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void {
57 .allocator = allocator,58 .allocator = allocator,
58 .workers = &[_]Worker{},59 .workers = &[_]Worker{},
59 };60 };
60 if (std.builtin.single_threaded)61 if (builtin.single_threaded)
61 return;62 return;
6263
63 const worker_count = std.math.max(1, std.Thread.getCpuCount() catch 1);64 const worker_count = std.math.max(1, std.Thread.getCpuCount() catch 1);
...@@ -100,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void {...@@ -100,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void {
100}101}
101102
102pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {103pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
103 if (std.builtin.single_threaded) {104 if (builtin.single_threaded) {
104 @call(.{}, func, args);105 @call(.{}, func, args);
105 return;106 return;
106 }107 }
src/Zir.zig+2-1
...@@ -11,6 +11,7 @@...@@ -11,6 +11,7 @@
11//! inline assembly is not an exception.11//! inline assembly is not an exception.
1212
13const std = @import("std");13const std = @import("std");
14const builtin = @import("builtin");
14const mem = std.mem;15const mem = std.mem;
15const Allocator = std.mem.Allocator;16const Allocator = std.mem.Allocator;
16const assert = std.debug.assert;17const assert = std.debug.assert;
...@@ -2215,7 +2216,7 @@ pub const Inst = struct {...@@ -2215,7 +2216,7 @@ pub const Inst = struct {
2215 // bigger than expected. Note that in Debug builds, Zig is allowed2216 // bigger than expected. Note that in Debug builds, Zig is allowed
2216 // to insert a secret field for safety checks.2217 // to insert a secret field for safety checks.
2217 comptime {2218 comptime {
2218 if (std.builtin.mode != .Debug) {2219 if (builtin.mode != .Debug) {
2219 assert(@sizeOf(Data) == 8);2220 assert(@sizeOf(Data) == 8);
2220 }2221 }
2221 }2222 }
src/codegen.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const mem = std.mem;3const mem = std.mem;
3const math = std.math;4const math = std.math;
4const assert = std.debug.assert;5const assert = std.debug.assert;
...@@ -522,7 +523,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -522,7 +523,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
522 code: *std.ArrayList(u8),523 code: *std.ArrayList(u8),
523 debug_output: DebugInfoOutput,524 debug_output: DebugInfoOutput,
524 ) GenerateSymbolError!FnResult {525 ) GenerateSymbolError!FnResult {
525 if (build_options.skip_non_native and std.Target.current.cpu.arch != arch) {526 if (build_options.skip_non_native and builtin.cpu.arch != arch) {
526 @panic("Attempted to compile for architecture that was disabled by build configuration");527 @panic("Attempted to compile for architecture that was disabled by build configuration");
527 }528 }
528529
src/codegen/c.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const mem = std.mem;4const mem = std.mem;
4const log = std.log.scoped(.c);5const log = std.log.scoped(.c);
...@@ -600,7 +601,7 @@ pub const DeclGen = struct {...@@ -600,7 +601,7 @@ pub const DeclGen = struct {
600 );601 );
601 },602 },
602 .ErrorSet => {603 .ErrorSet => {
603 comptime std.debug.assert(Type.initTag(.anyerror).abiSize(std.Target.current) == 2);604 comptime std.debug.assert(Type.initTag(.anyerror).abiSize(builtin.target) == 2);
604 try w.writeAll("uint16_t");605 try w.writeAll("uint16_t");
605 },606 },
606 .ErrorUnion => {607 .ErrorUnion => {
src/introspect.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const mem = std.mem;3const mem = std.mem;
3const fs = std.fs;4const fs = std.fs;
4const Compilation = @import("Compilation.zig");5const Compilation = @import("Compilation.zig");
...@@ -71,7 +72,7 @@ pub fn resolveGlobalCacheDir(allocator: *mem.Allocator) ![]u8 {...@@ -71,7 +72,7 @@ pub fn resolveGlobalCacheDir(allocator: *mem.Allocator) ![]u8 {
7172
72 const appname = "zig";73 const appname = "zig";
7374
74 if (std.Target.current.os.tag != .windows) {75 if (builtin.os.tag != .windows) {
75 if (std.os.getenv("XDG_CACHE_HOME")) |cache_root| {76 if (std.os.getenv("XDG_CACHE_HOME")) |cache_root| {
76 return fs.path.join(allocator, &[_][]const u8{ cache_root, appname });77 return fs.path.join(allocator, &[_][]const u8{ cache_root, appname });
77 } else if (std.os.getenv("HOME")) |home| {78 } else if (std.os.getenv("HOME")) |home| {
src/libc_installation.zig+4-4
...@@ -6,9 +6,9 @@ const Allocator = std.mem.Allocator;...@@ -6,9 +6,9 @@ const Allocator = std.mem.Allocator;
6const Batch = std.event.Batch;6const Batch = std.event.Batch;
7const build_options = @import("build_options");7const build_options = @import("build_options");
88
9const is_darwin = Target.current.isDarwin();9const is_darwin = builtin.target.isDarwin();
10const is_windows = Target.current.os.tag == .windows;10const is_windows = builtin.target.os.tag == .windows;
11const is_haiku = Target.current.os.tag == .haiku;11const is_haiku = builtin.target.os.tag == .haiku;
1212
13const log = std.log.scoped(.libc_installation);13const log = std.log.scoped(.libc_installation);
1414
...@@ -219,7 +219,7 @@ pub const LibCInstallation = struct {...@@ -219,7 +219,7 @@ pub const LibCInstallation = struct {
219 var batch = Batch(FindError!void, 2, .auto_async).init();219 var batch = Batch(FindError!void, 2, .auto_async).init();
220 errdefer batch.wait() catch {};220 errdefer batch.wait() catch {};
221 batch.add(&async self.findNativeIncludeDirPosix(args));221 batch.add(&async self.findNativeIncludeDirPosix(args));
222 switch (Target.current.os.tag) {222 switch (builtin.target.os.tag) {
223 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),223 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),
224 .solaris => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib/64"),224 .solaris => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib/64"),
225 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),225 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),
src/link.zig+2-2
...@@ -292,7 +292,7 @@ pub const File = struct {...@@ -292,7 +292,7 @@ pub const File = struct {
292 // make executable, so we don't have to close it.292 // make executable, so we don't have to close it.
293 return;293 return;
294 }294 }
295 if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64) {295 if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) {
296 if (base.options.target.cpu.arch != .aarch64) return; // If we're not targeting aarch64, nothing to do.296 if (base.options.target.cpu.arch != .aarch64) return; // If we're not targeting aarch64, nothing to do.
297 // XNU starting with Big Sur running on arm64 is caching inodes of running binaries.297 // XNU starting with Big Sur running on arm64 is caching inodes of running binaries.
298 // Any change to the binary will effectively invalidate the kernel's cache298 // Any change to the binary will effectively invalidate the kernel's cache
...@@ -711,7 +711,7 @@ pub fn determineMode(options: Options) fs.File.Mode {...@@ -711,7 +711,7 @@ pub fn determineMode(options: Options) fs.File.Mode {
711 // with 0o755 permissions, but it works appropriately if the system is configured711 // with 0o755 permissions, but it works appropriately if the system is configured
712 // more leniently. As another data point, C's fopen seems to open files with the712 // more leniently. As another data point, C's fopen seems to open files with the
713 // 666 mode.713 // 666 mode.
714 const executable_mode = if (std.Target.current.os.tag == .windows) 0 else 0o777;714 const executable_mode = if (builtin.target.os.tag == .windows) 0 else 0o777;
715 switch (options.effectiveOutputMode()) {715 switch (options.effectiveOutputMode()) {
716 .Lib => return switch (options.link_mode) {716 .Lib => return switch (options.link_mode) {
717 .Dynamic => executable_mode,717 .Dynamic => executable_mode,
src/link/Elf.zig+5-5
...@@ -755,7 +755,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {...@@ -755,7 +755,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
755 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;755 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;
756756
757 const target_endian = self.base.options.target.cpu.arch.endian();757 const target_endian = self.base.options.target.cpu.arch.endian();
758 const foreign_endian = target_endian != std.Target.current.cpu.arch.endian();758 const foreign_endian = target_endian != builtin.cpu.arch.endian();
759 const ptr_width_bytes: u8 = self.ptrWidthBytes();759 const ptr_width_bytes: u8 = self.ptrWidthBytes();
760 const init_len_size: usize = switch (self.ptr_width) {760 const init_len_size: usize = switch (self.ptr_width) {
761 .p32 => 4,761 .p32 => 4,
...@@ -2827,7 +2827,7 @@ pub fn deleteExport(self: *Elf, exp: Export) void {...@@ -2827,7 +2827,7 @@ pub fn deleteExport(self: *Elf, exp: Export) void {
2827}2827}
28282828
2829fn writeProgHeader(self: *Elf, index: usize) !void {2829fn writeProgHeader(self: *Elf, index: usize) !void {
2830 const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian();2830 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
2831 const offset = self.program_headers.items[index].p_offset;2831 const offset = self.program_headers.items[index].p_offset;
2832 switch (self.ptr_width) {2832 switch (self.ptr_width) {
2833 .p32 => {2833 .p32 => {
...@@ -2848,7 +2848,7 @@ fn writeProgHeader(self: *Elf, index: usize) !void {...@@ -2848,7 +2848,7 @@ fn writeProgHeader(self: *Elf, index: usize) !void {
2848}2848}
28492849
2850fn writeSectHeader(self: *Elf, index: usize) !void {2850fn writeSectHeader(self: *Elf, index: usize) !void {
2851 const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian();2851 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
2852 switch (self.ptr_width) {2852 switch (self.ptr_width) {
2853 .p32 => {2853 .p32 => {
2854 var shdr: [1]elf.Elf32_Shdr = undefined;2854 var shdr: [1]elf.Elf32_Shdr = undefined;
...@@ -2946,7 +2946,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {...@@ -2946,7 +2946,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {
2946 syms_sect.sh_size = needed_size; // anticipating adding the global symbols later2946 syms_sect.sh_size = needed_size; // anticipating adding the global symbols later
2947 self.shdr_table_dirty = true; // TODO look into only writing one section2947 self.shdr_table_dirty = true; // TODO look into only writing one section
2948 }2948 }
2949 const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian();2949 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
2950 switch (self.ptr_width) {2950 switch (self.ptr_width) {
2951 .p32 => {2951 .p32 => {
2952 var sym = [1]elf.Elf32_Sym{2952 var sym = [1]elf.Elf32_Sym{
...@@ -2982,7 +2982,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void {...@@ -2982,7 +2982,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void {
2982 .p32 => @sizeOf(elf.Elf32_Sym),2982 .p32 => @sizeOf(elf.Elf32_Sym),
2983 .p64 => @sizeOf(elf.Elf64_Sym),2983 .p64 => @sizeOf(elf.Elf64_Sym),
2984 };2984 };
2985 const foreign_endian = self.base.options.target.cpu.arch.endian() != std.Target.current.cpu.arch.endian();2985 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
2986 const global_syms_off = syms_sect.sh_offset + self.local_symbols.items.len * sym_size;2986 const global_syms_off = syms_sect.sh_offset + self.local_symbols.items.len * sym_size;
2987 switch (self.ptr_width) {2987 switch (self.ptr_width) {
2988 .p32 => {2988 .p32 => {
src/link/MachO.zig+1-1
...@@ -967,7 +967,7 @@ fn resolveSearchDir(...@@ -967,7 +967,7 @@ fn resolveSearchDir(
967967
968 if (fs.path.isAbsolute(dir)) {968 if (fs.path.isAbsolute(dir)) {
969 if (syslibroot) |root| {969 if (syslibroot) |root| {
970 const common_dir = if (std.Target.current.os.tag == .windows) blk: {970 const common_dir = if (builtin.os.tag == .windows) blk: {
971 // We need to check for disk designator and strip it out from dir path so971 // We need to check for disk designator and strip it out from dir path so
972 // that we can concat dir with syslibroot.972 // that we can concat dir with syslibroot.
973 // TODO we should backport this mechanism to 'MachO.Dylib.parseDependentLibs()'973 // TODO we should backport this mechanism to 'MachO.Dylib.parseDependentLibs()'
src/link/MachO/fat.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const log = std.log.scoped(.archive);3const log = std.log.scoped(.archive);
4const macho = std.macho;4const macho = std.macho;
5const mem = std.mem;5const mem = std.mem;
...@@ -23,7 +23,7 @@ fn readFatStruct(reader: anytype, comptime T: type) !T {...@@ -23,7 +23,7 @@ fn readFatStruct(reader: anytype, comptime T: type) !T {
23 // Fat structures (fat_header & fat_arch) are always written and read to/from23 // Fat structures (fat_header & fat_arch) are always written and read to/from
24 // disk in big endian order.24 // disk in big endian order.
25 var res = try reader.readStruct(T);25 var res = try reader.readStruct(T);
26 if (native_endian != builtin.Endian.Big) {26 if (native_endian != std.builtin.Endian.Big) {
27 mem.bswapAllFields(T, &res);27 mem.bswapAllFields(T, &res);
28 }28 }
29 return res;29 return res;
src/main.zig+10-9
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const io = std.io;4const io = std.io;
4const fs = std.fs;5const fs = std.fs;
...@@ -34,7 +35,7 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn {...@@ -34,7 +35,7 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn {
34/// be byte-indexed with a u32 integer.35/// be byte-indexed with a u32 integer.
35pub const max_src_size = std.math.maxInt(u32);36pub const max_src_size = std.math.maxInt(u32);
3637
37pub const debug_extensions_enabled = std.builtin.mode == .Debug;38pub const debug_extensions_enabled = builtin.mode == .Debug;
3839
39pub const Color = enum {40pub const Color = enum {
40 auto,41 auto,
...@@ -90,7 +91,7 @@ const debug_usage = normal_usage ++...@@ -90,7 +91,7 @@ const debug_usage = normal_usage ++
9091
91const usage = if (debug_extensions_enabled) debug_usage else normal_usage;92const usage = if (debug_extensions_enabled) debug_usage else normal_usage;
9293
93pub const log_level: std.log.Level = switch (std.builtin.mode) {94pub const log_level: std.log.Level = switch (builtin.mode) {
94 .Debug => .debug,95 .Debug => .debug,
95 .ReleaseSafe, .ReleaseFast => .info,96 .ReleaseSafe, .ReleaseFast => .info,
96 .ReleaseSmall => .crit,97 .ReleaseSmall => .crit,
...@@ -142,7 +143,7 @@ pub fn main() anyerror!void {...@@ -142,7 +143,7 @@ pub fn main() anyerror!void {
142143
143 var gpa_need_deinit = false;144 var gpa_need_deinit = false;
144 const gpa = gpa: {145 const gpa = gpa: {
145 if (!std.builtin.link_libc) {146 if (!builtin.link_libc) {
146 gpa_need_deinit = true;147 gpa_need_deinit = true;
147 break :gpa &general_purpose_allocator.allocator;148 break :gpa &general_purpose_allocator.allocator;
148 }149 }
...@@ -1688,13 +1689,13 @@ fn buildOutputType(...@@ -1688,13 +1689,13 @@ fn buildOutputType(
1688 }1689 }
1689 }1690 }
16901691
1691 if (comptime std.Target.current.isDarwin()) {1692 if (comptime builtin.target.isDarwin()) {
1692 // If we want to link against frameworks, we need system headers.1693 // If we want to link against frameworks, we need system headers.
1693 if (framework_dirs.items.len > 0 or frameworks.items.len > 0)1694 if (framework_dirs.items.len > 0 or frameworks.items.len > 0)
1694 want_native_include_dirs = true;1695 want_native_include_dirs = true;
1695 }1696 }
16961697
1697 const is_darwin_on_darwin = (comptime std.Target.current.isDarwin()) and cross_target.isDarwin();1698 const is_darwin_on_darwin = (comptime builtin.target.isDarwin()) and cross_target.isDarwin();
16981699
1699 if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and1700 if (sysroot == null and (cross_target.isNativeOs() or is_darwin_on_darwin) and
1700 (system_libs.items.len != 0 or want_native_include_dirs))1701 (system_libs.items.len != 0 or want_native_include_dirs))
...@@ -1706,7 +1707,7 @@ fn buildOutputType(...@@ -1706,7 +1707,7 @@ fn buildOutputType(
1706 warn("{s}", .{warning});1707 warn("{s}", .{warning});
1707 }1708 }
17081709
1709 const has_sysroot = if (comptime std.Target.current.isDarwin()) outer: {1710 const has_sysroot = if (comptime builtin.target.isDarwin()) outer: {
1710 const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: {1711 const should_get_sdk_path = if (cross_target.isNativeOs() and target_info.target.os.tag == .macos) inner: {
1711 const min = target_info.target.os.getVersionRange().semver.min;1712 const min = target_info.target.os.getVersionRange().semver.min;
1712 const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);1713 const at_least_mojave = min.major >= 11 or (min.major >= 10 and min.minor >= 14);
...@@ -2355,7 +2356,7 @@ fn runOrTest(...@@ -2355,7 +2356,7 @@ fn runOrTest(
2355 defer argv.deinit();2356 defer argv.deinit();
23562357
2357 if (test_exec_args.len == 0) {2358 if (test_exec_args.len == 0) {
2358 if (!std.Target.current.canExecBinariesOf(target)) {2359 if (!builtin.target.canExecBinariesOf(target)) {
2359 switch (arg_mode) {2360 switch (arg_mode) {
2360 .zig_test => {2361 .zig_test => {
2361 warn("created {s} but skipping execution because it is non-native", .{exe_path});2362 warn("created {s} but skipping execution because it is non-native", .{exe_path});
...@@ -3915,7 +3916,7 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {...@@ -3915,7 +3916,7 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
3915 const posix = std.os;3916 const posix = std.os;
39163917
3917 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.3918 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
3918 if (comptime std.Target.current.isDarwin()) {3919 if (comptime builtin.target.isDarwin()) {
3919 // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.3920 // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
3920 // According to the man pages for setrlimit():3921 // According to the man pages for setrlimit():
3921 // setrlimit() now returns with errno set to EINVAL in places that historically succeeded.3922 // 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...@@ -3959,7 +3960,7 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s
3959/// check for resource leaks can be accurate. In release builds, this3960/// check for resource leaks can be accurate. In release builds, this
3960/// calls exit(0), and does not return.3961/// calls exit(0), and does not return.
3961pub fn cleanExit() void {3962pub fn cleanExit() void {
3962 if (std.builtin.mode == .Debug) {3963 if (builtin.mode == .Debug) {
3963 return;3964 return;
3964 } else {3965 } else {
3965 process.exit(0);3966 process.exit(0);
src/tracy.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
23
3pub const enable = if (std.builtin.is_test) false else @import("build_options").enable_tracy;4pub const enable = if (builtin.is_test) false else @import("build_options").enable_tracy;
45
5extern fn ___tracy_emit_zone_begin_callstack(6extern fn ___tracy_emit_zone_begin_callstack(
6 srcloc: *const ___tracy_source_location_data,7 srcloc: *const ___tracy_source_location_data,
test/assemble_and_link.zig+2-1
...@@ -1,8 +1,9 @@...@@ -1,8 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const tests = @import("tests.zig");3const tests = @import("tests.zig");
34
4pub fn addCases(cases: *tests.CompareOutputContext) void {5pub fn addCases(cases: *tests.CompareOutputContext) void {
5 if (std.Target.current.os.tag == .linux and std.Target.current.cpu.arch == .x86_64) {6 if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64) {
6 cases.addAsm("hello world linux x86_64",7 cases.addAsm("hello world linux x86_64",
7 \\.text8 \\.text
8 \\.globl _start9 \\.globl _start
test/behavior/asm.zig+2-1
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const expect = std.testing.expect;3const expect = std.testing.expect;
34
4const is_x86_64_linux = std.Target.current.cpu.arch == .x86_64 and std.Target.current.os.tag == .linux;5const is_x86_64_linux = builtin.cpu.arch == .x86_64 and builtin.os.tag == .linux;
56
6comptime {7comptime {
7 if (is_x86_64_linux) {8 if (is_x86_64_linux) {
test/behavior/atomics.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const expect = std.testing.expect;3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;4const expectEqual = std.testing.expectEqual;
4const builtin = @import("builtin");
55
6test "cmpxchg" {6test "cmpxchg" {
7 try testCmpxchg();7 try testCmpxchg();
test/behavior/namespace_depends_on_compile_var.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const expect = std.testing.expect;3const expect = std.testing.expect;
34
4test "namespace depends on compile var" {5test "namespace depends on compile var" {
...@@ -8,7 +9,7 @@ test "namespace depends on compile var" {...@@ -8,7 +9,7 @@ test "namespace depends on compile var" {
8 try expect(!some_namespace.a_bool);9 try expect(!some_namespace.a_bool);
9 }10 }
10}11}
11const some_namespace = switch (std.builtin.os.tag) {12const some_namespace = switch (builtin.os.tag) {
12 .linux => @import("namespace_depends_on_compile_var/a.zig"),13 .linux => @import("namespace_depends_on_compile_var/a.zig"),
13 else => @import("namespace_depends_on_compile_var/b.zig"),14 else => @import("namespace_depends_on_compile_var/b.zig"),
14};15};
test/behavior/sizeof_and_typeof.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const expect = std.testing.expect;2const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;3const expectEqual = std.testing.expectEqual;
54
test/behavior/sizeof_and_typeof_stage1.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;
3const expect = std.testing.expect;2const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;3const expectEqual = std.testing.expectEqual;
54
test/behavior/vector.zig+1-1
...@@ -674,7 +674,7 @@ test "saturating subtraction" {...@@ -674,7 +674,7 @@ test "saturating subtraction" {
674674
675test "saturating multiplication" {675test "saturating multiplication" {
676 // TODO: once #9660 has been solved, remove this line676 // TODO: once #9660 has been solved, remove this line
677 if (std.builtin.target.cpu.arch == .wasm32) return error.SkipZigTest;677 if (builtin.target.cpu.arch == .wasm32) return error.SkipZigTest;
678678
679 const S = struct {679 const S = struct {
680 fn doTheTest() !void {680 fn doTheTest() !void {
test/cli.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const testing = std.testing;3const testing = std.testing;
3const process = std.process;4const process = std.process;
4const fs = std.fs;5const fs = std.fs;
...@@ -97,7 +98,7 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {...@@ -97,7 +98,7 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
97}98}
9899
99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {100fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100 if (std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64) return;101 if (builtin.os.tag != .linux or builtin.cpu.arch != .x86_64) return;
101102
102 const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });103 const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });104 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
test/compare_output.zig+4-2
...@@ -28,7 +28,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -28,7 +28,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
2828
29 cases.addC("number literals",29 cases.addC("number literals",
30 \\const std = @import("std");30 \\const std = @import("std");
31 \\const is_windows = std.Target.current.os.tag == .windows;31 \\const builtin = @import("builtin");
32 \\const is_windows = builtin.os.tag == .windows;
32 \\const c = @cImport({33 \\const c = @cImport({
33 \\ if (is_windows) {34 \\ if (is_windows) {
34 \\ // See https://github.com/ziglang/zig/issues/51535 \\ // See https://github.com/ziglang/zig/issues/515
...@@ -207,7 +208,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -207,7 +208,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
207208
208 cases.addC("casting between float and integer types",209 cases.addC("casting between float and integer types",
209 \\const std = @import("std");210 \\const std = @import("std");
210 \\const is_windows = std.Target.current.os.tag == .windows;211 \\const builtin = @import("builtin");
212 \\const is_windows = builtin.os.tag == .windows;
211 \\const c = @cImport({213 \\const c = @cImport({
212 \\ if (is_windows) {214 \\ if (is_windows) {
213 \\ // See https://github.com/ziglang/zig/issues/515215 \\ // See https://github.com/ziglang/zig/issues/515
test/compile_errors.zig+4-2
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const TestContext = @import("../src/test.zig").TestContext;3const TestContext = @import("../src/test.zig").TestContext;
34
4pub fn addCases(ctx: *TestContext) !void {5pub fn addCases(ctx: *TestContext) !void {
...@@ -2898,7 +2899,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -2898,7 +2899,7 @@ pub fn addCases(ctx: *TestContext) !void {
2898 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",2899 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
2899 });2900 });
29002901
2901 if (std.Target.current.os.tag == .linux) {2902 if (builtin.os.tag == .linux) {
2902 ctx.testErrStage1("implicit dependency on libc",2903 ctx.testErrStage1("implicit dependency on libc",
2903 \\extern "c" fn exit(u8) void;2904 \\extern "c" fn exit(u8) void;
2904 \\export fn entry() void {2905 \\export fn entry() void {
...@@ -8834,9 +8835,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -8834,9 +8835,10 @@ pub fn addCases(ctx: *TestContext) !void {
88348835
8835 ctx.objErrStage1("Issue #9165: windows tcp server compilation error",8836 ctx.objErrStage1("Issue #9165: windows tcp server compilation error",
8836 \\const std = @import("std");8837 \\const std = @import("std");
8838 \\const builtin = @import("builtin");
8837 \\pub const io_mode = .evented;8839 \\pub const io_mode = .evented;
8838 \\pub fn main() !void {8840 \\pub fn main() !void {
8839 \\ if (std.builtin.os.tag == .windows) {8841 \\ if (builtin.os.tag == .windows) {
8840 \\ _ = try (std.net.StreamServer.init(.{})).accept();8842 \\ _ = try (std.net.StreamServer.init(.{})).accept();
8841 \\ } else {8843 \\ } else {
8842 \\ @compileError("Unsupported OS");8844 \\ @compileError("Unsupported OS");
test/src/compare_output.zig+1-2
...@@ -1,14 +1,13 @@...@@ -1,14 +1,13 @@
1// This is the implementation of the test harness.1// This is the implementation of the test harness.
2// For the actual test cases, see test/compare_output.zig.2// For the actual test cases, see test/compare_output.zig.
3const std = @import("std");3const std = @import("std");
4const builtin = std.builtin;
5const build = std.build;4const build = std.build;
6const ArrayList = std.ArrayList;5const ArrayList = std.ArrayList;
7const fmt = std.fmt;6const fmt = std.fmt;
8const mem = std.mem;7const mem = std.mem;
9const fs = std.fs;8const fs = std.fs;
10const warn = std.debug.warn;9const warn = std.debug.warn;
11const Mode = builtin.Mode;10const Mode = std.builtin.Mode;
1211
13pub const CompareOutputContext = struct {12pub const CompareOutputContext = struct {
14 b: *build.Builder,13 b: *build.Builder,
test/standalone.zig+5-4
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const tests = @import("tests.zig");3const tests = @import("tests.zig");
34
4pub fn addCases(cases: *tests.StandaloneContext) void {5pub fn addCases(cases: *tests.StandaloneContext) void {
...@@ -29,19 +30,19 @@ pub fn addCases(cases: *tests.StandaloneContext) void {...@@ -29,19 +30,19 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
29 cases.addBuildFile("test/standalone/issue_7030/build.zig", .{});30 cases.addBuildFile("test/standalone/issue_7030/build.zig", .{});
30 cases.addBuildFile("test/standalone/install_raw_hex/build.zig", .{});31 cases.addBuildFile("test/standalone/install_raw_hex/build.zig", .{});
31 cases.addBuildFile("test/standalone/issue_9812/build.zig", .{});32 cases.addBuildFile("test/standalone/issue_9812/build.zig", .{});
32 if (std.Target.current.os.tag != .wasi) {33 if (builtin.os.tag != .wasi) {
33 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{});34 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{});
34 }35 }
35 if (std.Target.current.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures36 if (builtin.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures
36 cases.addBuildFile("test/stage1/c_abi/build.zig", .{});37 cases.addBuildFile("test/stage1/c_abi/build.zig", .{});
37 }38 }
38 cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true });39 cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true });
3940
40 if (std.Target.current.os.tag == .windows) {41 if (builtin.os.tag == .windows) {
41 cases.addC("test/standalone/issue_9402/main.zig");42 cases.addC("test/standalone/issue_9402/main.zig");
42 }43 }
43 // Try to build and run a PIE executable.44 // Try to build and run a PIE executable.
44 if (std.Target.current.os.tag == .linux) {45 if (builtin.os.tag == .linux) {
45 cases.addBuildFile("test/standalone/pie/build.zig", .{});46 cases.addBuildFile("test/standalone/pie/build.zig", .{});
46 }47 }
47 // Try to build and run an Objective-C executable.48 // Try to build and run an Objective-C executable.
test/standalone/c_compiler/build.zig+3-2
...@@ -1,12 +1,13 @@...@@ -1,12 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const Builder = std.build.Builder;3const Builder = std.build.Builder;
3const CrossTarget = std.zig.CrossTarget;4const CrossTarget = std.zig.CrossTarget;
45
5fn isRunnableTarget(t: CrossTarget) bool {6fn isRunnableTarget(t: CrossTarget) bool {
6 if (t.isNative()) return true;7 if (t.isNative()) return true;
78
8 return (t.getOsTag() == std.Target.current.os.tag and9 return (t.getOsTag() == builtin.os.tag and
9 t.getCpuArch() == std.Target.current.cpu.arch);10 t.getCpuArch() == builtin.cpu.arch);
10}11}
1112
12pub fn build(b: *Builder) void {13pub fn build(b: *Builder) void {
test/standalone/install_raw_hex/build.zig+107-113
...@@ -28,14 +28,14 @@ pub fn build(b: *Builder) void {...@@ -28,14 +28,14 @@ pub fn build(b: *Builder) void {
2828
29 const expected_hex = &[_][]const u8{29 const expected_hex = &[_][]const u8{
30 ":020000021000EC",30 ":020000021000EC",
31 ":1000D400D001010001000000D20101000100000074",31 ":1000D400A401010001000000A601010001000000CC",
32 ":1000E40028020100010000002402010001000000B8",32 ":1000E400FC01010001000000F80101000100000012",
33 ":1000F4003A02010001000000E202010001000000D8",33 ":1000F4000E02010001000000B60201000100000030",
34 ":100104000C03010001000000A50202000000000031",34 ":10010400E00201000100000079020200000000008A",
35 ":1001140000000000000000000000000000000000DB",35 ":1001140000000000000000000000000000000000DB",
36 ":1001240000000000000000000000000000000000CB",36 ":1001240000000000000000000000000000000000CB",
37 ":1001340000000000000000000000000000000000BB",37 ":1001340000000000000000000000000000000000BB",
38 ":10014400AF02020098020100090000004D02010004",38 ":10014400830202006C020100090000002102010088",
39 ":100154000900000001000000000000000000000091",39 ":100154000900000001000000000000000000000091",
40 ":1001640000080002008001010004000010000000EB",40 ":1001640000080002008001010004000010000000EB",
41 ":100174000000000000000000000000001F0000005C",41 ":100174000000000000000000000000001F0000005C",
...@@ -44,55 +44,52 @@ pub fn build(b: *Builder) void {...@@ -44,55 +44,52 @@ pub fn build(b: *Builder) void {
44 ":1001A40000000000000000001F000000000000002C",44 ":1001A40000000000000000001F000000000000002C",
45 ":1001B400000000000000000000000000000000003B",45 ":1001B400000000000000000000000000000000003B",
46 ":1001C400000000000000000000000000000000002B",46 ":1001C400000000000000000000000000000000002B",
47 ":1001D400000000000000000000000000000000001B",47 ":1001D4005B02010010000000F40101002C0000008B",
48 ":1001E400000000000000000000000000000000000B",48 ":1001E4003F0201001B0000002B020100130000006D",
49 ":1001F4000000000000000000000000008702010071",49 ":1001F40072656D61696E646572206469766973699C",
50 ":1002040010000000200201002C0000006B0201001D",50 ":100204006F6E206279207A65726F206F72206E653E",
51 ":100214001B000000570201001300000072656D61AD",51 ":100214006761746976652076616C756500636F72D9",
52 ":10022400696E646572206469766973696F6E2062B1",52 ":100224007465782D6D3400696E646578206F75741B",
53 ":1002340079207A65726F206F72206E6567617469C8",53 ":10023400206F6620626F756E647300696E74656703",
54 ":1002440076652076616C756500636F727465782DD0",54 ":1002440065722063617374207472756E6361746582",
55 ":100254006D3400696E646578206F7574206F662054",55 ":10025400642062697473006469766973696F6E20DF",
56 ":10026400626F756E647300696E746567657220638E",56 ":100264006279207A65726F00636F727465785F6D6E",
57 ":10027400617374207472756E63617465642062695D",57 ":100274003400000081B00091FFE700BEFDE7D0B577",
58 ":100284007473006469766973696F6E206279207A89",58 ":1002840002AF90B00391029007A800F029F80399F7",
59 ":1002940065726F00636F727465785F6D340000007F",59 ":100294000020069048680490FFE7049906980190AE",
60 ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A",60 ":1002A40088420FD2FFE7019903980068405C07F881",
61 ":1002B4000391029007A800F029F803990020069002",61 ":1002B400310C17F8311C07A800F021F8019801301F",
62 ":1002C40048680490FFE704990698019088420FD289",62 ":1002C4000690EAE7029807A9B1E80C50A0E80C50A0",
63 ":1002D400FFE7019903980068405C07F8310C17F8B0",63 ":1002D40091E81C5080E81C5010B0D0BDFFE7FEE749",
64 ":1002E400311C07A800F021F8019801300690EAE7D4",64 ":1002E400D0B502AF40F2B011C0F20101B1E80C5038",
65 ":1002F400029807A9B1E80C50A0E80C5091E81C50F2",65 ":1002F400A0E80C5091E81C5080E81C50D0BD80B59B",
66 ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7",66 ":100304006F4688B006906FF35F2127F80A1C37F810",
67 ":1003140040F2DC11C0F20101B1E80C50A0E80C502D",67 ":100314000A0C0490012038B9FFE740F2D410C0F26F",
68 ":1003240091E81C5080E81C50D0BD80B56F4688B061",68 ":1003240001000021FFF7A6FF0498C0F3431027F84B",
69 ":1003340006906FF35F2127F80A1C37F80A0C049023",69 ":10033400020C37F80A0C0390002038B9FFE7039841",
70 ":10034400012038B9FFE740F20020C0F2010000218B",70 ":1003440000F01F000290012038B914E040F2DC10E4",
71 ":10035400FFF7A6FF0498C0F3431027F8020C37F800",71 ":10035400C0F201000021FFF78DFF029800F01F009A",
72 ":100364000A0C0390002038B9FFE7039800F01F003F",72 ":1003640007F8030C0698009037F8020C0146019137",
73 ":100374000290012038B914E040F20820C0F20100D4",73 ":1003740009280ED306E040F2E410C0F20100002187",
74 ":100384000021FFF78DFF029800F01F0007F8030C0F",74 ":10038400FFF778FF40F2EC10C0F201000021FFF704",
75 ":100394000698009037F8020C0146019109280ED303",75 ":1003940071FF0099019A51F8220017F803CC012348",
76 ":1003A40006E040F21020C0F201000021FFF778FFC0",76 ":1003A40003FA0CF3184341F8220008B080BD81B071",
77 ":1003B40040F21820C0F201000021FFF771FF0099FC",77 ":1003B40000F03F008DF802009DF802000F3000F0BD",
78 ":1003C400019A51F8220017F803CC012303FA0CF325",78 ":1003C4003F00022804D3FFE700208DF8030003E078",
79 ":1003D400184341F8220008B080BD81B000F03F000E",79 ":1003D40001208DF80300FFE79DF8030001B070478A",
80 ":1003E4008DF802009DF802000F3000F03F00022853",80 ":1003E4000A00000012000000020071001200000068",
81 ":1003F40004D3FFE700208DF8030003E001208DF80B",81 ":1003F4006600000003007D0C060000000000000001",
82 ":100404000300FFE79DF8030001B070470A000000F5",82 ":1004040000011101250E1305030E10171B0EB44233",
83 ":1004140012000000020071001200000066000000DB",83 ":0A0414001911011206000002340065",
84 ":1004240003007D0C06000000000000000001110123",
85 ":10043400250E1305030E10171B0EB44219110112D9",
86 ":0604440006000002340076",
87 ":020000021000EC",84 ":020000021000EC",
88 ":1000D400D001010001000000D20101000100000074",85 ":1000D400A401010001000000A601010001000000CC",
89 ":1000E40028020100010000002402010001000000B8",86 ":1000E400FC01010001000000F80101000100000012",
90 ":1000F4003A02010001000000E202010001000000D8",87 ":1000F4000E02010001000000B60201000100000030",
91 ":100104000C03010001000000A50202000000000031",88 ":10010400E00201000100000079020200000000008A",
92 ":1001140000000000000000000000000000000000DB",89 ":1001140000000000000000000000000000000000DB",
93 ":1001240000000000000000000000000000000000CB",90 ":1001240000000000000000000000000000000000CB",
94 ":1001340000000000000000000000000000000000BB",91 ":1001340000000000000000000000000000000000BB",
95 ":10014400AF02020098020100090000004D02010004",92 ":10014400830202006C020100090000002102010088",
96 ":100154000900000001000000000000000000000091",93 ":100154000900000001000000000000000000000091",
97 ":1001640000080002008001010004000010000000EB",94 ":1001640000080002008001010004000010000000EB",
98 ":100174000000000000000000000000001F0000005C",95 ":100174000000000000000000000000001F0000005C",
...@@ -101,70 +98,67 @@ pub fn build(b: *Builder) void {...@@ -101,70 +98,67 @@ pub fn build(b: *Builder) void {
101 ":1001A40000000000000000001F000000000000002C",98 ":1001A40000000000000000001F000000000000002C",
102 ":1001B400000000000000000000000000000000003B",99 ":1001B400000000000000000000000000000000003B",
103 ":1001C400000000000000000000000000000000002B",100 ":1001C400000000000000000000000000000000002B",
104 ":1001D400000000000000000000000000000000001B",101 ":1001D4005B02010010000000F40101002C0000008B",
105 ":1001E400000000000000000000000000000000000B",102 ":1001E4003F0201001B0000002B020100130000006D",
106 ":1001F4000000000000000000000000008702010071",103 ":1001F40072656D61696E646572206469766973699C",
107 ":1002040010000000200201002C0000006B0201001D",104 ":100204006F6E206279207A65726F206F72206E653E",
108 ":100214001B000000570201001300000072656D61AD",105 ":100214006761746976652076616C756500636F72D9",
109 ":10022400696E646572206469766973696F6E2062B1",106 ":100224007465782D6D3400696E646578206F75741B",
110 ":1002340079207A65726F206F72206E6567617469C8",107 ":10023400206F6620626F756E647300696E74656703",
111 ":1002440076652076616C756500636F727465782DD0",108 ":1002440065722063617374207472756E6361746582",
112 ":100254006D3400696E646578206F7574206F662054",109 ":10025400642062697473006469766973696F6E20DF",
113 ":10026400626F756E647300696E746567657220638E",110 ":100264006279207A65726F00636F727465785F6D6E",
114 ":10027400617374207472756E63617465642062695D",111 ":100274003400000081B00091FFE700BEFDE7D0B577",
115 ":100284007473006469766973696F6E206279207A89",112 ":1002840002AF90B00391029007A800F029F80399F7",
116 ":1002940065726F00636F727465785F6D340000007F",113 ":100294000020069048680490FFE7049906980190AE",
117 ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A",114 ":1002A40088420FD2FFE7019903980068405C07F881",
118 ":1002B4000391029007A800F029F803990020069002",115 ":1002B400310C17F8311C07A800F021F8019801301F",
119 ":1002C40048680490FFE704990698019088420FD289",116 ":1002C4000690EAE7029807A9B1E80C50A0E80C50A0",
120 ":1002D400FFE7019903980068405C07F8310C17F8B0",117 ":1002D40091E81C5080E81C5010B0D0BDFFE7FEE749",
121 ":1002E400311C07A800F021F8019801300690EAE7D4",118 ":1002E400D0B502AF40F2B011C0F20101B1E80C5038",
122 ":1002F400029807A9B1E80C50A0E80C5091E81C50F2",119 ":1002F400A0E80C5091E81C5080E81C50D0BD80B59B",
123 ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7",120 ":100304006F4688B006906FF35F2127F80A1C37F810",
124 ":1003140040F2DC11C0F20101B1E80C50A0E80C502D",121 ":100314000A0C0490012038B9FFE740F2D410C0F26F",
125 ":1003240091E81C5080E81C50D0BD80B56F4688B061",122 ":1003240001000021FFF7A6FF0498C0F3431027F84B",
126 ":1003340006906FF35F2127F80A1C37F80A0C049023",123 ":10033400020C37F80A0C0390002038B9FFE7039841",
127 ":10034400012038B9FFE740F20020C0F2010000218B",124 ":1003440000F01F000290012038B914E040F2DC10E4",
128 ":10035400FFF7A6FF0498C0F3431027F8020C37F800",125 ":10035400C0F201000021FFF78DFF029800F01F009A",
129 ":100364000A0C0390002038B9FFE7039800F01F003F",126 ":1003640007F8030C0698009037F8020C0146019137",
130 ":100374000290012038B914E040F20820C0F20100D4",127 ":1003740009280ED306E040F2E410C0F20100002187",
131 ":100384000021FFF78DFF029800F01F0007F8030C0F",128 ":10038400FFF778FF40F2EC10C0F201000021FFF704",
132 ":100394000698009037F8020C0146019109280ED303",129 ":1003940071FF0099019A51F8220017F803CC012348",
133 ":1003A40006E040F21020C0F201000021FFF778FFC0",130 ":1003A40003FA0CF3184341F8220008B080BD81B071",
134 ":1003B40040F21820C0F201000021FFF771FF0099FC",131 ":1003B40000F03F008DF802009DF802000F3000F0BD",
135 ":1003C400019A51F8220017F803CC012303FA0CF325",132 ":1003C4003F00022804D3FFE700208DF8030003E078",
136 ":1003D400184341F8220008B080BD81B000F03F000E",133 ":1003D40001208DF80300FFE79DF8030001B070478A",
137 ":1003E4008DF802009DF802000F3000F03F00022853",134 ":1003E4000A00000012000000020071001200000068",
138 ":1003F40004D3FFE700208DF8030003E001208DF80B",135 ":1003F4006600000003007D0C060000000000000001",
139 ":100404000300FFE79DF8030001B070470A000000F5",136 ":1004040000011101250E1305030E10171B0EB44233",
140 ":1004140012000000020071001200000066000000DB",137 ":0A0414001911011206000002340065",
141 ":1004240003007D0C06000000000000000001110123",
142 ":10043400250E1305030E10171B0EB44219110112D9",
143 ":0604440006000002340076",
144 ":020000022000DC",138 ":020000022000DC",
145 ":1002A40081B00091FFE700BEFDE7D0B502AF90B08A",139 ":1002780081B00091FFE700BEFDE7D0B502AF90B0B6",
146 ":1002B4000391029007A800F029F803990020069002",140 ":100288000391029007A800F029F80399002006902E",
147 ":1002C40048680490FFE704990698019088420FD289",141 ":1002980048680490FFE704990698019088420FD2B5",
148 ":1002D400FFE7019903980068405C07F8310C17F8B0",142 ":1002A800FFE7019903980068405C07F8310C17F8DC",
149 ":1002E400311C07A800F021F8019801300690EAE7D4",143 ":1002B800311C07A800F021F8019801300690EAE700",
150 ":1002F400029807A9B1E80C50A0E80C5091E81C50F2",144 ":1002C800029807A9B1E80C50A0E80C5091E81C501E",
151 ":1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7",145 ":1002D80080E81C5010B0D0BDFFE7FEE7D0B502AFF4",
152 ":1003140040F2DC11C0F20101B1E80C50A0E80C502D",146 ":1002E80040F2B011C0F20101B1E80C50A0E80C5086",
153 ":1003240091E81C5080E81C50D0BD80B56F4688B061",147 ":1002F80091E81C5080E81C50D0BD80B56F4688B08E",
154 ":1003340006906FF35F2127F80A1C37F80A0C049023",148 ":1003080006906FF35F2127F80A1C37F80A0C04904F",
155 ":10034400012038B9FFE740F20020C0F2010000218B",149 ":10031800012038B9FFE740F2D410C0F201000021F3",
156 ":10035400FFF7A6FF0498C0F3431027F8020C37F800",150 ":10032800FFF7A6FF0498C0F3431027F8020C37F82C",
157 ":100364000A0C0390002038B9FFE7039800F01F003F",151 ":100338000A0C0390002038B9FFE7039800F01F006B",
158 ":100374000290012038B914E040F20820C0F20100D4",152 ":100348000290012038B914E040F2DC10C0F201003C",
159 ":100384000021FFF78DFF029800F01F0007F8030C0F",153 ":100358000021FFF78DFF029800F01F0007F8030C3B",
160 ":100394000698009037F8020C0146019109280ED303",154 ":100368000698009037F8020C0146019109280ED32F",
161 ":1003A40006E040F21020C0F201000021FFF778FFC0",155 ":1003780006E040F2E410C0F201000021FFF778FF28",
162 ":1003B40040F21820C0F201000021FFF771FF0099FC",156 ":1003880040F2EC10C0F201000021FFF771FF009964",
163 ":1003C400019A51F8220017F803CC012303FA0CF325",157 ":10039800019A51F8220017F803CC012303FA0CF351",
164 ":1003D400184341F8220008B080BD81B000F03F000E",158 ":1003A800184341F8220008B080BD81B000F03F003A",
165 ":1003E4008DF802009DF802000F3000F03F00022853",159 ":1003B8008DF802009DF802000F3000F03F0002287F",
166 ":1003F40004D3FFE700208DF8030003E001208DF80B",160 ":1003C80004D3FFE700208DF8030003E001208DF837",
167 ":0C0404000300FFE79DF8030001B0704703",161 ":0C03D8000300FFE79DF8030001B0704730",
168 ":00000001FF",162 ":00000001FF",
169 };163 };
170164
test/tests.zig+7-7
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const warn = debug.warn;4const warn = debug.warn;
5const build = std.build;5const build = std.build;
...@@ -9,7 +9,7 @@ const fs = std.fs;...@@ -9,7 +9,7 @@ const fs = std.fs;
9const mem = std.mem;9const mem = std.mem;
10const fmt = std.fmt;10const fmt = std.fmt;
11const ArrayList = std.ArrayList;11const ArrayList = std.ArrayList;
12const Mode = builtin.Mode;12const Mode = std.builtin.Mode;
13const LibExeObjStep = build.LibExeObjStep;13const LibExeObjStep = build.LibExeObjStep;
1414
15// Cases15// Cases
...@@ -29,7 +29,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput...@@ -29,7 +29,7 @@ pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutput
2929
30const TestTarget = struct {30const TestTarget = struct {
31 target: CrossTarget = @as(CrossTarget, .{}),31 target: CrossTarget = @as(CrossTarget, .{}),
32 mode: builtin.Mode = .Debug,32 mode: std.builtin.Mode = .Debug,
33 link_libc: bool = false,33 link_libc: bool = false,
34 single_threaded: bool = false,34 single_threaded: bool = false,
35 disable_native: bool = false,35 disable_native: bool = false,
...@@ -532,8 +532,8 @@ pub fn addPkgTests(...@@ -532,8 +532,8 @@ pub fn addPkgTests(
532 continue;532 continue;
533533
534 if (test_target.disable_native and534 if (test_target.disable_native and
535 test_target.target.getOsTag() == std.Target.current.os.tag and535 test_target.target.getOsTag() == builtin.os.tag and
536 test_target.target.getCpuArch() == std.Target.current.cpu.arch)536 test_target.target.getCpuArch() == builtin.cpu.arch)
537 {537 {
538 continue;538 continue;
539 }539 }
...@@ -785,7 +785,7 @@ pub const StackTracesContext = struct {...@@ -785,7 +785,7 @@ pub const StackTracesContext = struct {
785 if (line.len == 0) continue;785 if (line.len == 0) continue;
786786
787 // offset search past `[drive]:` on windows787 // offset search past `[drive]:` on windows
788 var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0;788 var pos: usize = if (builtin.os.tag == .windows) 2 else 0;
789 // locate delims/anchor789 // locate delims/anchor
790 const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" };790 const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" };
791 var marks = [_]usize{0} ** delims.len;791 var marks = [_]usize{0} ** delims.len;
...@@ -1055,7 +1055,7 @@ pub const GenHContext = struct {...@@ -1055,7 +1055,7 @@ pub const GenHContext = struct {
1055 pub fn addCase(self: *GenHContext, case: *const TestCase) void {1055 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
1056 const b = self.b;1056 const b = self.b;
10571057
1058 const mode = builtin.Mode.Debug;1058 const mode = std.builtin.Mode.Debug;
1059 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable;1059 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable;
1060 if (self.test_filter) |filter| {1060 if (self.test_filter) |filter| {
1061 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;1061 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
test/translate_c.zig+7-6
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1const tests = @import("tests.zig");
2const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const tests = @import("tests.zig");
3const CrossTarget = std.zig.CrossTarget;4const CrossTarget = std.zig.CrossTarget;
45
5pub fn addCases(cases: *tests.TranslateCContext) void {6pub fn addCases(cases: *tests.TranslateCContext) void {
6 const default_enum_type = if (std.Target.current.abi == .msvc) "c_int" else "c_uint";7 const default_enum_type = if (builtin.abi == .msvc) "c_int" else "c_uint";
78
8 cases.add("field access is grouped if necessary",9 cases.add("field access is grouped if necessary",
9 \\unsigned long foo(unsigned long x) {10 \\unsigned long foo(unsigned long x) {
...@@ -1153,7 +1154,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1153,7 +1154,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1153 \\pub export fn foo() void {}1154 \\pub export fn foo() void {}
1154 });1155 });
11551156
1156 if (std.Target.current.os.tag != .windows) {1157 if (builtin.os.tag != .windows) {
1157 // Windows treats this as an enum with type c_int1158 // Windows treats this as an enum with type c_int
1158 cases.add("big negative enum init values when C ABI supports long long enums",1159 cases.add("big negative enum init values when C ABI supports long long enums",
1159 \\enum EnumWithInits {1160 \\enum EnumWithInits {
...@@ -1558,7 +1559,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1558,7 +1559,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1558 \\}1559 \\}
1559 });1560 });
15601561
1561 if (std.Target.current.os.tag != .windows) {1562 if (builtin.os.tag != .windows) {
1562 // sysv_abi not currently supported on windows1563 // sysv_abi not currently supported on windows
1563 cases.add("Macro qualified functions",1564 cases.add("Macro qualified functions",
1564 \\void __attribute__((sysv_abi)) foo(void);1565 \\void __attribute__((sysv_abi)) foo(void);
...@@ -2160,7 +2161,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2160,7 +2161,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2160 \\}2161 \\}
2161 });2162 });
21622163
2163 if (std.Target.current.os.tag != .windows) {2164 if (builtin.os.tag != .windows) {
2164 // When clang uses the <arch>-windows-none triple it behaves as MSVC and2165 // When clang uses the <arch>-windows-none triple it behaves as MSVC and
2165 // interprets the inner `struct Bar` as an anonymous structure2166 // interprets the inner `struct Bar` as an anonymous structure
2166 cases.add("type referenced struct",2167 cases.add("type referenced struct",
...@@ -3398,7 +3399,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3398,7 +3399,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3398 \\pub const FOO = @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.promoteIntLiteral(c_int, 0x8000, .hexadecimal));3399 \\pub const FOO = @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.promoteIntLiteral(c_int, 0x8000, .hexadecimal));
3399 });3400 });
34003401
3401 if (std.Target.current.abi == .msvc) {3402 if (builtin.abi == .msvc) {
3402 cases.add("nameless struct fields",3403 cases.add("nameless struct fields",
3403 \\typedef struct NAMED3404 \\typedef struct NAMED
3404 \\{3405 \\{
tools/update_cpu_features.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const fs = std.fs;3const fs = std.fs;
3const mem = std.mem;4const mem = std.mem;
4const json = std.json;5const json = std.json;
...@@ -803,7 +804,7 @@ pub fn main() anyerror!void {...@@ -803,7 +804,7 @@ pub fn main() anyerror!void {
803 const root_progress = try progress.start("", llvm_targets.len);804 const root_progress = try progress.start("", llvm_targets.len);
804 defer root_progress.end();805 defer root_progress.end();
805806
806 if (std.builtin.single_threaded) {807 if (builtin.single_threaded) {
807 for (llvm_targets) |llvm_target| {808 for (llvm_targets) |llvm_target| {
808 try processOneTarget(Job{809 try processOneTarget(Job{
809 .llvm_tblgen_exe = llvm_tblgen_exe,810 .llvm_tblgen_exe = llvm_tblgen_exe,