I’m trying to make use of new (as of Zig 0.14) fanotify APIs on std.posix, for instance:
std.posix.fanotify_init
std.posix.fanotify_mark
std.posix.name_to_handle_at
I’m using as inspiration the code in Build.Watch, which uses the same functions for file-watching logic in Linuyx.
When I try to call these in my project I get the following compilation error:
error: root source file struct 'c' has no member named 'fanotify_init'
I’ve some questions related to these error, would deeply appreciate any help!
Is this expected behavior for my target (x86_64-linux, NixOS, default target and optimize mode, Zig 0.14.1).
Does this error mean that the specified posix functions are not available on my compilation target?
Is there a way to check which targets do support those functions / which functions are supported by my current compilation target?
I can use equivalent functions on std.os.linux, so I’m not blocked, but would prefer to use the posix versions because of the conveniences they offer (like returning error unions).
It looks like these declarations were never added in std.c. Probably because the build runner doesn’t link libc, so it was only necessary to add the syscalls to std.os.linux. A PR to add them would be welcome.
One point I’m not entirely clear on yet: I do see the Builld.Watch code use std.posix.fanotify_init as opposed to the functions on std.os.linux, and I can find the posix-versions of these calls in the documentation as well, for instance:
In fact, I’ve based my workaround wrappers around the std.os.linux versions on the source code shown in the documentation. That was super helpful.
All to say, it looks to me like more code than just the syscalls in std.os.linux already exists, it’s just not clear to me why it’s available in some places (Build.Watch, docs) but no others (my project).
As mentioned, the build runner doesn’t link libc. In this configuration, std.posix uses std.os.linux as the backing system API. If the build runner did link libc, std.posix would instead use std.c and fail to build like your project.