smol-rs / polling

Portable interface to epoll, kqueue, event ports, and wepoll
Apache License 2.0
551 stars 68 forks source link

Support for the ESP-IDF framework #128

Closed ivmarkov closed 1 year ago

ivmarkov commented 1 year ago

(This has been long supported in a fork of the polling crate, but the fork was against an ancient version. So I finally jumped the gun to rebase it against the latest polling and try to upstream now.)

ESP IDF already does support the poll syscall, so this PR is only necessary because - ESP IDF being an embedded OS (or toolkit?) - does not support anything process-related, including the pipe syscall.

However it does support a subset of the eventfd syscall API, so what this PR does is to augment the poll module - specifically for ESP IDF - with an alternative eventfd codepath to where pipe is usually utilized. The same idea (use eventfd for the ESP IDF) was I believe re-used by @jasta in the recently upstreamed support for ESP IDF in tokio's reactor.

In terms of changes, two main items:

ivmarkov commented 1 year ago

OK. Will schedule some time over the weekend to do that.

daggerrz commented 1 year ago

@ivmarkov, this is a related: https://github.com/smol-rs/polling/pull/129

I rant into this while using your branch for embedded development and building tests for my MacOS host. The Rustix dependency update breaks some targets.

notgull commented 1 year ago

I merged #123 because I don't want to build up changes that are going to get stale. Just a heads up. This also takes care of the rustix v0.38 port.

daggerrz commented 1 year ago

Ah, thanks, did not see that it was already pending!

ivmarkov commented 1 year ago

@notgull Two additional follow up questions:

I'm in favor of a minimal variant where poll still has its own, private implementation based on pipe (and eventfd for the ESP IDF) as this stuff is difficult to test with so many variants of polling mechanisms and operating systems, but also would like to understand where you want to drive this in the end, so that I don't have to redo the PR multiple times.

notgull commented 1 year ago
ivmarkov commented 1 year ago
  • Unfortunately UnixStream does not work on Fuchsia. As Fuchsia isn't technically Unix, libstd does not expose it. So pipes are necessary for this use case.
  • I would prefer to keep the Notifier type in this module. The goal is to have each module be as self contained as possible. Not to mention, the code can't really be shared between Unix and Windows.

OK it should be ready for another review.

ivmarkov commented 1 year ago

Overall this looks good to me. Can you add a test to CI to make sure this code builds when targeting ESP-IDF? Even a simple cargo check would be enough.

Ignore the Wine and Cross failures in CI, they aren't your fault.

cargo check should be doable, yes, but with the following two caveats:

So if you are OK with "Caveat 1", yes, I'll work on that.

ivmarkov commented 1 year ago

OK, CI is ready. For now (and until rustix 0.38.7 is released), cargo check for ESP IDF runs with the rustix dependency patched against its mainline (and there is a weird warning that the patched dependency is not used, but surely it is or else the build would've failed).