nix-rust / nix

Rust friendly bindings to *nix APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

epoll-shim and libinotify-kqueue support

jbeich opened this issue · comments

BSD systems provide compatibility shims for inotify and epoll/eventfd/signalfd/timerfd from Linux. It'd be nice to reuse those from nix instead of forcing consumers to add a separate codepath for kqueue.

epoll + eventfd example
$ git clone https://gitlab.com/gilrs-project/gilrs.git
$ cd gilrs
$ cargo build
[...]
error[E0432]: unresolved import `nix::sys::epoll`
  --> gilrs-core/src/platform/linux/gamepad.rs:21:15
   |
21 | use nix::sys::epoll::{EpollEvent, EpollFlags, EpollOp};
   |               ^^^^^ could not find `epoll` in `sys`

error[E0432]: unresolved import `nix::sys::eventfd`
  --> gilrs-core/src/platform/linux/gamepad.rs:22:15
   |
22 | use nix::sys::eventfd::EfdFlags;
   |               ^^^^^^^ could not find `eventfd` in `sys`

error[E0432]: unresolved imports `nix::sys::epoll`, `nix::sys::eventfd`
  --> gilrs-core/src/platform/linux/gamepad.rs:23:16
   |
23 | use nix::sys::{epoll, eventfd};
   |                ^^^^^  ^^^^^^^
   |                |      |
   |                |      no `eventfd` in `sys`
   |                |      help: a similar name exists in the module: `event`
   |                no `epoll` in `sys`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `gilrs-core` due to 3 previous errors
inotify + timerfd example
$ git clone https://github.com/k0kubun/xremap
$ cd xremap
$ cargo build --features sway
[...]
error[E0432]: unresolved import `nix::sys::inotify`
  --> src/main.rs:13:15
   |
13 | use nix::sys::inotify::{AddWatchFlags, Inotify, InotifyEvent};
   |               ^^^^^^^ could not find `inotify` in `sys`

error[E0432]: unresolved import `nix::sys::timerfd`
  --> src/main.rs:16:15
   |
16 | use nix::sys::timerfd::{ClockId, TimerFd, TimerFlags};
   |               ^^^^^^^ could not find `timerfd` in `sys`

error[E0432]: unresolved import `nix::sys::inotify`
  --> src/config/mod.rs:18:15
   |
18 | use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify};
   |               ^^^^^^^ could not find `inotify` in `sys`

error[E0432]: unresolved import `nix::sys::inotify`
 --> src/device.rs:8:15
  |
8 | use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify};
  |               ^^^^^^^ could not find `inotify` in `sys`

error[E0432]: unresolved import `nix::sys::timerfd`
  --> src/event_handler.rs:15:15
   |
15 | use nix::sys::timerfd::{Expiration, TimerFd, TimerSetTimeFlags};
   |               ^^^^^^^ could not find `timerfd` in `sys`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `xremap` due to 5 previous errors

Portability is explicitly a non-goal of Nix. Instead, Nix is focused on providing zero- or low-overhead Rusty access to existing system APIs. If you want cross-platform epoll compatibility, that would be better off in a separate crate, perhaps one that consumes Nix. There's also mio . mio is already cross-platform, though it isn't a drop-in replacement for epoll.