Skip to content

Commit 234c3b8

Browse files
committed
fix compilation failures found by CI
1 parent 6b2899d commit 234c3b8

27 files changed

+124
-125
lines changed

lib/compiler/resinator/main.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub fn _errno() *c_int {
88
return &errno;
99
}
1010

11+
pub const PATH_MAX = 4096;
12+
1113
pub const mode_t = u32;
1214
pub const time_t = i64;
1315

lib/std/fs.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
5555
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/os.zig

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const elf = std.elf;
2222
const fs = std.fs;
2323
const dl = @import("dynamic_library.zig");
2424
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
25+
const posix = std.posix;
2526

2627
pub const linux = @import("os/linux.zig");
2728
pub 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.
100101
pub 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`.
241+
pub 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+
259+
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
42834283
pub 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

4303-
fn 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-
43164303
pub 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`.
43294316
pub 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`.
43454332
pub 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`.
4378-
fn 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-
43964362
pub 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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

207-
pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult {
207+
pub 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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
41364136
return null;
41374137
}
41384138

4139-
pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
4139+
pub 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

4152-
pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void {
4152+
pub 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

43324332
const HotUpdateState = struct {
4333-
mach_task: ?std.os.darwin.MachTask = null,
4333+
mach_task: ?std.c.MachTask = null,
43344334
};
43354335

43364336
pub const DynamicRelocs = struct {

0 commit comments

Comments
 (0)