Skip to content
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

Make no_std compatible #7

Closed
t-moe opened this issue Nov 2, 2023 · 6 comments · Fixed by #12
Closed

Make no_std compatible #7

t-moe opened this issue Nov 2, 2023 · 6 comments · Fixed by #12
Labels
bug Something isn't working question Further information is requested

Comments

@t-moe
Copy link

t-moe commented Nov 2, 2023

Thanks for this awesome crate.

In order to use it on no_std targets I had to modify the header of lib.rs

#![no_std]
#![doc = core::include_str!(core::concat!("../", core::env!("CARGO_PKG_README")))]
@bengreenier
Copy link
Owner

bengreenier commented Nov 2, 2023

Thanks @t-moe - I don't have any experience with no_std, but is that the only change you had to make? If so, sounds easy enough to include here - do you know if we also need some no_std feature flag to enable/disable such an attribute?

@bengreenier bengreenier added bug Something isn't working question Further information is requested labels Nov 2, 2023
@bengreenier
Copy link
Owner

Looking at serde I don't think we should need #![no_std] in this library crate, only in the consuming application crate (in the serde example, they have it in the test)...

That said, I put together a minimal repro that builds a no_std binary for windows (which is easiest for me to test, at the moment) and do indeed see that partially isn't compatible (causes build error when used): https://github.com/bengreenier/test_partially_no_std/blob/main/src/main.rs

I'll have to play with this a bit more tomorrow though, as the phrasing at https://docs.rust-embedded.org/embedonomicon/smallest-no-std.html#what-does-no_std-mean coupled with the serde example suggests to me that we probably shouldn't just be dropping in #![no_std] as the fix here.

@bengreenier
Copy link
Owner

created a built-in test application to mirror serde's setup, so we now have a (failing to compile) test case for no_std in repo. https://github.com/bengreenier/partially/tree/feat/no_std/crates/test_no_std

@t-moe
Copy link
Author

t-moe commented Nov 3, 2023

Serde has more to say about no_std: Look here: https://github.com/search?q=repo%3Aserde-rs%2Fserde+no_std&type=code

Here's some implementation suggestion: https://github.com/KodrAus/rust-no-std/blob/main/src/lib.rs
(via https://stackoverflow.com/questions/57611219/when-adding-no-std-to-a-library-are-there-any-disadvantages-or-complicati )

@bengreenier
Copy link
Owner

Just linking in some other resources I've come across while investigating this one:

Starting to sound like maybe it is normal to just add #![no_std] to a library crate itself, and then flag any features that depend on std with an std feature that's enabled by default.

@bengreenier
Copy link
Owner

landed in 0.2.0: crates.io - docs.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants