-
Notifications
You must be signed in to change notification settings - Fork 11
no-std support #55
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
base: main
Are you sure you want to change the base?
no-std support #55
Conversation
|
Please update from main |
src/packet.rs
Outdated
| use super::*; | ||
| use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; | ||
| use core::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; | ||
| use socket2::SockAddr; |
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.
the tests should be adjusted to remove the socket2 dependency. Once that is gone, then the tests are also no_std.
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.
+1. Honestly if core gives us what we need for initializing sockets, I'm in favor of just removing socket2 altogether.
That crate advertises itself as providing a nice cross-platform way to configure sockets with advanced options; if we're not making use of those options, fewer dependencies is faster compiles :)
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.
As far as I can tell core::net only supplies the basic address types and does not do any socket initialization unfortunately. So for the receiver and source modules we'd still need something like it.
I have rewritten the tests in packet.rs without using socket2::SockAddr. Perhaps a #![cfg(feature = "std)] flag or similar should be used in the tests/ directory as they still depend on socket2?
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.
The receiver and source use advanced socket features through socket2. Packet parsing does not make use of socket2 features, so packet parsing and packing could be no_std (+alloc) fairly easily.
Removed dependency on std when the "std" feature is disabled The library can now be compiled with the --no-default-features flag to enable no_std support. The target will have to specify a #[global_allocator] such as [embedded-alloc](https://docs.rs/embedded-alloc/latest/embedded_alloc/) Replace socket2::SockAddr dependency with core::net::SocketAddrV4/6 `pub fn universe_to_ipv4_multicast_addr()` now returns core::net::SocketAddrV4 `pub fn universe_to_ipv6_multicast_addr()` now returns core::net::SocketAddrV6
Dependencies related to the embedded example were removed
|
I have merged the changes from main and removed the example dependencies from the root Cargo.toml. I also removed the socket2 usage from the packet.rs tests, which now pass with the --no-default-features flag. However the tests in the tests directory still depend on socket2. I have now also added my example code. And I feel like some things are missing as far as no_std functionality goes:
|
Example code for an stm32f746g-disco development board. Listens on the discovery universe. Automatically connects to the discovered universes. Up to the multicast limit as set by the smoltcp feature flag. Prints received packets with defmt.
| authors = ["Lukas Schmierer <lukas.schmierer@lschmierer.de>", "Paul Lancaster <paul@lancasterzone.com>"] | ||
| authors = [ | ||
| "Lukas Schmierer <lukas.schmierer@lschmierer.de>", | ||
| "Paul Lancaster <paul@lancasterzone.com>", | ||
| ] | ||
| documentation = "https://github.com/RustLight/sacn" | ||
| repository = "https://github.com/RustLight/sacn" | ||
| license = "MIT OR Apache-2.0" | ||
| homepage = "https://github.com/RustLight/sacn" | ||
| exclude = [ | ||
| "documentation/*", | ||
| "further testing/*", | ||
| ".github/*", | ||
| ".travis.yml", | ||
| ".gitignore", | ||
| "documentation/*", | ||
| "further testing/*", | ||
| ".github/*", | ||
| ".travis.yml", | ||
| ".gitignore", |
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.
Remove formatting edits of unmodified code sections.
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.
Add the added example to cargo.toml
| Uuid(#[from] uuid::Error), | ||
| Uuid(uuid::Error), |
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.
What is wrong with this #[from] compared to the one above for Utf8Error?
| #[cfg(feature = "std")] | ||
| extern crate std; | ||
|
|
||
| //use core::{fmt, fmt::Display}; |
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.
Is this needed? Uncomment or delete the line.
| /// The errors within the sACN crate related to parse/pack errors. | ||
| /// Error-chain is used for errors within the library to allow chaining errors together to provide more informative backtraces. | ||
| /// This completely replaces the old error system (sACN crate version 0.4.4) which relied on a simple Enum model without proper backtraces. | ||
| //#[cfg(feature = "std")] |
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.
Delete comment if not needed.
| pub mod sacn_parse_pack_error; | ||
|
|
||
| /// The errors used within the sACN crate, parse/pack errors are seperated out into sacn_parse_pack_error. | ||
| //#[cfg(feature = "std")] |
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.
Delete comment if not needed.
Removed dependency on std when the "std" feature is disabled
The library can now be compiled with the --no-default-features flag to enable no_std support. The target will have to specify a #[global_allocator] such as
embedded-alloc
Replace socket2::SockAddr dependency with core::net::SocketAddrV4/6
pub fn universe_to_ipv4_multicast_addr()now returns core::net::SocketAddrV4pub fn universe_to_ipv6_multicast_addr()now returns core::net::SocketAddrV6Implements the foundation for #42