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
10001000 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
10011001}
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 {
10041004 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)) });
10061006 }
10071007 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
10081008}
......@@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
10541054 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
10551055}
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 {
10581058 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)) });
10601060 }
10611061 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
10621062}
lib/std/x/net/tcp.zig+6-6
......@@ -12,8 +12,8 @@ const ip = std.x.net.ip;
1212
1313const fmt = std.fmt;
1414const mem = std.mem;
15const builtin = std.builtin;
1615const testing = std.testing;
16const native_os = std.Target.current.os;
1717
1818const IPv4 = std.x.os.IPv4;
1919const IPv6 = std.x.os.IPv6;
......@@ -325,7 +325,7 @@ pub const Listener = struct {
325325};
326326
327327test "tcp: create client/listener pair" {
328 if (builtin.os.tag == .wasi) return error.SkipZigTest;
328 if (native_os.tag == .wasi) return error.SkipZigTest;
329329
330330 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
331331 defer listener.deinit();
......@@ -349,7 +349,7 @@ test "tcp: create client/listener pair" {
349349}
350350
351351test "tcp/client: 1ms read timeout" {
352 if (builtin.os.tag == .wasi) return error.SkipZigTest;
352 if (native_os.tag == .wasi) return error.SkipZigTest;
353353
354354 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
355355 defer listener.deinit();
......@@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" {
377377}
378378
379379test "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
382382 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
383383 defer listener.deinit();
......@@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" {
416416}
417417
418418test "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
421421 const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
422422 defer listener.deinit();
......@@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
429429}
430430
431431test "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
434434 const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true });
435435 defer listener.deinit();
lib/std/x/os/io.zig+4-4
......@@ -2,12 +2,12 @@ const std = @import("../../std.zig");
22
33const os = std.os;
44const mem = std.mem;
5const builtin = std.builtin;
65const testing = std.testing;
6const native_os = std.Target.current.os;
77
88/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering
99/// 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)
1111 extern struct {
1212 len: c_ulong,
1313 ptr: usize,
......@@ -38,7 +38,7 @@ else
3838 }
3939
4040 pub fn intoMutable(self: Buffer) []u8 {
41 return @intToptr([*]u8, self.ptr)[0..self.len];
41 return @intToPtr([*]u8, self.ptr)[0..self.len];
4242 }
4343 };
4444
......@@ -115,7 +115,7 @@ pub const Reactor = struct {
115115};
116116
117117test "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
120120 const ip = std.x.net.ip;
121121 const tcp = std.x.net.tcp;
lib/std/x/os/net.zig+2-2
......@@ -10,8 +10,8 @@ const os = std.os;
1010const fmt = std.fmt;
1111const mem = std.mem;
1212const math = std.math;
13const builtin = std.builtin;
1413const testing = std.testing;
14const native_os = std.Target.current.os;
1515
1616/// Resolves a network interface name into a scope/zone ID. It returns
1717/// an error if either resolution fails, or if the interface name is
......@@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {
2020 if (comptime @hasDecl(os, "IFNAMESIZE")) {
2121 if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;
2222
23 if (comptime builtin.os.tag == .windows) {
23 if (comptime native_os.tag == .windows) {
2424 var interface_name: [os.IFNAMESIZE]u8 = undefined;
2525 mem.copy(u8, &interface_name, name);
2626 interface_name[name.len] = 0;
lib/std/x/os/socket.zig+11-10
......@@ -12,7 +12,8 @@ const fmt = std.fmt;
1212const mem = std.mem;
1313const time = std.time;
1414const meta = std.meta;
15const builtin = std.builtin;
15const native_os = std.Target.current.os;
16const native_endian = std.Target.current.cpu.arch.endian();
1617
1718const Buffer = std.x.os.Buffer;
1819
......@@ -35,7 +36,7 @@ pub const Socket = struct {
3536 /// the fields of a `Socket.Address`.
3637 pub const Address = union(enum) {
3738 pub const Native = struct {
38 pub const requires_prepended_length = builtin.os.getVersionRange() == .semver;
39 pub const requires_prepended_length = native_os.getVersionRange() == .semver;
3940 pub const Length = if (requires_prepended_length) u8 else [0]u8;
4041
4142 pub const Family = if (requires_prepended_length) u8 else c_ushort;
......@@ -140,7 +141,7 @@ pub const Socket = struct {
140141
141142 /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported
142143 /// 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).?)
144145 extern struct {
145146 name: usize = @ptrToInt(@as(?[*]u8, null)),
146147 name_len: c_int = 0,
......@@ -156,7 +157,7 @@ pub const Socket = struct {
156157
157158 pub usingnamespace MessageMixin(Message);
158159 }
159 else if (builtin.os.tag == .windows)
160 else if (native_os.tag == .windows)
160161 extern struct {
161162 name: usize = @ptrToInt(@as(?[*]u8, null)),
162163 name_len: c_int = 0,
......@@ -172,7 +173,7 @@ pub const Socket = struct {
172173
173174 pub usingnamespace MessageMixin(Message);
174175 }
175 else if (@sizeOf(usize) > 4 and builtin.endian == .Big)
176 else if (@sizeOf(usize) > 4 and native_endian == .Big)
176177 extern struct {
177178 name: usize = @ptrToInt(@as(?[*]u8, null)),
178179 name_len: c_uint = 0,
......@@ -189,7 +190,7 @@ pub const Socket = struct {
189190
190191 pub usingnamespace MessageMixin(Message);
191192 }
192 else if (@sizeOf(usize) > 4 and builtin.endian == .Little)
193 else if (@sizeOf(usize) > 4 and native_endian == .Little)
193194 extern struct {
194195 name: usize = @ptrToInt(@as(?[*]u8, null)),
195196 name_len: c_uint = 0,
......@@ -241,7 +242,7 @@ pub const Socket = struct {
241242 }
242243
243244 pub fn setControl(self: *Self, control: []const u8) void {
244 if (builtin.os.tag == .windows) {
245 if (native_os.tag == .windows) {
245246 self.control = Buffer.from(control);
246247 } else {
247248 self.control = @ptrToInt(control.ptr);
......@@ -262,7 +263,7 @@ pub const Socket = struct {
262263 }
263264
264265 pub fn getControl(self: Self) []const u8 {
265 if (builtin.os.tag == .windows) {
266 if (native_os.tag == .windows) {
266267 return self.control.into();
267268 } else {
268269 return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)];
......@@ -281,7 +282,7 @@ pub const Socket = struct {
281282 /// short's on Windows, whereas glibc and musl denote the fields to be
282283 /// int's on every other platform.
283284 pub const Linger = extern struct {
284 pub const Field = switch (builtin.os.tag) {
285 pub const Field = switch (native_os.tag) {
285286 .windows => c_ushort,
286287 else => c_int,
287288 };
......@@ -315,7 +316,7 @@ pub const Socket = struct {
315316 }
316317
317318 /// 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) {
319320 .windows => @import("socket_windows.zig"),
320321 else => @import("socket_posix.zig"),
321322 }.Mixin(Socket);