authorgravatar for kenta@lithdew.netKenta Iwasaki <kenta@lithdew.net> 2021-05-19 14:30:04+09:00
committergravatar for kenta@lithdew.netKenta Iwasaki <kenta@lithdew.net> 2021-06-01 18:24:43+09:00
log278e5d398ea137a4c81bd00b1f40e50a16755684
treede5baa7748e1dc810c5ad878dcc42226c273ae43
parent21ec0158a1b76cb52014b5dc79fb35ba3449d226

x: replace std.builtin with std.Target.current


5 files changed, 27 insertions(+), 26 deletions(-)

lib/std/os/linux.zig+4-4
...@@ -1000,9 +1000,9 @@ pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noal...@@ -1000,9 +1000,9 @@ pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noal
1000 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));1000 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
1001}1001}
10021002
1003pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {1003pub fn sendmsg(fd: i32, msg: *const std.x.os.Socket.Message, flags: c_int) usize {
1004 if (native_arch == .i386) {1004 if (native_arch == .i386) {
1005 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });1005 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) });
1006 }1006 }
1007 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));1007 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
1008}1008}
...@@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {...@@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
1054 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);1054 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
1055}1055}
10561056
1057pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {1057pub fn recvmsg(fd: i32, msg: *std.x.os.Socket.Message, flags: c_int) usize {
1058 if (native_arch == .i386) {1058 if (native_arch == .i386) {
1059 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });1059 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) });
1060 }1060 }
1061 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));1061 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
1062}1062}
lib/std/x/net/tcp.zig+6-6
...@@ -12,8 +12,8 @@ const ip = std.x.net.ip;...@@ -12,8 +12,8 @@ const ip = std.x.net.ip;
1212
13const fmt = std.fmt;13const fmt = std.fmt;
14const mem = std.mem;14const mem = std.mem;
15const builtin = std.builtin;
16const testing = std.testing;15const testing = std.testing;
16const native_os = std.Target.current.os;
1717
18const IPv4 = std.x.os.IPv4;18const IPv4 = std.x.os.IPv4;
19const IPv6 = std.x.os.IPv6;19const IPv6 = std.x.os.IPv6;
...@@ -325,7 +325,7 @@ pub const Listener = struct {...@@ -325,7 +325,7 @@ pub const Listener = struct {
325};325};
326326
327test "tcp: create client/listener pair" {327test "tcp: create client/listener pair" {
328 if (builtin.os.tag == .wasi) return error.SkipZigTest;328 if (native_os.tag == .wasi) return error.SkipZigTest;
329329
330 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });330 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
331 defer listener.deinit();331 defer listener.deinit();
...@@ -349,7 +349,7 @@ test "tcp: create client/listener pair" {...@@ -349,7 +349,7 @@ test "tcp: create client/listener pair" {
349}349}
350350
351test "tcp/client: 1ms read timeout" {351test "tcp/client: 1ms read timeout" {
352 if (builtin.os.tag == .wasi) return error.SkipZigTest;352 if (native_os.tag == .wasi) return error.SkipZigTest;
353353
354 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });354 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
355 defer listener.deinit();355 defer listener.deinit();
...@@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" {...@@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" {
377}377}
378378
379test "tcp/client: read and write multiple vectors" {379test "tcp/client: read and write multiple vectors" {
380 if (builtin.os.tag == .wasi) return error.SkipZigTest;380 if (native_os.tag == .wasi) return error.SkipZigTest;
381381
382 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });382 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
383 defer listener.deinit();383 defer listener.deinit();
...@@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" {...@@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" {
416}416}
417417
418test "tcp/listener: bind to unspecified ipv4 address" {418test "tcp/listener: bind to unspecified ipv4 address" {
419 if (builtin.os.tag == .wasi) return error.SkipZigTest;419 if (native_os.tag == .wasi) return error.SkipZigTest;
420420
421 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });421 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
422 defer listener.deinit();422 defer listener.deinit();
...@@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {...@@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
429}429}
430430
431test "tcp/listener: bind to unspecified ipv6 address" {431test "tcp/listener: bind to unspecified ipv6 address" {
432 if (builtin.os.tag == .wasi) return error.SkipZigTest;432 if (native_os.tag == .wasi) return error.SkipZigTest;
433433
434 const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true });434 const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true });
435 defer listener.deinit();435 defer listener.deinit();
lib/std/x/os/io.zig+4-4
...@@ -2,12 +2,12 @@ const std = @import("../../std.zig");...@@ -2,12 +2,12 @@ const std = @import("../../std.zig");
22
3const os = std.os;3const os = std.os;
4const mem = std.mem;4const mem = std.mem;
5const builtin = std.builtin;
6const testing = std.testing;5const testing = std.testing;
6const native_os = std.Target.current.os;
77
8/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering8/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering
9/// of fields, alongside the length being represented as either a ULONG or a size_t.9/// of fields, alongside the length being represented as either a ULONG or a size_t.
10pub const Buffer = if (builtin.os.tag == .windows)10pub const Buffer = if (native_os.tag == .windows)
11 extern struct {11 extern struct {
12 len: c_ulong,12 len: c_ulong,
13 ptr: usize,13 ptr: usize,
...@@ -38,7 +38,7 @@ else...@@ -38,7 +38,7 @@ else
38 }38 }
3939
40 pub fn intoMutable(self: Buffer) []u8 {40 pub fn intoMutable(self: Buffer) []u8 {
41 return @intToptr([*]u8, self.ptr)[0..self.len];41 return @intToPtr([*]u8, self.ptr)[0..self.len];
42 }42 }
43 };43 };
4444
...@@ -115,7 +115,7 @@ pub const Reactor = struct {...@@ -115,7 +115,7 @@ pub const Reactor = struct {
115};115};
116116
117test "reactor/linux: drive async tcp client/listener pair" {117test "reactor/linux: drive async tcp client/listener pair" {
118 if (builtin.os.tag != .linux) return error.SkipZigTest;118 if (native_os.tag != .linux) return error.SkipZigTest;
119119
120 const ip = std.x.net.ip;120 const ip = std.x.net.ip;
121 const tcp = std.x.net.tcp;121 const tcp = std.x.net.tcp;
lib/std/x/os/net.zig+2-2
...@@ -10,8 +10,8 @@ const os = std.os;...@@ -10,8 +10,8 @@ const os = std.os;
10const fmt = std.fmt;10const fmt = std.fmt;
11const mem = std.mem;11const mem = std.mem;
12const math = std.math;12const math = std.math;
13const builtin = std.builtin;
14const testing = std.testing;13const testing = std.testing;
14const native_os = std.Target.current.os;
1515
16/// Resolves a network interface name into a scope/zone ID. It returns16/// Resolves a network interface name into a scope/zone ID. It returns
17/// an error if either resolution fails, or if the interface name is17/// an error if either resolution fails, or if the interface name is
...@@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {...@@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {
20 if (comptime @hasDecl(os, "IFNAMESIZE")) {20 if (comptime @hasDecl(os, "IFNAMESIZE")) {
21 if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;21 if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;
2222
23 if (comptime builtin.os.tag == .windows) {23 if (comptime native_os.tag == .windows) {
24 var interface_name: [os.IFNAMESIZE]u8 = undefined;24 var interface_name: [os.IFNAMESIZE]u8 = undefined;
25 mem.copy(u8, &interface_name, name);25 mem.copy(u8, &interface_name, name);
26 interface_name[name.len] = 0;26 interface_name[name.len] = 0;
lib/std/x/os/socket.zig+11-10
...@@ -12,7 +12,8 @@ const fmt = std.fmt;...@@ -12,7 +12,8 @@ const fmt = std.fmt;
12const mem = std.mem;12const mem = std.mem;
13const time = std.time;13const time = std.time;
14const meta = std.meta;14const meta = std.meta;
15const builtin = std.builtin;15const native_os = std.Target.current.os;
16const native_endian = std.Target.current.cpu.arch.endian();
1617
17const Buffer = std.x.os.Buffer;18const Buffer = std.x.os.Buffer;
1819
...@@ -35,7 +36,7 @@ pub const Socket = struct {...@@ -35,7 +36,7 @@ pub const Socket = struct {
35 /// the fields of a `Socket.Address`.36 /// the fields of a `Socket.Address`.
36 pub const Address = union(enum) {37 pub const Address = union(enum) {
37 pub const Native = struct {38 pub const Native = struct {
38 pub const requires_prepended_length = builtin.os.getVersionRange() == .semver;39 pub const requires_prepended_length = native_os.getVersionRange() == .semver;
39 pub const Length = if (requires_prepended_length) u8 else [0]u8;40 pub const Length = if (requires_prepended_length) u8 else [0]u8;
4041
41 pub const Family = if (requires_prepended_length) u8 else c_ushort;42 pub const Family = if (requires_prepended_length) u8 else c_ushort;
...@@ -140,7 +141,7 @@ pub const Socket = struct {...@@ -140,7 +141,7 @@ pub const Socket = struct {
140141
141 /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported142 /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported
142 /// directly from musl.143 /// directly from musl.
143 pub const Message = if (builtin.os.isAtLeast(.windows, .vista) != null and builtin.os.isAtLeast(.windows, .vista).?)144 pub const Message = if (native_os.isAtLeast(.windows, .vista) != null and native_os.isAtLeast(.windows, .vista).?)
144 extern struct {145 extern struct {
145 name: usize = @ptrToInt(@as(?[*]u8, null)),146 name: usize = @ptrToInt(@as(?[*]u8, null)),
146 name_len: c_int = 0,147 name_len: c_int = 0,
...@@ -156,7 +157,7 @@ pub const Socket = struct {...@@ -156,7 +157,7 @@ pub const Socket = struct {
156157
157 pub usingnamespace MessageMixin(Message);158 pub usingnamespace MessageMixin(Message);
158 }159 }
159 else if (builtin.os.tag == .windows)160 else if (native_os.tag == .windows)
160 extern struct {161 extern struct {
161 name: usize = @ptrToInt(@as(?[*]u8, null)),162 name: usize = @ptrToInt(@as(?[*]u8, null)),
162 name_len: c_int = 0,163 name_len: c_int = 0,
...@@ -172,7 +173,7 @@ pub const Socket = struct {...@@ -172,7 +173,7 @@ pub const Socket = struct {
172173
173 pub usingnamespace MessageMixin(Message);174 pub usingnamespace MessageMixin(Message);
174 }175 }
175 else if (@sizeOf(usize) > 4 and builtin.endian == .Big)176 else if (@sizeOf(usize) > 4 and native_endian == .Big)
176 extern struct {177 extern struct {
177 name: usize = @ptrToInt(@as(?[*]u8, null)),178 name: usize = @ptrToInt(@as(?[*]u8, null)),
178 name_len: c_uint = 0,179 name_len: c_uint = 0,
...@@ -189,7 +190,7 @@ pub const Socket = struct {...@@ -189,7 +190,7 @@ pub const Socket = struct {
189190
190 pub usingnamespace MessageMixin(Message);191 pub usingnamespace MessageMixin(Message);
191 }192 }
192 else if (@sizeOf(usize) > 4 and builtin.endian == .Little)193 else if (@sizeOf(usize) > 4 and native_endian == .Little)
193 extern struct {194 extern struct {
194 name: usize = @ptrToInt(@as(?[*]u8, null)),195 name: usize = @ptrToInt(@as(?[*]u8, null)),
195 name_len: c_uint = 0,196 name_len: c_uint = 0,
...@@ -241,7 +242,7 @@ pub const Socket = struct {...@@ -241,7 +242,7 @@ pub const Socket = struct {
241 }242 }
242243
243 pub fn setControl(self: *Self, control: []const u8) void {244 pub fn setControl(self: *Self, control: []const u8) void {
244 if (builtin.os.tag == .windows) {245 if (native_os.tag == .windows) {
245 self.control = Buffer.from(control);246 self.control = Buffer.from(control);
246 } else {247 } else {
247 self.control = @ptrToInt(control.ptr);248 self.control = @ptrToInt(control.ptr);
...@@ -262,7 +263,7 @@ pub const Socket = struct {...@@ -262,7 +263,7 @@ pub const Socket = struct {
262 }263 }
263264
264 pub fn getControl(self: Self) []const u8 {265 pub fn getControl(self: Self) []const u8 {
265 if (builtin.os.tag == .windows) {266 if (native_os.tag == .windows) {
266 return self.control.into();267 return self.control.into();
267 } else {268 } else {
268 return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)];269 return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)];
...@@ -281,7 +282,7 @@ pub const Socket = struct {...@@ -281,7 +282,7 @@ pub const Socket = struct {
281 /// short's on Windows, whereas glibc and musl denote the fields to be282 /// short's on Windows, whereas glibc and musl denote the fields to be
282 /// int's on every other platform. 283 /// int's on every other platform.
283 pub const Linger = extern struct {284 pub const Linger = extern struct {
284 pub const Field = switch (builtin.os.tag) {285 pub const Field = switch (native_os.tag) {
285 .windows => c_ushort,286 .windows => c_ushort,
286 else => c_int,287 else => c_int,
287 };288 };
...@@ -315,7 +316,7 @@ pub const Socket = struct {...@@ -315,7 +316,7 @@ pub const Socket = struct {
315 }316 }
316317
317 /// Mix in socket syscalls depending on the platform we are compiling against.318 /// Mix in socket syscalls depending on the platform we are compiling against.
318 pub usingnamespace switch (builtin.os.tag) {319 pub usingnamespace switch (native_os.tag) {
319 .windows => @import("socket_windows.zig"),320 .windows => @import("socket_windows.zig"),
320 else => @import("socket_posix.zig"),321 else => @import("socket_posix.zig"),
321 }.Mixin(Socket);322 }.Mixin(Socket);