Cross-compile for macos fails with "undefined symbol _ppoll" (works with posix.poll)

With the help of user @Wunka I recently added support for capturing SIGWINCH resize signals while waiting on an input event for my TUI lib dabeob. The solution uses std.posix.ppoll to wait for an input event OR a SIGWINCH signal. (executed fn)

Generally, that works very good when compiling for my own machine (Void Linux x86_64 glibc) or for other Linux archs (I testes aarch64 with glibc and musl libc).

However, now I tried cross-compiling for aarch64-macos-none and x86_64-macos-none, but both failed with error undefined symbol: _ppoll.

Extended error message
$ zig build -Dtarget=x86_64-macos-none
install
└─ install example-my-tui
   └─ compile exe example-my-tui debug x86_64-macos-none 1 errors
error: undefined symbol: _ppoll
    note: referenced by /home/lukeflo/Documents/coding/zig/dabeob/.zig-cache/o/997f1c3beafeaf4abee51469f3262c56/example-my-tui_zcu.o:_posix.ppoll
error: 1 compilation errors
failed command: /home/lukeflo/.cache/zxc/versions/0.17.1/zig build-exe -Odebug -target x86_64-macos-none -mcpu baseline --dep dabeob -Mroot=examples/my_tui.zig -target x86_64-macos-none -mcpu baseline -Mdabeob=src/root.zig --cache-dir .zig-cache --global-cache-dir /home/lukeflo/.cache/zig --build-root . --name example-my-tui --zig-lib-dir /home/lukeflo/.cache/zxc/versions/0.17.1/lib/ --listen=-

Build Summary: 0/3 steps succeeded (1 failed)
install transitive failure
└─ install example-my-tui transitive failure
   └─ compile exe example-my-tui debug x86_64-macos-none 1 errors

That was surprising, because before I added the usage of ppoll, the lib used plain std.posix.poll() for polling only input events. With the plain poll() function cross-compiling for the named targets was no problem. (example code with old setup)

Since I neither have access to a real Mac for testing, nor am I an expert for the backend stuff going on regarding “C stuff” (std.posix.(p)poll are resolved to std.c.(p)poll for macos) when cross-compiling for a different target, I would be very thankful for some insights or tipps. Could it be a flaw in my code or maybe the respective std-lib namespace?

Just to make something clear, which I noticed after my code got merged. I first misunderstood what ppoll did exactly / how it did what it did. (I am not experienced with all this stuff, this was my first real thing coding with these interrupt systems). While ppoll does solve that exact problem and with it we don’t miss any SIGWINCH. Normally we could still use poll, but there a thing which also kinda confused me on the way:
std.posix.poll does this regarding interrupts:

pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
    ...
    while (true) {
        const rc = system.poll(fds.ptr, fds_count, timeout);
        switch (errno(rc)) {
            ...
            .INTR => continue,
            ...
        }
    }
    ...

Which std.posix.ppoll doesn’t:

pub fn ppoll(fds: []pollfd, timeout: ?*const timespec, mask: ?*const sigset_t) PPollError!usize {
    ...
    const rc = system.ppoll(fds.ptr, fds_count, ts_ptr, mask);
    switch (errno(rc)) {
        ...
        .INTR => return error.SignalInterrupt,
        ...
    }
    ...

Else std.posix.poll would have just “worked”, but would let a small window open where we can be interrupted, but maybe just don’t notice it.
So maybe std.posix.system.poll would “work” even if it lets a tiny window open. (all of this from my understanding, with not a lot of experience)

Also sorry that I didn’t mention this all earlier.

OK, that’s interesting and definitely worth a look for solving this exact problem in this particular case.

No need to excuse, I’m also not too familiar with all that stuff :wink:

However, to my understanding it doesn’t explain why cross compiling with poll() works while it fails with ppoll(). A solution for the latter case might also help others who potentially run into the same error.

I just found this issue: `ppoll` is not available on macOS but is declared in `std.c` · Issue #18693 · ziglang/zig · GitHub

Seems like ppoll just maybe doesn’t exist on macos :frowning:

Oh :open_mouth:. That’s weird