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
Default to no_std
#2543
base: master
Are you sure you want to change the base?
Default to no_std
#2543
Conversation
Strange errors showing up in CI on this and other PRs? |
This one looks real; it's related to imports of types which are affected by nostd. |
No worries, thanks. Looks like I have some more work to do. Will come back to this. |
Pull Request Test Coverage Report for Build 8946096346Details
💛 - Coveralls |
59d831f
to
26f6703
Compare
Note to self, consider updating manifest catagories and keywords to include no-std same as in |
Hashes does not build with |
Interesting, that exposes a hole in CI also then. Will investigate, thanks. Tip your local CI bot for me, he is doing good work. EDIT: oh, this is not a hole in CI, slipped through because we don't check every patch only the final PR state. |
Either way is fine, just pick one and be uniform.
As we do for other crates; default to `no_std`. There are currently two major problems with defaulting to `no_std`: 1. Many of the units tests use types/macros from `alloc`. 2. The "schemars" feature has an implicit dependency on "alloc", the current code is buggy but we only ever test "schemars" with the "std" feature enabled. Solutions: 1. Just unconditionally import a bunch of `alloc` types. 2. Add a new feature "schemars" and change the dependency to be "actual-schemars" then add all the feature gated imports. Note also the usage of `use std::is_x86_feature_detected;`
As we do for other crates; default to `no_std`. The major issues with this is that we have, up until now, assumed we have `extern crate std` in tests. Most of this patch is fixing the feature gating to use stuff from `extern crate alloc` and correctly feature gating on "std" if required. Note also use of `format!` in tests instead of `println!` because it is available in `alloc`.
This is getting a bit silly, one has to wonder at if there is not a better way #[cfg(test)]
mod tests {
#[cfg(feature = "alloc")]
#[allow(unused_imports)] // Less maintenance if we just import these.
use crate::alloc::{format, string::ToString, vec, vec::Vec};
#[cfg(any(feature = "alloc", feature = "serde"))]
use crate::{sha256d, Hash as _}; |
This is partially fallout from rust-lang/rust#121708 .. though I think it actually predates that issue. We have a couple options. One is to just |
What if we had a test prelude module (ie., gated on I believe that wildcard imports do not trigger redundant import warnings, which is nice. We'd have to be careful that for crates with a |
"gross", what are you, five? (Not sure if that joke translates to text, but I mean it in the most jovial of ribbing ways.) |
I'm not a huge fan of |
Yeah I've heard you say that before, maybe I'm missing something, but when do you ever need to search for alloc/core/std type e.g,. |
Oh, I literally just suggested putting non-std types in a prelude :( |
Just FTR this PR is good to merge, we are just having a discussion on the pain of imports for |
To understand what set of feature-gates are controlling their import logic, which is important when reviewing code that should work in a no-std context. But yes, for non-std types the problem with wildcards is even clearer. |
Interesting, so are you saying that when you review no-std code you are thinking "what are the feature gate requirements for this code"? And then you like to look at the imports to see if it matches your thoughts? I always have treated prelude to mean "there are a set of feature gated imports that work with this code" and because its in one place it implies "and they are sane because we looked before and don't change them much". Where as when the feature gated imports are in each place I have to reason about them to check if they are sane. |
No, only when they break.
If only.. |
Needs rebase, this feature gating is boring as hell - leaving rebasing until after the one-ack thing comes in and we have some hope of merging this without more rebasing. |
Default to
no_std
forhashes
andbitcoin
- all other crates are already done.Turns out this one was a bit more involved that I expected, its a fair bit of messing around in tests but I think its worth it to give us more confidence in
no_std.
Close: #2413