diff --git a/lib/compiler/resinator/main.zig b/lib/compiler/resinator/main.zig index b01d720c8c..10ffafcfc7 100644 --- a/lib/compiler/resinator/main.zig +++ b/lib/compiler/resinator/main.zig @@ -26,7 +26,7 @@ pub fn main() !void { if (args.len < 2) { try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{}); - std.os.exit(1); + std.process.exit(1); } const zig_lib_dir = args[1]; var cli_args = args[2..]; @@ -62,7 +62,7 @@ pub fn main() !void { var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) { error.ParseError => { try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics); - std.os.exit(1); + std.process.exit(1); }, else => |e| return e, }; @@ -117,7 +117,7 @@ pub fn main() !void { }, } try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{}); - std.os.exit(1); + std.process.exit(1); }, }; @@ -153,16 +153,16 @@ pub fn main() !void { preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) { error.GeneratedSourceError => { try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp); - std.os.exit(1); + std.process.exit(1); }, // ArgError can occur if e.g. the .rc file is not found error.ArgError, error.PreprocessError => { try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp); - std.os.exit(1); + std.process.exit(1); }, error.StreamTooLong => { try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{}); - std.os.exit(1); + std.process.exit(1); }, error.OutOfMemory => |e| return e, }; @@ -171,7 +171,7 @@ pub fn main() !void { } else { break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| { try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) }); - std.os.exit(1); + std.process.exit(1); }; } }; @@ -191,14 +191,14 @@ pub fn main() !void { const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) { error.InvalidSourceMappingCollapse => { try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{}); - std.os.exit(1); + std.process.exit(1); }, else => |e| return e, }; var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| { try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) }); - std.os.exit(1); + std.process.exit(1); }; var output_file_closed = false; defer if (!output_file_closed) output_file.close(); @@ -231,7 +231,7 @@ pub fn main() !void { output_file_closed = true; // Failing to delete is not really a big deal, so swallow any errors std.fs.cwd().deleteFile(options.output_filename) catch {}; - std.os.exit(1); + std.process.exit(1); }, else => |e| return e, }; @@ -247,7 +247,7 @@ pub fn main() !void { if (options.depfile_path) |depfile_path| { var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| { try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) }); - std.os.exit(1); + std.process.exit(1); }; defer depfile.close(); diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig index 95558787ae..c7533dce92 100644 --- a/lib/std/c/wasi.zig +++ b/lib/std/c/wasi.zig @@ -8,6 +8,8 @@ pub fn _errno() *c_int { return &errno; } +pub const PATH_MAX = 4096; + pub const mode_t = u32; pub const time_t = i64; diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 06b9cf3e12..109ce7fe23 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -53,14 +53,12 @@ pub const MAX_PATH_BYTES = max_path_bytes; /// * On other platforms, `[]u8` file paths are opaque sequences of bytes with /// no particular encoding. pub const max_path_bytes = switch (native_os) { - .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten => posix.PATH_MAX, + .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi => posix.PATH_MAX, // Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes. // If it would require 4 WTF-8 bytes, then there would be a surrogate // pair in the WTF-16LE, and we (over)account 3 bytes for it that way. // +1 for the null byte at the end, which can be encoded in 1 byte. .windows => windows.PATH_MAX_WIDE * 3 + 1, - // TODO work out what a reasonable value we should use here - .wasi => 4096, else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX")) root.os.PATH_MAX else diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index e6777e2c09..74d91239f8 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2555,7 +2555,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat { return file.stat(); } if (native_os == .wasi and !builtin.link_libc) { - const st = try posix.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true }); + const st = try std.os.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true }); return Stat.fromWasi(st); } const st = try posix.fstatat(self.fd, sub_path, 0); diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 8e15836536..0b5058c5fe 100644 --- a/lib/std/fs/File.zig +++ b/lib/std/fs/File.zig @@ -457,7 +457,7 @@ pub fn stat(self: File) StatError!Stat { } if (builtin.os.tag == .wasi and !builtin.link_libc) { - const st = try posix.fstat_wasi(self.handle); + const st = try std.os.fstat_wasi(self.handle); return Stat.fromWasi(st); } @@ -1004,7 +1004,7 @@ pub fn metadata(self: File) MetadataError!Metadata { .statx = stx, }; }, - .wasi => .{ .stat = try posix.fstat_wasi(self.handle) }, + .wasi => .{ .stat = try std.os.fstat_wasi(self.handle) }, else => .{ .stat = try posix.fstat(self.handle) }, }, }; diff --git a/lib/std/fs/wasi.zig b/lib/std/fs/wasi.zig index 7ed7a75ea9..040dd4ca3e 100644 --- a/lib/std/fs/wasi.zig +++ b/lib/std/fs/wasi.zig @@ -1,6 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -const os = std.os; const mem = std.mem; const math = std.math; const fs = std.fs; @@ -14,10 +13,10 @@ pub const Preopens = struct { // Indexed by file descriptor number. names: []const []const u8, - pub fn find(p: Preopens, name: []const u8) ?os.fd_t { + pub fn find(p: Preopens, name: []const u8) ?std.posix.fd_t { for (p.names, 0..) |elem_name, i| { if (mem.eql(u8, elem_name, name)) { - return @as(os.fd_t, @intCast(i)); + return @intCast(i); } } return null; diff --git a/lib/std/os.zig b/lib/std/os.zig index 9d322ed9bd..53f1bef4fe 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -22,6 +22,7 @@ const elf = std.elf; const fs = std.fs; const dl = @import("dynamic_library.zig"); const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES; +const posix = std.posix; pub const linux = @import("os/linux.zig"); pub const plan9 = @import("os/plan9.zig"); @@ -98,7 +99,6 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool { /// /// Calling this function is usually a bug. pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 { - const posix = std.posix; if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) { @compileError("querying for canonical path of a handle is unsupported on this host"); } @@ -234,3 +234,37 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix. else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above } } + +/// WASI-only. Same as `fstatat` but targeting WASI. +/// `pathname` should be encoded as valid UTF-8. +/// See also `fstatat`. +pub fn fstatat_wasi(dirfd: posix.fd_t, pathname: []const u8, flags: wasi.lookupflags_t) posix.FStatAtError!wasi.filestat_t { + var stat: wasi.filestat_t = undefined; + switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) { + .SUCCESS => return stat, + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .FAULT => unreachable, + .NAMETOOLONG => return error.NameTooLong, + .NOENT => return error.FileNotFound, + .NOTDIR => return error.FileNotFound, + .NOTCAPABLE => return error.AccessDenied, + .ILSEQ => return error.InvalidUtf8, + else => |err| return posix.unexpectedErrno(err), + } +} + +pub fn fstat_wasi(fd: posix.fd_t) posix.FStatError!wasi.filestat_t { + var stat: wasi.filestat_t = undefined; + switch (wasi.fd_filestat_get(fd, &stat)) { + .SUCCESS => return stat, + .INVAL => unreachable, + .BADF => unreachable, // Always a race condition. + .NOMEM => return error.SystemResources, + .ACCES => return error.AccessDenied, + .NOTCAPABLE => return error.AccessDenied, + else => |err| return posix.unexpectedErrno(err), + } +} diff --git a/lib/std/os/linux/start_pie.zig b/lib/std/os/linux/start_pie.zig index cf557f9d66..b576134042 100644 --- a/lib/std/os/linux/start_pie.zig +++ b/lib/std/os/linux/start_pie.zig @@ -81,7 +81,7 @@ pub fn relocate(phdrs: []elf.Phdr) void { break :base @intFromPtr(dynv) - phdr.p_vaddr; } // This is not supposed to happen for well-formed binaries. - std.os.abort(); + @trap(); }; var rel_addr: usize = 0; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index a5f8641ed6..6d70b79a4c 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -1635,7 +1635,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE errdefer close(fd); if (flags.write) { - const info = try fstat_wasi(fd); + const info = try std.os.fstat_wasi(fd); if (info.filetype == .DIRECTORY) return error.IsDir; } @@ -4282,7 +4282,7 @@ pub const FStatError = error{ /// Return information about a file descriptor. pub fn fstat(fd: fd_t) FStatError!Stat { if (native_os == .wasi and !builtin.link_libc) { - return Stat.fromFilestat(try fstat_wasi(fd)); + return Stat.fromFilestat(try std.os.fstat_wasi(fd)); } if (native_os == .windows) { @compileError("fstat is not yet implemented on Windows"); @@ -4300,19 +4300,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat { } } -fn fstat_wasi(fd: fd_t) FStatError!wasi.filestat_t { - var stat: wasi.filestat_t = undefined; - switch (wasi.fd_filestat_get(fd, &stat)) { - .SUCCESS => return stat, - .INVAL => unreachable, - .BADF => unreachable, // Always a race condition. - .NOMEM => return error.SystemResources, - .ACCES => return error.AccessDenied, - .NOTCAPABLE => return error.AccessDenied, - else => |err| return unexpectedErrno(err), - } -} - pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound, @@ -4325,10 +4312,10 @@ pub const FStatAtError = FStatError || error{ /// which is relative to `dirfd` handle. /// On WASI, `pathname` should be encoded as valid UTF-8. /// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding. -/// See also `fstatatZ` and `fstatat_wasi`. +/// See also `fstatatZ` and `std.os.fstatat_wasi`. pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat { if (native_os == .wasi and !builtin.link_libc) { - const filestat = try fstatat_wasi(dirfd, pathname, .{ + const filestat = try std.os.fstatat_wasi(dirfd, pathname, .{ .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0, }); return Stat.fromFilestat(filestat); @@ -4344,7 +4331,7 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat /// See also `fstatat`. pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { if (native_os == .wasi and !builtin.link_libc) { - const filestat = try fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{ + const filestat = try std.os.fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{ .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0, }); return Stat.fromFilestat(filestat); @@ -4372,27 +4359,6 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S } } -/// WASI-only. Same as `fstatat` but targeting WASI. -/// `pathname` should be encoded as valid UTF-8. -/// See also `fstatat`. -fn fstatat_wasi(dirfd: fd_t, pathname: []const u8, flags: wasi.lookupflags_t) FStatAtError!wasi.filestat_t { - var stat: wasi.filestat_t = undefined; - switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) { - .SUCCESS => return stat, - .INVAL => unreachable, - .BADF => unreachable, // Always a race condition. - .NOMEM => return error.SystemResources, - .ACCES => return error.AccessDenied, - .FAULT => unreachable, - .NAMETOOLONG => return error.NameTooLong, - .NOENT => return error.FileNotFound, - .NOTDIR => return error.FileNotFound, - .NOTCAPABLE => return error.AccessDenied, - .ILSEQ => return error.InvalidUtf8, - else => |err| return unexpectedErrno(err), - } -} - pub const KQueueError = error{ /// The per-process limit on the number of open file descriptors has been reached. ProcessFdQuotaExceeded, @@ -4822,7 +4788,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path }; const st = blk: { - break :blk fstatat_wasi(dirfd, path, .{ + break :blk std.os.fstatat_wasi(dirfd, path, .{ .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0, }); } catch |err| switch (err) { diff --git a/src/DarwinPosixSpawn.zig b/src/DarwinPosixSpawn.zig index 336848353e..eaca944241 100644 --- a/src/DarwinPosixSpawn.zig +++ b/src/DarwinPosixSpawn.zig @@ -81,7 +81,7 @@ pub const Actions = struct { } pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return self.openZ(fd, &posix_path, flags, mode); } @@ -130,7 +130,7 @@ pub const Actions = struct { } pub fn chdir(self: *Actions, path: []const u8) Error!void { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return self.chdirZ(&posix_path); } @@ -164,7 +164,7 @@ pub fn spawn( argv: [*:null]?[*:0]const u8, envp: [*:null]?[*:0]const u8, ) Error!std.c.pid_t { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return spawnZ(&posix_path, actions, attr, argv, envp); } @@ -204,12 +204,12 @@ pub fn spawnZ( } } -pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult { +pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult { var status: c_int = undefined; while (true) { const rc = waitpid(pid, &status, @as(c_int, @intCast(flags))); switch (errno(rc)) { - .SUCCESS => return std.os.WaitPidResult{ + .SUCCESS => return std.posix.WaitPidResult{ .pid = @as(std.c.pid_t, @intCast(rc)), .status = @as(u32, @bitCast(status)), }, diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 6731f88e43..29ac89d26c 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols { return null; } -pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void { +pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void { if (!is_hot_update_compatible) return; - const mach_task = try std.os.darwin.machTaskForPid(pid); + const mach_task = try std.c.machTaskForPid(pid); log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task }); self.hot_state.mach_task = mach_task; @@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void { // try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0); } -pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void { +pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void { if (!is_hot_update_compatible) return; _ = pid; @@ -4330,7 +4330,7 @@ const Section = struct { }; const HotUpdateState = struct { - mach_task: ?std.os.darwin.MachTask = null, + mach_task: ?std.c.MachTask = null, }; pub const DynamicRelocs = struct { diff --git a/src/main.zig b/src/main.zig index 4609109d15..be2083a0f8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -12,6 +12,7 @@ const Color = std.zig.Color; const warn = std.log.warn; const ThreadPool = std.Thread.Pool; const cleanExit = std.process.cleanExit; +const native_os = builtin.os.tag; const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); @@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ pub fn main() anyerror!void { crash_report.initialize(); - const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi; + const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi; const gpa = gpa: { - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { break :gpa std.heap.wasm_allocator; } if (use_gpa) { @@ -187,7 +188,7 @@ pub fn main() anyerror!void { return mainArgs(gpa_tracy.allocator(), arena, args); } - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { wasi_preopens = try fs.wasi.preopensAlloc(arena); } @@ -813,9 +814,9 @@ fn buildOutputType( var no_builtin = false; var listen: Listen = .none; var debug_compile_errors = false; - var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_link = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_LINK.isSet(); - var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_cc = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_CC.isSet(); var verbose_air = false; var verbose_intern_pool = false; @@ -991,7 +992,7 @@ fn buildOutputType( // if it exists, default the color setting to .off // explicit --color arguments will still override this setting. // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 - var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto; + var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto; switch (arg_mode) { .build, .translate_c, .zig_test, .run => { @@ -2684,7 +2685,7 @@ fn buildOutputType( fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) }); }, }; - } else if (builtin.os.tag == .wasi) { + } else if (native_os == .wasi) { break :d getWasiPreopen("/lib"); } else if (self_exe_path) |p| { break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| { @@ -2703,7 +2704,7 @@ fn buildOutputType( .path = p, }; } - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { break :l getWasiPreopen("/cache"); } const p = try introspect.resolveGlobalCacheDir(arena); @@ -4368,7 +4369,7 @@ fn runOrTest( } } else { const cmd = try std.mem.join(arena, " ", argv.items); - fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); + fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); } } @@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var child_argv = std.ArrayList([]const u8).init(arena); var reference_trace: ?u32 = null; var debug_compile_errors = false; - var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_link = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_LINK.isSet(); - var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_cc = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_CC.isSet(); var verbose_air = false; var verbose_intern_pool = false; @@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } } - const work_around_btrfs_bug = builtin.os.tag == .linux and + const work_around_btrfs_bug = native_os == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); const color: Color = .auto; @@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } } else { const cmd = try std.mem.join(arena, " ", child_argv.items); - fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); + fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); } } } @@ -5543,7 +5544,7 @@ fn jitCmd( if (!process.can_spawn) { const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ - @tagName(builtin.os.tag), cmd, + @tagName(native_os), cmd, }); } @@ -5655,7 +5656,7 @@ pub fn lldMain( var count: usize = 0; }; if (CallCounter.count == 1) { // Issue the warning on the first repeat call - warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(builtin.os.tag)}); + warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(native_os)}); } CallCounter.count += 1; @@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel { /// garbage collector to run concurrently to zig processes, and to allow multiple /// zig processes to run concurrently with each other, without clobbering each other. fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { - const have_rlimit = switch (builtin.os.tag) { + const have_rlimit = switch (native_os) { .windows, .wasi => false, else => true, }; @@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { const posix = std.posix; var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. - if (comptime builtin.target.isDarwin()) { + if (native_os.isDarwin()) { // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`. // According to the man pages for setrlimit(): // setrlimit() now returns with errno set to EINVAL in places that historically succeeded. // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE. // Use "rlim_cur = min(OPEN_MAX, rlim_max)". - lim.max = @min(std.os.darwin.OPEN_MAX, lim.max); + lim.max = @min(std.c.OPEN_MAX, lim.max); } if (lim.cur == lim.max) return; @@ -6770,7 +6771,7 @@ fn cmdFetch( args: []const []const u8, ) !void { const color: Color = .auto; - const work_around_btrfs_bug = builtin.os.tag == .linux and + const work_around_btrfs_bug = native_os == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); var opt_path_or_url: ?[]const u8 = null; var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); diff --git a/test/cases/arithmetic_operations.0.zig b/test/cases/arithmetic_operations.0.zig index 405c19d86a..ea22e22216 100644 --- a/test/cases/arithmetic_operations.0.zig +++ b/test/cases/arithmetic_operations.0.zig @@ -8,7 +8,7 @@ pub fn main() void { fn print(a: u32, b: u32) void { const str = "123456789"; const len = a + b; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/arithmetic_operations.1.zig b/test/cases/arithmetic_operations.1.zig index ba2520abe9..31f77317d5 100644 --- a/test/cases/arithmetic_operations.1.zig +++ b/test/cases/arithmetic_operations.1.zig @@ -8,7 +8,7 @@ pub fn main() void { fn print(a: u32, b: u32) void { const str = "123456789"; const len = a - b; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/arithmetic_operations.2.zig b/test/cases/arithmetic_operations.2.zig index be4ec466f1..4ef5bec8d6 100644 --- a/test/cases/arithmetic_operations.2.zig +++ b/test/cases/arithmetic_operations.2.zig @@ -8,7 +8,7 @@ pub fn main() void { fn print(a: u32, b: u32) void { const str = "123456789"; const len = a & b; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/arithmetic_operations.3.zig b/test/cases/arithmetic_operations.3.zig index b939950730..a16fdbc2d1 100644 --- a/test/cases/arithmetic_operations.3.zig +++ b/test/cases/arithmetic_operations.3.zig @@ -8,7 +8,7 @@ pub fn main() void { fn print(a: u32, b: u32) void { const str = "123456789"; const len = a | b; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/arithmetic_operations.4.zig b/test/cases/arithmetic_operations.4.zig index 50bf0df0ce..5037ad7485 100644 --- a/test/cases/arithmetic_operations.4.zig +++ b/test/cases/arithmetic_operations.4.zig @@ -8,7 +8,7 @@ pub fn main() void { fn print(a: u32, b: u32) void { const str = "123456789"; const len = a ^ b; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/errors.0.zig b/test/cases/errors.0.zig index 5e6940ac3e..f61ebc42b7 100644 --- a/test/cases/errors.0.zig +++ b/test/cases/errors.0.zig @@ -7,7 +7,7 @@ pub fn main() void { fn foo() anyerror!void {} fn print() void { - _ = std.os.write(1, "Hello, World!\n") catch {}; + _ = std.posix.write(1, "Hello, World!\n") catch {}; } // run diff --git a/test/cases/errors.1.zig b/test/cases/errors.1.zig index 5f9582df8a..ead3262f84 100644 --- a/test/cases/errors.1.zig +++ b/test/cases/errors.1.zig @@ -9,7 +9,7 @@ fn foo() anyerror!void { } fn print() void { - _ = std.os.write(1, "Hello, World!\n") catch {}; + _ = std.posix.write(1, "Hello, World!\n") catch {}; } // run diff --git a/test/cases/function_pointers.zig b/test/cases/function_pointers.zig index d48dc0da95..546eef72a4 100644 --- a/test/cases/function_pointers.zig +++ b/test/cases/function_pointers.zig @@ -12,11 +12,11 @@ pub fn main() void { } fn stopSayingThat() void { - _ = std.os.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {}; + _ = std.posix.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {}; } fn moveEveryZig() void { - _ = std.os.write(1, "All your codebase are belong to us\n") catch {}; + _ = std.posix.write(1, "All your codebase are belong to us\n") catch {}; } // run diff --git a/test/cases/parameters_and_return_values.0.zig b/test/cases/parameters_and_return_values.0.zig index 45f0813e3d..bf07cf2921 100644 --- a/test/cases/parameters_and_return_values.0.zig +++ b/test/cases/parameters_and_return_values.0.zig @@ -10,7 +10,7 @@ fn id(x: u32) u32 { fn print(len: u32) void { const str = "Hello, World!\n"; - _ = std.os.write(1, str[0..len]) catch {}; + _ = std.posix.write(1, str[0..len]) catch {}; } // run diff --git a/test/cases/print_u32s.zig b/test/cases/print_u32s.zig index f50e85d0aa..0c73361278 100644 --- a/test/cases/print_u32s.zig +++ b/test/cases/print_u32s.zig @@ -12,10 +12,10 @@ fn printNumberHex(x: u32) void { var i: u5 = 28; while (true) : (i -= 4) { const digit = (x >> i) & 0xf; - _ = std.os.write(1, &.{digit_chars[digit]}) catch {}; + _ = std.posix.write(1, &.{digit_chars[digit]}) catch {}; if (i == 0) break; } - _ = std.os.write(1, "\n") catch {}; + _ = std.posix.write(1, "\n") catch {}; } // run diff --git a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig index 8970e06516..f8bf6d44c0 100644 --- a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +++ b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig @@ -11,21 +11,21 @@ fn foo() void { } var f = async bar(@frame()); _ = &f; - std.os.exit(1); + std.process.exit(1); } fn bar(frame: anyframe) void { suspend { resume frame; } - std.os.exit(1); + std.process.exit(1); } var global_frame: anyframe = undefined; pub fn main() !void { _ = async foo(); resume global_frame; - std.os.exit(1); + std.process.exit(1); } // run // backend=stage1 diff --git a/test/cases/safety/resuming a non-suspended function which never been suspended.zig b/test/cases/safety/resuming a non-suspended function which never been suspended.zig index 420da72a5c..af288ab8ba 100644 --- a/test/cases/safety/resuming a non-suspended function which never been suspended.zig +++ b/test/cases/safety/resuming a non-suspended function which never been suspended.zig @@ -8,14 +8,14 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi fn foo() void { var f = async bar(@frame()); _ = &f; - std.os.exit(1); + std.process.exit(1); } fn bar(frame: anyframe) void { suspend { resume frame; } - std.os.exit(1); + std.process.exit(1); } pub fn main() !void { diff --git a/test/link/glibc_compat/glibc_runtime_check.zig b/test/link/glibc_compat/glibc_runtime_check.zig index 7344bafc6e..3dc1548379 100644 --- a/test/link/glibc_compat/glibc_runtime_check.zig +++ b/test/link/glibc_compat/glibc_runtime_check.zig @@ -30,11 +30,11 @@ fn checkStat() !void { var stat = std.mem.zeroes(std.c.Stat); var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0); assert(result == -1); - assert(std.c.getErrno(result) == .NOENT); + assert(std.posix.errno(result) == .NOENT); result = std.c.stat("a_file_that_definitely_does_not_exist", &stat); assert(result == -1); - assert(std.c.getErrno(result) == .NOENT); + assert(std.posix.errno(result) == .NOENT); } // PR #17607 - reallocarray not visible in headers diff --git a/test/standalone/sigpipe/breakpipe.zig b/test/standalone/sigpipe/breakpipe.zig index d4d123c317..044a2bc65f 100644 --- a/test/standalone/sigpipe/breakpipe.zig +++ b/test/standalone/sigpipe/breakpipe.zig @@ -1,19 +1,17 @@ const std = @import("std"); const build_options = @import("build_options"); -pub usingnamespace if (build_options.keep_sigpipe) struct { - pub const std_options = .{ - .keep_sigpipe = true, - }; -} else struct {}; +pub const std_options = .{ + .keep_sigpipe = build_options.keep_sigpipe, +}; pub fn main() !void { - const pipe = try std.os.pipe(); - std.os.close(pipe[0]); - _ = std.os.write(pipe[1], "a") catch |err| switch (err) { + const pipe = try std.posix.pipe(); + std.posix.close(pipe[0]); + _ = std.posix.write(pipe[1], "a") catch |err| switch (err) { error.BrokenPipe => { try std.io.getStdOut().writer().writeAll("BrokenPipe\n"); - std.os.exit(123); + std.posix.exit(123); }, else => |e| return e, }; diff --git a/test/standalone/sigpipe/build.zig b/test/standalone/sigpipe/build.zig index 6f50a86d68..07005795e2 100644 --- a/test/standalone/sigpipe/build.zig +++ b/test/standalone/sigpipe/build.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const os = std.os; +const posix = std.posix; pub fn build(b: *std.build.Builder) !void { const test_step = b.step("test", "Test it"); @@ -16,12 +16,12 @@ pub fn build(b: *std.build.Builder) !void { // This test runs "breakpipe" as a child process and that process // depends on inheriting a SIGPIPE disposition of "default". { - const act = os.Sigaction{ - .handler = .{ .handler = os.SIG.DFL }, - .mask = os.empty_sigset, + const act = posix.Sigaction{ + .handler = .{ .handler = posix.SIG.DFL }, + .mask = posix.empty_sigset, .flags = 0, }; - try os.sigaction(os.SIG.PIPE, &act, null); + try posix.sigaction(posix.SIG.PIPE, &act, null); } for ([_]bool{ false, true }) |keep_sigpipe| { @@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void { exe.addOptions("build_options", options); const run = b.addRunArtifact(exe); if (keep_sigpipe) { - run.addCheck(.{ .expect_term = .{ .Signal = std.os.SIG.PIPE } }); + run.addCheck(.{ .expect_term = .{ .Signal = std.posix.SIG.PIPE } }); } else { run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" }); run.addCheck(.{ .expect_term = .{ .Exited = 123 } }); diff --git a/test/standalone/windows_spawn/main.zig b/test/standalone/windows_spawn/main.zig index 13d60467a9..cfc8caf18b 100644 --- a/test/standalone/windows_spawn/main.zig +++ b/test/standalone/windows_spawn/main.zig @@ -25,13 +25,13 @@ pub fn main() anyerror!void { defer allocator.free(tmp_relative_path); // Clear PATH - std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW( + std.debug.assert(windows.kernel32.SetEnvironmentVariableW( utf16Literal("PATH"), null, ) == windows.TRUE); // Set PATHEXT to something predictable - std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW( + std.debug.assert(windows.kernel32.SetEnvironmentVariableW( utf16Literal("PATHEXT"), utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"), ) == windows.TRUE); @@ -39,7 +39,7 @@ pub fn main() anyerror!void { // No PATH, so it should fail to find anything not in the cwd try testExecError(error.FileNotFound, allocator, "something_missing"); - std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW( + std.debug.assert(windows.kernel32.SetEnvironmentVariableW( utf16Literal("PATH"), tmp_absolute_path_w, ) == windows.TRUE); @@ -120,7 +120,7 @@ pub fn main() anyerror!void { const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0); defer allocator.free(something_subdir_abs_path); - std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW( + std.debug.assert(windows.kernel32.SetEnvironmentVariableW( utf16Literal("PATH"), something_subdir_abs_path, ) == windows.TRUE);