authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2026-01-11 21:52:21+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2026-01-12 22:38:21+01:00
log0a8e8e67d7e67e8381f2dcdb8e5ede8e42a71649
tree71b723b9277106db0ce8b76d19db9cdc9ac0d82a
parent6376103b23617735044970f08c2a314c46b97c98

Misc. `std.Io` fixes for WASI and Emscripten

- Corrects WASI `UTIME_*` definitions now that the libc build has been fixed (see previous commit), and adds the corresponding definitions for Emscripten which were missing. - Fixes `dirReadUnimplemented()`, which didn't compile. - Prevents a dependency on `pthread_kill` from being pulled in in single-threaded Emscripten builds, where it isn't defined. With these changes, Emscripten can now participate in juicy main.

3 files changed, 28 insertions(+), 4 deletions(-)

lib/std/Io/Threaded.zig+6-2
......@@ -2024,6 +2024,7 @@ fn groupConcurrent(
20242024
20252025fn groupAwait(userdata: ?*anyopaque, type_erased: *Io.Group, initial_token: *anyopaque) Io.Cancelable!void {
20262026 _ = initial_token; // we need to load `token` *after* the group finishes
2027 if (builtin.single_threaded) unreachable; // nothing to await
20272028 const t: *Threaded = @ptrCast(@alignCast(userdata));
20282029 const g: Group = .{ .ptr = type_erased };
20292030
......@@ -2082,6 +2083,7 @@ fn groupAwait(userdata: ?*anyopaque, type_erased: *Io.Group, initial_token: *any
20822083
20832084fn groupCancel(userdata: ?*anyopaque, type_erased: *Io.Group, initial_token: *anyopaque) void {
20842085 _ = initial_token;
2086 if (builtin.single_threaded) unreachable; // nothing to cancel
20852087 const t: *Threaded = @ptrCast(@alignCast(userdata));
20862088 const g: Group = .{ .ptr = type_erased };
20872089
......@@ -2152,6 +2154,7 @@ fn await(
21522154 result_alignment: Alignment,
21532155) void {
21542156 _ = result_alignment;
2157 if (builtin.single_threaded) unreachable; // nothing to await
21552158 const t: *Threaded = @ptrCast(@alignCast(userdata));
21562159 const future: *Future = @ptrCast(@alignCast(any_future));
21572160
......@@ -2218,6 +2221,7 @@ fn cancel(
22182221 result_alignment: Alignment,
22192222) void {
22202223 _ = result_alignment;
2224 if (builtin.single_threaded) unreachable; // nothing to cancel
22212225 const t: *Threaded = @ptrCast(@alignCast(userdata));
22222226 const future: *Future = @ptrCast(@alignCast(any_future));
22232227
......@@ -4959,7 +4963,7 @@ fn dirReadUnimplemented(userdata: ?*anyopaque, dir_reader: *Dir.Reader, buffer:
49594963 _ = userdata;
49604964 _ = dir_reader;
49614965 _ = buffer;
4962 return error.Unimplemented;
4966 return error.Unexpected;
49634967}
49644968
49654969const dirRealPathFile = switch (native_os) {
......@@ -13224,7 +13228,7 @@ fn processSpawnPath(userdata: ?*anyopaque, dir: Dir, options: process.SpawnOptio
1322413228}
1322513229
1322613230const processSpawn = switch (native_os) {
13227 .wasi, .ios, .tvos, .visionos, .watchos => processSpawnUnsupported,
13231 .wasi, .emscripten, .ios, .tvos, .visionos, .watchos => processSpawnUnsupported,
1322813232 .windows => processSpawnWindows,
1322913233 else => processSpawnPosix,
1323013234};
lib/std/c.zig+6-2
......@@ -97,6 +97,7 @@ pub const off_t = switch (native_os) {
9797pub const timespec = switch (native_os) {
9898 .linux => linux.timespec,
9999 .emscripten => emscripten.timespec,
100 // lib/libc/include/wasm-wasi-musl/__struct_timespec.h
100101 .wasi => extern struct {
101102 sec: time_t,
102103 nsec: isize,
......@@ -115,16 +116,18 @@ pub const timespec = switch (native_os) {
115116 @as(wasi.timestamp_t, @intCast(ts.nsec));
116117 }
117118
119 // lib/libc/include/wasm-wasi-musl/__header_sys_stat.h
120
118121 /// For use with `utimensat` and `futimens`.
119122 pub const NOW: timespec = .{
120123 .sec = 0,
121 .nsec = 0x3fffffff,
124 .nsec = -1,
122125 };
123126
124127 /// For use with `utimensat` and `futimens`.
125128 pub const OMIT: timespec = .{
126129 .sec = 0,
127 .nsec = 0x3ffffffe,
130 .nsec = -2,
128131 };
129132 },
130133 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20
......@@ -7007,6 +7010,7 @@ pub const time_t = switch (native_os) {
70077010 .linux => linux.time_t,
70087011 .emscripten => emscripten.time_t,
70097012 .haiku, .dragonfly => isize,
7013 // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h
70107014 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47
70117015 else => i64,
70127016};
lib/std/os/emscripten.zig+16
......@@ -729,6 +729,7 @@ pub const sockaddr = c.sockaddr;
729729
730730pub const blksize_t = i32;
731731pub const nlink_t = u32;
732// https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L140
732733pub const time_t = i64;
733734pub const mode_t = u32;
734735pub const off_t = i64;
......@@ -765,9 +766,24 @@ pub const stack_t = extern struct {
765766 size: usize,
766767};
767768
769// https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L284
768770pub const timespec = extern struct {
769771 sec: time_t,
770772 nsec: isize,
773
774 // https://github.com/emscripten-core/emscripten/blob/d72d7226f4733af8ff993dec70198cf09a24142d/system/lib/libc/musl/include/sys/stat.h#L77-L78
775
776 /// For use with `utimensat` and `futimens`.
777 pub const NOW: timespec = .{
778 .sec = 0,
779 .nsec = 0x3fffffff,
780 };
781
782 /// For use with `utimensat` and `futimens`.
783 pub const OMIT: timespec = .{
784 .sec = 0,
785 .nsec = 0x3ffffffe,
786 };
771787};
772788
773789pub const timezone = extern struct {