Commit 278e5d398e

Kenta Iwasaki <kenta@lithdew.net>
2021-05-19 07:30:04
x: replace std.builtin with std.Target.current
1 parent 21ec015
Changed files (5)
lib/std/os/linux.zig
@@ -1000,9 +1000,9 @@ pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noal
     return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
 }
 
-pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
+pub fn sendmsg(fd: i32, msg: *const std.x.os.Socket.Message, flags: c_int) usize {
     if (native_arch == .i386) {
-        return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
+        return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) });
     }
     return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
 }
@@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
     return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
 }
 
-pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
+pub fn recvmsg(fd: i32, msg: *std.x.os.Socket.Message, flags: c_int) usize {
     if (native_arch == .i386) {
-        return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
+        return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) });
     }
     return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)));
 }
lib/std/x/net/tcp.zig
@@ -12,8 +12,8 @@ const ip = std.x.net.ip;
 
 const fmt = std.fmt;
 const mem = std.mem;
-const builtin = std.builtin;
 const testing = std.testing;
+const native_os = std.Target.current.os;
 
 const IPv4 = std.x.os.IPv4;
 const IPv6 = std.x.os.IPv6;
@@ -325,7 +325,7 @@ pub const Listener = struct {
 };
 
 test "tcp: create client/listener pair" {
-    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+    if (native_os.tag == .wasi) return error.SkipZigTest;
 
     const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
     defer listener.deinit();
@@ -349,7 +349,7 @@ test "tcp: create client/listener pair" {
 }
 
 test "tcp/client: 1ms read timeout" {
-    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+    if (native_os.tag == .wasi) return error.SkipZigTest;
 
     const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
     defer listener.deinit();
@@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" {
 }
 
 test "tcp/client: read and write multiple vectors" {
-    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+    if (native_os.tag == .wasi) return error.SkipZigTest;
 
     const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
     defer listener.deinit();
@@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" {
 }
 
 test "tcp/listener: bind to unspecified ipv4 address" {
-    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+    if (native_os.tag == .wasi) return error.SkipZigTest;
 
     const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
     defer listener.deinit();
@@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
 }
 
 test "tcp/listener: bind to unspecified ipv6 address" {
-    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+    if (native_os.tag == .wasi) return error.SkipZigTest;
 
     const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true });
     defer listener.deinit();
lib/std/x/os/io.zig
@@ -2,12 +2,12 @@ const std = @import("../../std.zig");
 
 const os = std.os;
 const mem = std.mem;
-const builtin = std.builtin;
 const testing = std.testing;
+const native_os = std.Target.current.os;
 
 /// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering
 /// of fields, alongside the length being represented as either a ULONG or a size_t.
-pub const Buffer = if (builtin.os.tag == .windows)
+pub const Buffer = if (native_os.tag == .windows)
     extern struct {
         len: c_ulong,
         ptr: usize,
@@ -38,7 +38,7 @@ else
         }
 
         pub fn intoMutable(self: Buffer) []u8 {
-            return @intToptr([*]u8, self.ptr)[0..self.len];
+            return @intToPtr([*]u8, self.ptr)[0..self.len];
         }
     };
 
