`realpathAlloc` returns `error: Unexpected` when running Windows executable with Wine

I’m trying to cross-compile a binary from Linux to Windows, and I’m using Wine to test it. Here’s the code that causes the error:

pub fn main() !void {
    std.debug.print("{s}\n", .{try std.fs.cwd().realpathAlloc(std.heap.page_allocator, "path/here")});
}

Error:

error: Unexpected
Unable to dump stack trace: Unexpected

Running the Linux binary is fine, but when trying to run the Windows binary with Wine I get that error.

I can confirm this (Zig version 0.15.2, Wine 11.3).

realpath has several problems, see remove realpath() from the standard library · Issue #19353 · ziglang/zig · GitHub, it’s best to try and avoid it (even if that’s not always easy).

2 Likes

Zig prefers calling into ntdll over higher-level APIs when targeting Windows:

https://codeberg.org/ziglang/zig/issues/31131

This means that the Zig standard library may hit Wine bugs in those APIs, and the recommended solution is to submit patches to Wine rather than introduce workarounds in Zig.

(FYI the stack traces not showing up currently has a Wine-specific workaround in place on the master branch but it’s pretty likely to be reverted)

2 Likes