-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for embedded-hal-async traits #1
base: master
Are you sure you want to change the base?
Conversation
Older Cargo versions use the same namespace for both features and dependencies.
It looks like you're running CI tests on a version of Cargo from 2018 that doesn't support |
This is interesting, thanks!
|
AIUI the way to interpret this is not "non-blocking feature", it's the "use the nb crate feature". It's a pretty common convention that feature names should match the name of the dependency they add, if possible.
That's true; I made
Yeah, it's tough until
Certainly not happening on a 2018 Rust :)
Done. |
Thanks! As a TODO list so that we do not forget anything:
|
…ed off on non-Linux
I bumped the MSRV to 1.56.0, so you can trigger another CI run which will hopefully pass. I also started using the I added a single example to the top level of the library; since every function is exactly the same, hopefully that will be enough. Unfortunately neither |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Sorry it took me quite a while to go through the whole PR.
Could you also update the clippy version in CI and add a job building and running clippy with the async
feature?
The CI fails on bare-metal targets because of linux-embedded-hal
. For no-std targets I have a step in the CI where I comment out linux-embedded-hal
, which is the reason for the weird error message. The build would fail nevertheless since this cannot be compiled there so another way to manage the dependencies would be necessary.
Now that we have a newer MSRV, using the "dep" namespace here would also be possible.
Cargo.toml
Outdated
[dependencies] | ||
embedded-hal = "0.2.5" | ||
nb = "1" | ||
embedded-hal-async = { version = "0.1.0-alpha.1", optional = true } | ||
linux-embedded-hal = { version = "0.3", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linux-embedded-hal
should only be a dev-dependency
since it is only used for the examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible to have an optional dev-dependency
, so if I leave it there this crate is not buildable on macOS...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do:
[target.'cfg(target_os = "linux")'.dev-dependencies]
linux-embedded-hal = "0.3"
The examples will still not build, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do that, there's no way to indicate that the example requires it. At least with it as an optional dependency cargo will avoid building the example if the feature isn't enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, the best I can come up with is to use cfg
guards to make linux.rs
into a noop.
Cargo.toml
Outdated
@@ -19,13 +20,40 @@ include = [ | |||
"/LICENSE-APACHE", | |||
] | |||
|
|||
[features] | |||
default = ["nb", "linux-embedded-hal"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If requiring linux-embedded-hal
, bare-metal targets will not build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below.
The rust embedded community is moving to a set of async traits for i2c. I implemented this as a pair of features,
nb
andasync
, to choose the type of desired futures. I thought about trying to use macros to generate both flavors of code, but I decided it was better to just duplicate the files for now. Presumably at some point in the future thenb
version will just become deprecated.Note that embassy provides an adapter to convert a blocking
I2c
into an asyncI2c
, so this new async version can also be used with all the other legacy hals that don't provide the async traits.I also noticed that the crate doesn't pass
cargo test
on non-Linux because it tries to build the example andlinux-embedded-hal
doesn't build on non-Linux. I couldn't figure out how to tell cargo that it shouldn't try to build the example on non-Linux platforms, but this PR doesn't make that any better or worse.