Uh oh!
There was an error while loading. Please reload this page.
debug.zig: Make it build with 'other' target OS - #20845
Conversation
rootbeer
commented
Jul 29, 2024
Looks like Wasi has an |
andrewrk
left a comment
There was a problem hiding this comment.
Thanks.
This is the direction I would like to go instead:
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 31321d62fd..77345821ed 100644
--- a/lib/std/debug.zig+++ b/lib/std/debug.zig@@ -842,10 +842,7 @@ pub const StackIterator = struct {
}
};
-const have_msync = switch (native_os) {- .wasi, .emscripten, .windows => false,- else => true,-};+const have_msync = @TypeOf(posix.system.msync) != void;
pub fn writeCurrentStackTrace(
out_stream: anytype,
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
index 955987b036..d6c3746c4d 100644
--- a/lib/std/posix.zig+++ b/lib/std/posix.zig@@ -29,23 +29,34 @@ test {
_ = @import("posix/test.zig");
}
-/// Whether to use libc for the POSIX API layer.-const use_libc = builtin.link_libc or switch (native_os) {- .windows, .wasi => true,- else => false,-};-
const linux = std.os.linux;
const windows = std.os.windows;
const wasi = std.os.wasi;
/// A libc-compatible API layer.
-pub const system = if (use_libc)+pub const system = if (builtin.link_libc)
std.c
else switch (native_os) {
.linux => linux,
.plan9 => std.os.plan9,
+ .wasi => struct {+ pub const E = wasi.errno_t;+ pub const fd_t = wasi.fd_t;+ pub const msync = {};+ pub const pid_t = void;+ pub const pollfd = void;+ pub const rlimit_resource = void;+ pub const ucontext_t = void;+ pub const AT = void;+ pub const ino_t = void;+ pub const mode_t = void;+ },
else => struct {
+ pub const msync = {};+ pub const pid_t = void;+ pub const pollfd = void;+ pub const rlimit_resource = void;
pub const ucontext_t = void;
},
};
@@ -238,7 +249,7 @@ pub const socket_t = if (native_os == .windows) windows.ws2_32.SOCKET else fd_t;
/// function only returns a well-defined value when it is called directly after
/// the system function call whose errno value is intended to be observed.
pub fn errno(rc: anytype) E {
- if (use_libc) {+ if (builtin.link_libc) {
return if (rc == -1) @enumFromInt(std.c._errno().*) else .SUCCESS;
}
const signed: isize = @bitCast(rc);It points out compilation errors at all the places that the standard library is incorrectly leaning on a POSIX API layer for libc-less WASI rather than lowering standard library API directly to the WASI API layer.
I am pushing this change in the direction you suggested. It will take me a bit of time (all I know of WASI is what I'm learning in the Zig source tree...). I believe the three existing commits in this PR are mostly independent of the WASI cleanup (other than forcing the issue to be a bit more apparent), so I don't think you need to hold up review/submit of those. But unless I hear otherwise, I'll assume you want the WASI fixes on this PR and will push a new version here once I get through the fallout ... |
rootbeer
commented
Aug 1, 2024
@andrewrk would you prefer the The "void" seems more correct to me, but the existing Windows targets in Zig implicitly map I recommend setting |
andrewrk
commented
Aug 1, 2024
I think it's a good recommendation; let's do that. |
81b4224 to
c6995e6Comparec6995e6 to
8518ea2Comparerootbeer
commented
Aug 15, 2024
I've forked the more general WASI POSIX cleanup changes to #20991, as they got large. I know a bit more about WASM now, so I've cleaned up this PR to make the |
137b92a to
0167bc7Compare0167bc7 to
513bb99Comparerootbeer
commented
Oct 1, 2024
I updated this PR for the recent |
The freestanding and other OS targets by default need to just @trap in the default Panic implementation. And `isValidMemory` won't work with freestanding or other targets. Update the unwind_freestanding.zig test case to also run on the 'other' OS target, too. This should keep the Zig's stacktrace generation from regressing on the standalone targets.
513bb99 to
523f215Compareandrewrk
commented
Nov 29, 2024
Thanks! |
Make
std.debug.StackIteratorcompile on theotherOS target, and port the "unwind_freestanding" test case to theotherOS target.Inspired by #20833 which reported the original problem and pin-pointed the issue.
[Edited summary and PR a couple times.]