zig icon indicating copy to clipboard operation
zig copied to clipboard

Using `std.os.poll` on windows causes undefined reference error

Open IntegratedQuantum opened this issue 3 years ago • 1 comments

Zig Version

0.11.0-dev.3655+a2f54fce5

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() !void {
	_ = try std.os.poll(undefined, undefined);
}

Output:

$ zig run test.zig -target x86_64-windows-gnu -lc -lws2_32
error: lld-link: undefined symbol: poll
    note: referenced by /home/mint/Downloads/zig/lib/std/os.zig:6518
    note:               /home/mint/.cache/zig/o/3527c68e3a1bc7e3e4fe3d635ecb99dc/test.exe.obj:(os.poll)

Expected Behavior

std.os should use ws2_32.WSAPoll instead of using the non-existant extern function std.c.poll

IntegratedQuantum avatar Jun 20 '23 20:06 IntegratedQuantum

I would highly recommend against this, as WSAPoll is bugged and will not be fixed. see: https://curl.se/mail/lib-2012-10/0038.html

As far as I know rust uses (a variation of) the following as an alternative internally: https://github.com/piscisaureus/wepoll

iamtimmy avatar Jun 21 '23 00:06 iamtimmy

Related: #5019 : std.os functions really provide a POSIX-ish layer so should be moved to std.posix. (not currently accepted) #6600 : std.os shouldn't provide a POSIX-ish layer and instead be designed for all systems equally. (currently accepted)

My understanding of this: Short-term it seems like std.os.poll is just not supported on Windows, and should be guarded by a @compileError stating this. Long-term some mechanism like std.os.poll that supports Windows should be added, however note that std is currently designed around the needs of Zig itself. Therefore if Zig doesn't need such a mechanism on Windows, it might just not provide it there (especially if it's not fully reliable as mentioned above).

rohlem avatar Jun 21 '23 09:06 rohlem