Commit 871f6343f4

N00byEdge <hannesbredberg@gmail.com>
2021-07-30 19:27:41
Move iovec and log levels to bits/posix.zig
This lets only the OSes that uses them to import them, and removes dependencies on bits.zig for the os/<os>/<arch>.zig files
1 parent 934df5b
lib/std/os/bits/darwin.zig
@@ -7,6 +7,8 @@ const std = @import("../../std.zig");
 const assert = std.debug.assert;
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 // See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
 // TODO: audit mode_t/pid_t, should likely be u16/i32
 pub const fd_t = c_int;
lib/std/os/bits/dragonfly.zig
@@ -6,6 +6,8 @@
 const std = @import("../../std.zig");
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 pub fn S_ISCHR(m: u32) bool {
     return m & S_IFMT == S_IFCHR;
 }
lib/std/os/bits/freebsd.zig
@@ -7,6 +7,8 @@ const std = @import("../../std.zig");
 const builtin = @import("builtin");
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 pub const blksize_t = i32;
 pub const blkcnt_t = i64;
 pub const clockid_t = i32;
lib/std/os/bits/haiku.zig
@@ -6,6 +6,8 @@
 const std = @import("../../std.zig");
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 pub const fd_t = c_int;
 pub const pid_t = c_int;
 pub const uid_t = u32;
lib/std/os/bits/linux.zig
@@ -6,7 +6,7 @@
 const std = @import("../../std.zig");
 const maxInt = std.math.maxInt;
 const arch = @import("builtin").target.cpu.arch;
-usingnamespace @import("../bits.zig");
+pub usingnamespace @import("posix.zig");
 
 pub usingnamespace switch (arch) {
     .mips, .mipsel => @import("linux/errno-mips.zig"),
lib/std/os/bits/netbsd.zig
@@ -7,6 +7,8 @@ const std = @import("../../std.zig");
 const builtin = std.builtin;
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 pub const blkcnt_t = i64;
 pub const blksize_t = i32;
 pub const clock_t = u32;
lib/std/os/bits/openbsd.zig
@@ -7,6 +7,8 @@ const std = @import("../../std.zig");
 const builtin = std.builtin;
 const maxInt = std.math.maxInt;
 
+pub usingnamespace @import("posix.zig");
+
 pub const blkcnt_t = i64;
 pub const blksize_t = i32;
 pub const clock_t = i64;
lib/std/os/bits/posix.zig
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2015-2021 Zig Contributors
+// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
+// The MIT license requires this copyright notice to be included in all copies
+// and substantial portions of the software.
+
+pub const iovec = extern struct {
+    iov_base: [*]u8,
+    iov_len: usize,
+};
+
+pub const iovec_const = extern struct {
+    iov_base: [*]const u8,
+    iov_len: usize,
+};
+
+// syslog
+
+/// system is unusable
+pub const LOG_EMERG = 0;
+/// action must be taken immediately
+pub const LOG_ALERT = 1;
+/// critical conditions
+pub const LOG_CRIT = 2;
+/// error conditions
+pub const LOG_ERR = 3;
+/// warning conditions
+pub const LOG_WARNING = 4;
+/// normal but significant condition
+pub const LOG_NOTICE = 5;
+/// informational
+pub const LOG_INFO = 6;
+/// debug-level messages
+pub const LOG_DEBUG = 7;
lib/std/os/bits/wasi.zig
@@ -4,6 +4,10 @@
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
 // Convenience types and consts used by std.os module
+const posix = @import("posix.zig");
+pub const iovec = posix.iovec;
+pub const iovec_const = posix.iovec_const;
+
 pub const STDIN_FILENO = 0;
 pub const STDOUT_FILENO = 1;
 pub const STDERR_FILENO = 2;
lib/std/os/bits/windows.zig
@@ -8,6 +8,11 @@
 usingnamespace @import("../windows/bits.zig");
 const ws2_32 = @import("../windows/ws2_32.zig");
 
+// TODO: Stop using os.iovec in std.fs et al on Windows in the future
+const posix = @import("posix.zig");
+pub const iovec = posix.iovec;
+pub const iovec_const = posix.iovec_const;
+
 pub const fd_t = HANDLE;
 pub const ino_t = LARGE_INTEGER;
 pub const pid_t = HANDLE;
lib/std/os/linux/arm-eabi.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/arm64.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/i386.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/mips.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/powerpc.zig
@@ -4,7 +4,6 @@
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
 
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/powerpc64.zig
@@ -4,7 +4,6 @@
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
 
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/riscv64.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/linux/sparc64.zig
@@ -1,4 +1,3 @@
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall_pipe(fd: *[2]i32) usize {
lib/std/os/linux/thumb.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 // The syscall interface is identical to the ARM one but we're facing an extra
lib/std/os/linux/x86_64.zig
@@ -3,7 +3,6 @@
 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
 // The MIT license requires this copyright notice to be included in all copies
 // and substantial portions of the software.
-usingnamespace @import("../bits.zig");
 usingnamespace @import("../bits/linux.zig");
 
 pub fn syscall0(number: SYS) usize {
lib/std/os/bits.zig
@@ -25,32 +25,3 @@ pub usingnamespace switch (std.Target.current.os.tag) {
 };
 
 pub usingnamespace if (@hasDecl(root, "os") and @hasDecl(root.os, "bits")) root.os.bits else struct {};
-
-pub const iovec = extern struct {
-    iov_base: [*]u8,
-    iov_len: usize,
-};
-
-pub const iovec_const = extern struct {
-    iov_base: [*]const u8,
-    iov_len: usize,
-};
-
-// syslog
-
-/// system is unusable
-pub const LOG_EMERG = 0;
-/// action must be taken immediately
-pub const LOG_ALERT = 1;
-/// critical conditions
-pub const LOG_CRIT = 2;
-/// error conditions
-pub const LOG_ERR = 3;
-/// warning conditions
-pub const LOG_WARNING = 4;
-/// normal but significant condition
-pub const LOG_NOTICE = 5;
-/// informational
-pub const LOG_INFO = 6;
-/// debug-level messages
-pub const LOG_DEBUG = 7;