authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-18 23:59:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-19 16:18:18-07:00
log8c94950c2496a5fa69f35b0f06f221e2c12339cf
treeab80d1a4f48e7401ad04dfb7855ad654e3761f63
parent6b2899df2ad5ad139ebcadd7e42762b095853be4

fix compilation failures found by CI


28 files changed, 126 insertions(+), 128 deletions(-)

lib/compiler/resinator/main.zig+11-11
......@@ -26,7 +26,7 @@ pub fn main() !void {
2626
2727 if (args.len < 2) {
2828 try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{});
29 std.os.exit(1);
29 std.process.exit(1);
3030 }
3131 const zig_lib_dir = args[1];
3232 var cli_args = args[2..];
......@@ -62,7 +62,7 @@ pub fn main() !void {
6262 var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) {
6363 error.ParseError => {
6464 try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics);
65 std.os.exit(1);
65 std.process.exit(1);
6666 },
6767 else => |e| return e,
6868 };
......@@ -117,7 +117,7 @@ pub fn main() !void {
117117 },
118118 }
119119 try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{});
120 std.os.exit(1);
120 std.process.exit(1);
121121 },
122122 };
123123
......@@ -153,16 +153,16 @@ pub fn main() !void {
153153 preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) {
154154 error.GeneratedSourceError => {
155155 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp);
156 std.os.exit(1);
156 std.process.exit(1);
157157 },
158158 // ArgError can occur if e.g. the .rc file is not found
159159 error.ArgError, error.PreprocessError => {
160160 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp);
161 std.os.exit(1);
161 std.process.exit(1);
162162 },
163163 error.StreamTooLong => {
164164 try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{});
165 std.os.exit(1);
165 std.process.exit(1);
166166 },
167167 error.OutOfMemory => |e| return e,
168168 };
......@@ -171,7 +171,7 @@ pub fn main() !void {
171171 } else {
172172 break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| {
173173 try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) });
174 std.os.exit(1);
174 std.process.exit(1);
175175 };
176176 }
177177 };
......@@ -191,14 +191,14 @@ pub fn main() !void {
191191 const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) {
192192 error.InvalidSourceMappingCollapse => {
193193 try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{});
194 std.os.exit(1);
194 std.process.exit(1);
195195 },
196196 else => |e| return e,
197197 };
198198
199199 var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {
200200 try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });
201 std.os.exit(1);
201 std.process.exit(1);
202202 };
203203 var output_file_closed = false;
204204 defer if (!output_file_closed) output_file.close();
......@@ -231,7 +231,7 @@ pub fn main() !void {
231231 output_file_closed = true;
232232 // Failing to delete is not really a big deal, so swallow any errors
233233 std.fs.cwd().deleteFile(options.output_filename) catch {};
234 std.os.exit(1);
234 std.process.exit(1);
235235 },
236236 else => |e| return e,
237237 };
......@@ -247,7 +247,7 @@ pub fn main() !void {
247247 if (options.depfile_path) |depfile_path| {
248248 var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {
249249 try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
250 std.os.exit(1);
250 std.process.exit(1);
251251 };
252252 defer depfile.close();
253253
lib/std/c/wasi.zig+2
......@@ -8,6 +8,8 @@ pub fn _errno() *c_int {
88 return &errno;
99}
1010
11pub const PATH_MAX = 4096;
12
1113pub const mode_t = u32;
1214pub const time_t = i64;
1315
lib/std/fs.zig+1-3
......@@ -53,14 +53,12 @@ pub const MAX_PATH_BYTES = max_path_bytes;
5353/// * On other platforms, `[]u8` file paths are opaque sequences of bytes with
5454/// no particular encoding.
5555pub const max_path_bytes = switch (native_os) {
56 .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten => posix.PATH_MAX,
56 .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi => posix.PATH_MAX,
5757 // Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes.
5858 // If it would require 4 WTF-8 bytes, then there would be a surrogate
5959 // pair in the WTF-16LE, and we (over)account 3 bytes for it that way.
6060 // +1 for the null byte at the end, which can be encoded in 1 byte.
6161 .windows => windows.PATH_MAX_WIDE * 3 + 1,
62 // TODO work out what a reasonable value we should use here
63 .wasi => 4096,
6462 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX"))
6563 root.os.PATH_MAX
6664 else
lib/std/fs/Dir.zig+1-1
......@@ -2555,7 +2555,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
25552555 return file.stat();
25562556 }
25572557 if (native_os == .wasi and !builtin.link_libc) {
2558 const st = try posix.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
2558 const st = try std.os.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
25592559 return Stat.fromWasi(st);
25602560 }
25612561 const st = try posix.fstatat(self.fd, sub_path, 0);
lib/std/fs/File.zig+2-2
......@@ -457,7 +457,7 @@ pub fn stat(self: File) StatError!Stat {
457457 }
458458
459459 if (builtin.os.tag == .wasi and !builtin.link_libc) {
460 const st = try posix.fstat_wasi(self.handle);
460 const st = try std.os.fstat_wasi(self.handle);
461461 return Stat.fromWasi(st);
462462 }
463463
......@@ -1004,7 +1004,7 @@ pub fn metadata(self: File) MetadataError!Metadata {
10041004 .statx = stx,
10051005 };
10061006 },
1007 .wasi => .{ .stat = try posix.fstat_wasi(self.handle) },
1007 .wasi => .{ .stat = try std.os.fstat_wasi(self.handle) },
10081008 else => .{ .stat = try posix.fstat(self.handle) },
10091009 },
10101010 };
lib/std/fs/wasi.zig+2-3
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const os = std.os;
43const mem = std.mem;
54const math = std.math;
65const fs = std.fs;
......@@ -14,10 +13,10 @@ pub const Preopens = struct {
1413 // Indexed by file descriptor number.
1514 names: []const []const u8,
1615
17 pub fn find(p: Preopens, name: []const u8) ?os.fd_t {
16 pub fn find(p: Preopens, name: []const u8) ?std.posix.fd_t {
1817 for (p.names, 0..) |elem_name, i| {
1918 if (mem.eql(u8, elem_name, name)) {
20 return @as(os.fd_t, @intCast(i));
19 return @intCast(i);
2120 }
2221 }
2322 return null;
lib/std/os.zig+35-1
......@@ -22,6 +22,7 @@ const elf = std.elf;
2222const fs = std.fs;
2323const dl = @import("dynamic_library.zig");
2424const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
25const posix = std.posix;
2526
2627pub const linux = @import("os/linux.zig");
2728pub const plan9 = @import("os/plan9.zig");
......@@ -98,7 +99,6 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool {
9899///
99100/// Calling this function is usually a bug.
100101pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 {
101 const posix = std.posix;
102102 if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
103103 @compileError("querying for canonical path of a handle is unsupported on this host");
104104 }
......@@ -234,3 +234,37 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.
234234 else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above
235235 }
236236}
237
238/// WASI-only. Same as `fstatat` but targeting WASI.
239/// `pathname` should be encoded as valid UTF-8.
240/// See also `fstatat`.
241pub fn fstatat_wasi(dirfd: posix.fd_t, pathname: []const u8, flags: wasi.lookupflags_t) posix.FStatAtError!wasi.filestat_t {
242 var stat: wasi.filestat_t = undefined;
243 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
244 .SUCCESS => return stat,
245 .INVAL => unreachable,
246 .BADF => unreachable, // Always a race condition.
247 .NOMEM => return error.SystemResources,
248 .ACCES => return error.AccessDenied,
249 .FAULT => unreachable,
250 .NAMETOOLONG => return error.NameTooLong,
251 .NOENT => return error.FileNotFound,
252 .NOTDIR => return error.FileNotFound,
253 .NOTCAPABLE => return error.AccessDenied,
254 .ILSEQ => return error.InvalidUtf8,
255 else => |err| return posix.unexpectedErrno(err),
256 }
257}
258
259pub fn fstat_wasi(fd: posix.fd_t) posix.FStatError!wasi.filestat_t {
260 var stat: wasi.filestat_t = undefined;
261 switch (wasi.fd_filestat_get(fd, &stat)) {
262 .SUCCESS => return stat,
263 .INVAL => unreachable,
264 .BADF => unreachable, // Always a race condition.
265 .NOMEM => return error.SystemResources,
266 .ACCES => return error.AccessDenied,
267 .NOTCAPABLE => return error.AccessDenied,
268 else => |err| return posix.unexpectedErrno(err),
269 }
270}
lib/std/os/linux/start_pie.zig+1-1
......@@ -81,7 +81,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {
8181 break :base @intFromPtr(dynv) - phdr.p_vaddr;
8282 }
8383 // This is not supposed to happen for well-formed binaries.
84 std.os.abort();
84 @trap();
8585 };
8686
8787 var rel_addr: usize = 0;
lib/std/posix.zig+6-40
......@@ -1635,7 +1635,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE
16351635 errdefer close(fd);
16361636
16371637 if (flags.write) {
1638 const info = try fstat_wasi(fd);
1638 const info = try std.os.fstat_wasi(fd);
16391639 if (info.filetype == .DIRECTORY)
16401640 return error.IsDir;
16411641 }
......@@ -4282,7 +4282,7 @@ pub const FStatError = error{
42824282/// Return information about a file descriptor.
42834283pub fn fstat(fd: fd_t) FStatError!Stat {
42844284 if (native_os == .wasi and !builtin.link_libc) {
4285 return Stat.fromFilestat(try fstat_wasi(fd));
4285 return Stat.fromFilestat(try std.os.fstat_wasi(fd));
42864286 }
42874287 if (native_os == .windows) {
42884288 @compileError("fstat is not yet implemented on Windows");
......@@ -4300,19 +4300,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
43004300 }
43014301}
43024302
4303fn fstat_wasi(fd: fd_t) FStatError!wasi.filestat_t {
4304 var stat: wasi.filestat_t = undefined;
4305 switch (wasi.fd_filestat_get(fd, &stat)) {
4306 .SUCCESS => return stat,
4307 .INVAL => unreachable,
4308 .BADF => unreachable, // Always a race condition.
4309 .NOMEM => return error.SystemResources,
4310 .ACCES => return error.AccessDenied,
4311 .NOTCAPABLE => return error.AccessDenied,
4312 else => |err| return unexpectedErrno(err),
4313 }
4314}
4315
43164303pub const FStatAtError = FStatError || error{
43174304 NameTooLong,
43184305 FileNotFound,
......@@ -4325,10 +4312,10 @@ pub const FStatAtError = FStatError || error{
43254312/// which is relative to `dirfd` handle.
43264313/// On WASI, `pathname` should be encoded as valid UTF-8.
43274314/// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding.
4328/// See also `fstatatZ` and `fstatat_wasi`.
4315/// See also `fstatatZ` and `std.os.fstatat_wasi`.
43294316pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
43304317 if (native_os == .wasi and !builtin.link_libc) {
4331 const filestat = try fstatat_wasi(dirfd, pathname, .{
4318 const filestat = try std.os.fstatat_wasi(dirfd, pathname, .{
43324319 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
43334320 });
43344321 return Stat.fromFilestat(filestat);
......@@ -4344,7 +4331,7 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat
43444331/// See also `fstatat`.
43454332pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
43464333 if (native_os == .wasi and !builtin.link_libc) {
4347 const filestat = try fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{
4334 const filestat = try std.os.fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{
43484335 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
43494336 });
43504337 return Stat.fromFilestat(filestat);
......@@ -4372,27 +4359,6 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
43724359 }
43734360}
43744361
4375/// WASI-only. Same as `fstatat` but targeting WASI.
4376/// `pathname` should be encoded as valid UTF-8.
4377/// See also `fstatat`.
4378fn fstatat_wasi(dirfd: fd_t, pathname: []const u8, flags: wasi.lookupflags_t) FStatAtError!wasi.filestat_t {
4379 var stat: wasi.filestat_t = undefined;
4380 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
4381 .SUCCESS => return stat,
4382 .INVAL => unreachable,
4383 .BADF => unreachable, // Always a race condition.
4384 .NOMEM => return error.SystemResources,
4385 .ACCES => return error.AccessDenied,
4386 .FAULT => unreachable,
4387 .NAMETOOLONG => return error.NameTooLong,
4388 .NOENT => return error.FileNotFound,
4389 .NOTDIR => return error.FileNotFound,
4390 .NOTCAPABLE => return error.AccessDenied,
4391 .ILSEQ => return error.InvalidUtf8,
4392 else => |err| return unexpectedErrno(err),
4393 }
4394}
4395
43964362pub const KQueueError = error{
43974363 /// The per-process limit on the number of open file descriptors has been reached.
43984364 ProcessFdQuotaExceeded,
......@@ -4822,7 +4788,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
48224788 const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path };
48234789
48244790 const st = blk: {
4825 break :blk fstatat_wasi(dirfd, path, .{
4791 break :blk std.os.fstatat_wasi(dirfd, path, .{
48264792 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
48274793 });
48284794 } catch |err| switch (err) {
src/DarwinPosixSpawn.zig+5-5
......@@ -81,7 +81,7 @@ pub const Actions = struct {
8181 }
8282
8383 pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {
84 const posix_path = try std.os.toPosixPath(path);
84 const posix_path = try std.posix.toPosixPath(path);
8585 return self.openZ(fd, &posix_path, flags, mode);
8686 }
8787
......@@ -130,7 +130,7 @@ pub const Actions = struct {
130130 }
131131
132132 pub fn chdir(self: *Actions, path: []const u8) Error!void {
133 const posix_path = try std.os.toPosixPath(path);
133 const posix_path = try std.posix.toPosixPath(path);
134134 return self.chdirZ(&posix_path);
135135 }
136136
......@@ -164,7 +164,7 @@ pub fn spawn(
164164 argv: [*:null]?[*:0]const u8,
165165 envp: [*:null]?[*:0]const u8,
166166) Error!std.c.pid_t {
167 const posix_path = try std.os.toPosixPath(path);
167 const posix_path = try std.posix.toPosixPath(path);
168168 return spawnZ(&posix_path, actions, attr, argv, envp);
169169}
170170
......@@ -204,12 +204,12 @@ pub fn spawnZ(
204204 }
205205}
206206
207pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult {
207pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult {
208208 var status: c_int = undefined;
209209 while (true) {
210210 const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
211211 switch (errno(rc)) {
212 .SUCCESS => return std.os.WaitPidResult{
212 .SUCCESS => return std.posix.WaitPidResult{
213213 .pid = @as(std.c.pid_t, @intCast(rc)),
214214 .status = @as(u32, @bitCast(status)),
215215 },
src/link/MachO.zig+4-4
......@@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
41364136 return null;
41374137}
41384138
4139pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
4139pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void {
41404140 if (!is_hot_update_compatible) return;
41414141
4142 const mach_task = try std.os.darwin.machTaskForPid(pid);
4142 const mach_task = try std.c.machTaskForPid(pid);
41434143 log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });
41444144 self.hot_state.mach_task = mach_task;
41454145
......@@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
41494149 // try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);
41504150}
41514151
4152pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void {
4152pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void {
41534153 if (!is_hot_update_compatible) return;
41544154
41554155 _ = pid;
......@@ -4330,7 +4330,7 @@ const Section = struct {
43304330};
43314331
43324332const HotUpdateState = struct {
4333 mach_task: ?std.os.darwin.MachTask = null,
4333 mach_task: ?std.c.MachTask = null,
43344334};
43354335
43364336pub const DynamicRelocs = struct {
src/main.zig+20-19
......@@ -12,6 +12,7 @@ const Color = std.zig.Color;
1212const warn = std.log.warn;
1313const ThreadPool = std.Thread.Pool;
1414const cleanExit = std.process.cleanExit;
15const native_os = builtin.os.tag;
1516
1617const tracy = @import("tracy.zig");
1718const Compilation = @import("Compilation.zig");
......@@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{
158159pub fn main() anyerror!void {
159160 crash_report.initialize();
160161
161 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;
162 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi;
162163 const gpa = gpa: {
163 if (builtin.os.tag == .wasi) {
164 if (native_os == .wasi) {
164165 break :gpa std.heap.wasm_allocator;
165166 }
166167 if (use_gpa) {
......@@ -187,7 +188,7 @@ pub fn main() anyerror!void {
187188 return mainArgs(gpa_tracy.allocator(), arena, args);
188189 }
189190
190 if (builtin.os.tag == .wasi) {
191 if (native_os == .wasi) {
191192 wasi_preopens = try fs.wasi.preopensAlloc(arena);
192193 }
193194
......@@ -813,9 +814,9 @@ fn buildOutputType(
813814 var no_builtin = false;
814815 var listen: Listen = .none;
815816 var debug_compile_errors = false;
816 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
817 var verbose_link = (native_os != .wasi or builtin.link_libc) and
817818 EnvVar.ZIG_VERBOSE_LINK.isSet();
818 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
819 var verbose_cc = (native_os != .wasi or builtin.link_libc) and
819820 EnvVar.ZIG_VERBOSE_CC.isSet();
820821 var verbose_air = false;
821822 var verbose_intern_pool = false;
......@@ -991,7 +992,7 @@ fn buildOutputType(
991992 // if it exists, default the color setting to .off
992993 // explicit --color arguments will still override this setting.
993994 // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
994 var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
995 var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
995996
996997 switch (arg_mode) {
997998 .build, .translate_c, .zig_test, .run => {
......@@ -2684,7 +2685,7 @@ fn buildOutputType(
26842685 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
26852686 },
26862687 };
2687 } else if (builtin.os.tag == .wasi) {
2688 } else if (native_os == .wasi) {
26882689 break :d getWasiPreopen("/lib");
26892690 } else if (self_exe_path) |p| {
26902691 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
......@@ -2703,7 +2704,7 @@ fn buildOutputType(
27032704 .path = p,
27042705 };
27052706 }
2706 if (builtin.os.tag == .wasi) {
2707 if (native_os == .wasi) {
27072708 break :l getWasiPreopen("/cache");
27082709 }
27092710 const p = try introspect.resolveGlobalCacheDir(arena);
......@@ -4368,7 +4369,7 @@ fn runOrTest(
43684369 }
43694370 } else {
43704371 const cmd = try std.mem.join(arena, " ", argv.items);
4371 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
4372 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
43724373 }
43734374}
43744375
......@@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
47474748 var child_argv = std.ArrayList([]const u8).init(arena);
47484749 var reference_trace: ?u32 = null;
47494750 var debug_compile_errors = false;
4750 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
4751 var verbose_link = (native_os != .wasi or builtin.link_libc) and
47514752 EnvVar.ZIG_VERBOSE_LINK.isSet();
4752 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
4753 var verbose_cc = (native_os != .wasi or builtin.link_libc) and
47534754 EnvVar.ZIG_VERBOSE_CC.isSet();
47544755 var verbose_air = false;
47554756 var verbose_intern_pool = false;
......@@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
48944895 }
48954896 }
48964897
4897 const work_around_btrfs_bug = builtin.os.tag == .linux and
4898 const work_around_btrfs_bug = native_os == .linux and
48984899 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
48994900 const color: Color = .auto;
49004901
......@@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
53115312 }
53125313 } else {
53135314 const cmd = try std.mem.join(arena, " ", child_argv.items);
5314 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
5315 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
53155316 }
53165317 }
53175318}
......@@ -5543,7 +5544,7 @@ fn jitCmd(
55435544 if (!process.can_spawn) {
55445545 const cmd = try std.mem.join(arena, " ", child_argv.items);
55455546 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{
5546 @tagName(builtin.os.tag), cmd,
5547 @tagName(native_os), cmd,
55475548 });
55485549 }
55495550
......@@ -5655,7 +5656,7 @@ pub fn lldMain(
56555656 var count: usize = 0;
56565657 };
56575658 if (CallCounter.count == 1) { // Issue the warning on the first repeat call
5658 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)});
5659 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)});
56595660 }
56605661 CallCounter.count += 1;
56615662
......@@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
59855986/// garbage collector to run concurrently to zig processes, and to allow multiple
59865987/// zig processes to run concurrently with each other, without clobbering each other.
59875988fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
5988 const have_rlimit = switch (builtin.os.tag) {
5989 const have_rlimit = switch (native_os) {
59895990 .windows, .wasi => false,
59905991 else => true,
59915992 };
......@@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
59935994 const posix = std.posix;
59945995
59955996 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
5996 if (comptime builtin.target.isDarwin()) {
5997 if (native_os.isDarwin()) {
59975998 // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
59985999 // According to the man pages for setrlimit():
59996000 // setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
60006001 // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
60016002 // Use "rlim_cur = min(OPEN_MAX, rlim_max)".
6002 lim.max = @min(std.os.darwin.OPEN_MAX, lim.max);
6003 lim.max = @min(std.c.OPEN_MAX, lim.max);
60036004 }
60046005 if (lim.cur == lim.max) return;
60056006
......@@ -6770,7 +6771,7 @@ fn cmdFetch(
67706771 args: []const []const u8,
67716772) !void {
67726773 const color: Color = .auto;
6773 const work_around_btrfs_bug = builtin.os.tag == .linux and
6774 const work_around_btrfs_bug = native_os == .linux and
67746775 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
67756776 var opt_path_or_url: ?[]const u8 = null;
67766777 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
test/cases/arithmetic_operations.0.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main() void {
88fn print(a: u32, b: u32) void {
99 const str = "123456789";
1010 const len = a + b;
11 _ = std.os.write(1, str[0..len]) catch {};
11 _ = std.posix.write(1, str[0..len]) catch {};
1212}
1313
1414// run
test/cases/arithmetic_operations.1.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main() void {
88fn print(a: u32, b: u32) void {
99 const str = "123456789";
1010 const len = a - b;
11 _ = std.os.write(1, str[0..len]) catch {};
11 _ = std.posix.write(1, str[0..len]) catch {};
1212}
1313
1414// run
test/cases/arithmetic_operations.2.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main() void {
88fn print(a: u32, b: u32) void {
99 const str = "123456789";
1010 const len = a & b;
11 _ = std.os.write(1, str[0..len]) catch {};
11 _ = std.posix.write(1, str[0..len]) catch {};
1212}
1313
1414// run
test/cases/arithmetic_operations.3.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main() void {
88fn print(a: u32, b: u32) void {
99 const str = "123456789";
1010 const len = a | b;
11 _ = std.os.write(1, str[0..len]) catch {};
11 _ = std.posix.write(1, str[0..len]) catch {};
1212}
1313
1414// run
test/cases/arithmetic_operations.4.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main() void {
88fn print(a: u32, b: u32) void {
99 const str = "123456789";
1010 const len = a ^ b;
11 _ = std.os.write(1, str[0..len]) catch {};
11 _ = std.posix.write(1, str[0..len]) catch {};
1212}
1313
1414// run
test/cases/errors.0.zig+1-1
......@@ -7,7 +7,7 @@ pub fn main() void {
77fn foo() anyerror!void {}
88
99fn print() void {
10 _ = std.os.write(1, "Hello, World!\n") catch {};
10 _ = std.posix.write(1, "Hello, World!\n") catch {};
1111}
1212
1313// run
test/cases/errors.1.zig+1-1
......@@ -9,7 +9,7 @@ fn foo() anyerror!void {
99}
1010
1111fn print() void {
12 _ = std.os.write(1, "Hello, World!\n") catch {};
12 _ = std.posix.write(1, "Hello, World!\n") catch {};
1313}
1414
1515// run
test/cases/function_pointers.zig+2-2
......@@ -12,11 +12,11 @@ pub fn main() void {
1212}
1313
1414fn stopSayingThat() void {
15 _ = std.os.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};
15 _ = std.posix.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};
1616}
1717
1818fn moveEveryZig() void {
19 _ = std.os.write(1, "All your codebase are belong to us\n") catch {};
19 _ = std.posix.write(1, "All your codebase are belong to us\n") catch {};
2020}
2121
2222// run
test/cases/parameters_and_return_values.0.zig+1-1
......@@ -10,7 +10,7 @@ fn id(x: u32) u32 {
1010
1111fn print(len: u32) void {
1212 const str = "Hello, World!\n";
13 _ = std.os.write(1, str[0..len]) catch {};
13 _ = std.posix.write(1, str[0..len]) catch {};
1414}
1515
1616// run
test/cases/print_u32s.zig+2-2
......@@ -12,10 +12,10 @@ fn printNumberHex(x: u32) void {
1212 var i: u5 = 28;
1313 while (true) : (i -= 4) {
1414 const digit = (x >> i) & 0xf;
15 _ = std.os.write(1, &.{digit_chars[digit]}) catch {};
15 _ = std.posix.write(1, &.{digit_chars[digit]}) catch {};
1616 if (i == 0) break;
1717 }
18 _ = std.os.write(1, "\n") catch {};
18 _ = std.posix.write(1, "\n") catch {};
1919}
2020
2121// run
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +3-3
......@@ -11,21 +11,21 @@ fn foo() void {
1111 }
1212 var f = async bar(@frame());
1313 _ = &f;
14 std.os.exit(1);
14 std.process.exit(1);
1515}
1616
1717fn bar(frame: anyframe) void {
1818 suspend {
1919 resume frame;
2020 }
21 std.os.exit(1);
21 std.process.exit(1);
2222}
2323
2424var global_frame: anyframe = undefined;
2525pub fn main() !void {
2626 _ = async foo();
2727 resume global_frame;
28 std.os.exit(1);
28 std.process.exit(1);
2929}
3030// run
3131// backend=stage1
test/cases/safety/resuming a non-suspended function which never been suspended.zig +2-2
......@@ -8,14 +8,14 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88fn foo() void {
99 var f = async bar(@frame());
1010 _ = &f;
11 std.os.exit(1);
11 std.process.exit(1);
1212}
1313
1414fn bar(frame: anyframe) void {
1515 suspend {
1616 resume frame;
1717 }
18 std.os.exit(1);
18 std.process.exit(1);
1919}
2020
2121pub fn main() !void {
test/link/glibc_compat/glibc_runtime_check.zig+2-2
......@@ -30,11 +30,11 @@ fn checkStat() !void {
3030 var stat = std.mem.zeroes(std.c.Stat);
3131 var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0);
3232 assert(result == -1);
33 assert(std.c.getErrno(result) == .NOENT);
33 assert(std.posix.errno(result) == .NOENT);
3434
3535 result = std.c.stat("a_file_that_definitely_does_not_exist", &stat);
3636 assert(result == -1);
37 assert(std.c.getErrno(result) == .NOENT);
37 assert(std.posix.errno(result) == .NOENT);
3838}
3939
4040// PR #17607 - reallocarray not visible in headers
test/standalone/sigpipe/breakpipe.zig+7-9
......@@ -1,19 +1,17 @@
11const std = @import("std");
22const build_options = @import("build_options");
33
4pub usingnamespace if (build_options.keep_sigpipe) struct {
5 pub const std_options = .{
6 .keep_sigpipe = true,
7 };
8} else struct {};
4pub const std_options = .{
5 .keep_sigpipe = build_options.keep_sigpipe,
6};
97
108pub fn main() !void {
11 const pipe = try std.os.pipe();
12 std.os.close(pipe[0]);
13 _ = std.os.write(pipe[1], "a") catch |err| switch (err) {
9 const pipe = try std.posix.pipe();
10 std.posix.close(pipe[0]);
11 _ = std.posix.write(pipe[1], "a") catch |err| switch (err) {
1412 error.BrokenPipe => {
1513 try std.io.getStdOut().writer().writeAll("BrokenPipe\n");
16 std.os.exit(123);
14 std.posix.exit(123);
1715 },
1816 else => |e| return e,
1917 };
test/standalone/sigpipe/build.zig+6-6
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const os = std.os;
2const posix = std.posix;
33
44pub fn build(b: *std.build.Builder) !void {
55 const test_step = b.step("test", "Test it");
......@@ -16,12 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
1616 // This test runs "breakpipe" as a child process and that process
1717 // depends on inheriting a SIGPIPE disposition of "default".
1818 {
19 const act = os.Sigaction{
20 .handler = .{ .handler = os.SIG.DFL },
21 .mask = os.empty_sigset,
19 const act = posix.Sigaction{
20 .handler = .{ .handler = posix.SIG.DFL },
21 .mask = posix.empty_sigset,
2222 .flags = 0,
2323 };
24 try os.sigaction(os.SIG.PIPE, &act, null);
24 try posix.sigaction(posix.SIG.PIPE, &act, null);
2525 }
2626
2727 for ([_]bool{ false, true }) |keep_sigpipe| {
......@@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {
3434 exe.addOptions("build_options", options);
3535 const run = b.addRunArtifact(exe);
3636 if (keep_sigpipe) {
37 run.addCheck(.{ .expect_term = .{ .Signal = std.os.SIG.PIPE } });
37 run.addCheck(.{ .expect_term = .{ .Signal = std.posix.SIG.PIPE } });
3838 } else {
3939 run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });
4040 run.addCheck(.{ .expect_term = .{ .Exited = 123 } });
test/standalone/windows_spawn/main.zig+4-4
......@@ -25,13 +25,13 @@ pub fn main() anyerror!void {
2525 defer allocator.free(tmp_relative_path);
2626
2727 // Clear PATH
28 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
28 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
2929 utf16Literal("PATH"),
3030 null,
3131 ) == windows.TRUE);
3232
3333 // Set PATHEXT to something predictable
34 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
34 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
3535 utf16Literal("PATHEXT"),
3636 utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),
3737 ) == windows.TRUE);
......@@ -39,7 +39,7 @@ pub fn main() anyerror!void {
3939 // No PATH, so it should fail to find anything not in the cwd
4040 try testExecError(error.FileNotFound, allocator, "something_missing");
4141
42 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
42 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
4343 utf16Literal("PATH"),
4444 tmp_absolute_path_w,
4545 ) == windows.TRUE);
......@@ -120,7 +120,7 @@ pub fn main() anyerror!void {
120120 const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
121121 defer allocator.free(something_subdir_abs_path);
122122
123 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
123 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
124124 utf16Literal("PATH"),
125125 something_subdir_abs_path,
126126 ) == windows.TRUE);