@@ -115,7 +115,7 @@ pub const Reactor = struct {
 };
 
 test "reactor/linux: drive async tcp client/listener pair" {
-    if (builtin.os.tag != .linux) return error.SkipZigTest;
+    if (native_os.tag != .linux) return error.SkipZigTest;
 
     const ip = std.x.net.ip;
     const tcp = std.x.net.tcp;
lib/std/x/os/net.zig
@@ -10,8 +10,8 @@ const os = std.os;
 const fmt = std.fmt;
 const mem = std.mem;
 const math = std.math;
-const builtin = std.builtin;
 const testing = std.testing;
+const native_os = std.Target.current.os;
 
 /// Resolves a network interface name into a scope/zone ID. It returns
 /// an error if either resolution fails, or if the interface name is
@@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {
     if (comptime @hasDecl(os, "IFNAMESIZE")) {
         if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;
 
-        if (comptime builtin.os.tag == .windows) {
+        if (comptime native_os.tag == .windows) {
             var interface_name: [os.IFNAMESIZE]u8 = undefined;
             mem.copy(u8, &interface_name, name);
             interface_name[name.len] = 0;
lib/std/x/os/socket.zig
@@ -12,7 +12,8 @@ const fmt = std.fmt;
 const mem = std.mem;
 const time = std.time;
 const meta = std.meta;
-const builtin = std.builtin;
+const native_os = std.Target.current.os;
+const native_endian = std.Target.current.cpu.arch.endian();
 
 const Buffer = std.x.os.Buffer;
 
@@ -35,7 +36,7 @@ pub const Socket = struct {
     /// the fields of a `Socket.Address`.
     pub const Address = union(enum) {
         pub const Native = struct {
-            pub const requires_prepended_length = builtin.os.getVersionRange() == .semver;
+            pub const requires_prepended_length = native_os.getVersionRange() == .semver;
             pub const Length = if (requires_prepended_length) u8 else [0]u8;
 
             pub const Family = if (requires_prepended_length) u8 else c_ushort;
@@ -140,7 +141,7 @@ pub const Socket = struct {
 
     /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported
     /// directly from musl.
-    pub const Message = if (builtin.os.isAtLeast(.windows, .vista) != null and builtin.os.isAtLeast(.windows, .vista).?)
+    pub const Message = if (native_os.isAtLeast(.windows, .vista) != null and native_os.isAtLeast(.windows, .vista).?)
         extern struct {
             name: usize = @ptrToInt(@as(?[*]u8, null)),
             name_len: c_int = 0,
@@ -156,7 +157,7 @@ pub const Socket = struct {
 
             pub usingnamespace MessageMixin(Message);
         }
-    else if (builtin.os.tag == .windows)
+    else if (native_os.tag == .windows)
         extern struct {
             name: usize = @ptrToInt(@as(?[*]u8, null)),
             name_len: c_int = 0,
@@ -172,7 +173,7 @@ pub const Socket = struct {
 
             pub usingnamespace MessageMixin(Message);
         }
-    else if (@sizeOf(usize) > 4 and builtin.endian == .Big)
+    else if (@sizeOf(usize) > 4 and native_endian == .Big)
         extern struct {
             name: usize = @ptrToInt(@as(?[*]u8, null)),
             name_len: c_uint = 0,
@@ -189,7 +190,7 @@ pub const Socket = struct {
 
             pub usingnamespace MessageMixin(Message);
         }
-    else if (@sizeOf(usize) > 4 and builtin.endian == .Little)
+    else if (@sizeOf(usize) > 4 and native_endian == .Little)
         extern struct {
             name: usize = @ptrToInt(@as(?[*]u8, null)),
             name_len: c_uint = 0,
@@ -241,7 +242,7 @@ pub const Socket = struct {
             }
 
             pub fn setControl(self: *Self, control: []const u8) void {
-                if (builtin.os.tag == .windows) {
+                if (native_os.tag == .windows) {
                     self.control = Buffer.from(control);
                 } else {
                     self.control = @ptrToInt(control.ptr);
@@ -262,7 +263,7 @@ pub const Socket = struct {
             }
 
             pub fn getControl(self: Self) []const u8 {
-                if (builtin.os.tag == .windows) {
+                if (native_os.tag == .windows) {
                     return self.control.into();
                 } else {
                     return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)];
@@ -281,7 +282,7 @@ pub const Socket = struct {
     /// short's on Windows, whereas glibc and musl denote the fields to be
     /// int's on every other platform. 
     pub const Linger = extern struct {
-        pub const Field = switch (builtin.os.tag) {
+        pub const Field = switch (native_os.tag) {
             .windows => c_ushort,
             else => c_int,
         };
@@ -315,7 +316,7 @@ pub const Socket = struct {
     }
 
     /// Mix in socket syscalls depending on the platform we are compiling against.
-    pub usingnamespace switch (builtin.os.tag) {
+    pub usingnamespace switch (native_os.tag) {
         .windows => @import("socket_windows.zig"),
         else => @import("socket_posix.zig"),
     }.Mixin(Socket);