You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build Runner: Implement File System Watching for kqueue #20599
Most of the file system watching mechanism is abstracted across operating systems, however, the parts that deal with receiving events from file system changes require OS-specific implementations.
Based on some initial reading, kqueue requires a fd for each file being watched and not simply on the parent directory fd like can be done with inotify, which will cause issues if many files need to be watched individually.
An alternative for Mac is to use FSEvents which looks to be suitable for the workflow. I am not sure if this included by default in the core libraries available to use from zig.
I heard from @Jarred-Sumner today that you can dlopen frameworks such as FSEvents. That might be an option to explore. It's not really a good solution though because we want something that works for all the BSDs.
I'll double check the kqueue API too. We really need directory events, it's not really possible to implement correct behavior by only watching files. I bet it's possible.
Based on that Go code, kqueue indeed allows watching directories, however those events do not provide the names of changed files within the watched directory.
This is fine for our purposes here. It will just trigger a rebuild if any files are changed when any sibling files are watched. The Go code noted above simulates file system watching by scanning watched directories when their events fire. The Zig code will not need that hack since the rebuild will already do such a scan.
Activity
tiehuis commentedon Jul 13, 2024
Based on some initial reading, kqueue requires a fd for each file being watched and not simply on the parent directory fd like can be done with inotify, which will cause issues if many files need to be watched individually.
An alternative for Mac is to use FSEvents which looks to be suitable for the workflow. I am not sure if this included by default in the core libraries available to use from zig.
andrewrk commentedon Jul 13, 2024
I heard from @Jarred-Sumner today that you can dlopen frameworks such as FSEvents. That might be an option to explore. It's not really a good solution though because we want something that works for all the BSDs.
I'll double check the kqueue API too. We really need directory events, it's not really possible to implement correct behavior by only watching files. I bet it's possible.
ghostiam commentedon Aug 6, 2024
I found the implementation on kqueue.
Think this can help us in implementation.
freebsd || openbsd || netbsd || dragonfly || darwinhttps://github.com/fsnotify/fsnotify/blob/main/backend_kqueue.go
andrewrk commentedon Sep 24, 2024
Based on that Go code, kqueue indeed allows watching directories, however those events do not provide the names of changed files within the watched directory.
https://github.com/fsnotify/fsnotify/blob/c1467c02fba575afdb5f4201072ab8403bbf00f4/backend_kqueue.go#L524-L525
This is fine for our purposes here. It will just trigger a rebuild if any files are changed when any sibling files are watched. The Go code noted above simulates file system watching by scanning watched directories when their events fire. The Zig code will not need that hack since the rebuild will already do such a scan.
This is a pretty straightforward patch.