-
Notifications
You must be signed in to change notification settings - Fork 667
[WIP] Add no_std + alloc support #1438
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
Conversation
|
Edit: I deleted the old code. It is now implemented like this. (The alternative to |
Probably don't really need to facade anything from
Why import all of these specifically and then the glob as well?
Is the goal here to imitate the Overall I really like the idea behind Edit: Ah, I glossed over this from your original post:
I'm still of the opinion that if it's an alloc shim, it should look like Edit 2: Some reasoning behind my preferences: I feel like when |
|
One goal that I think this should aim for is minimal changes (and no extra dependencies) once I just thought of an alternative to the build-script based detection, you can have your original plan of #[cfg(all(feature = "alloc", not(any(feature = "std", feature = "nightly"))))]
compile_error!("The `alloc` feature without `std` requires the `nightly` feature active to explicitly opt-in to unstable features");Then switch back to using |
It's great, thanks! Previously I thought that it would be better for us to use alloc like std, but now I think that this is a bad idea (@jrobsonchase, @Nemo157 Thanks for pointing that out). And I rewrote this PR and |
|
When rust-lang/rust#58175 is done, I will update this PR and write a new summary. |
This adds the
allocfeatures tofutures,futures-core,futures-sink, andfutures-util.This allows to use
Box<Future>,alloc::task, many*Exttraits's methods etc in theno_std+allocenvironment.This PR adds alloc-shim crate as an optional dependency.
This is only valid if theallocfeature is enabled.alloc-shimwill re-export items ofcoreandallocin the same layout asstd. This allows addingno_std+allocsupport without changing existing imports.Edit: The current
alloc-shimhas the same layout as the alloc crate.Some other points:
When using the
allocfeature, thenightlyfeature must be used at the same time (see this comment in no_std + alloc feature selection #626).#[cfg(alloc)]is the same as#[cfg(any(feature = "alloc", feature = "std"))], but it is simpler and easier to write (build.rswas added for this).Edit: The implementation was changed to use
#[cfg(feature = "alloc")](thanks! @Nemo157).futures::stream::ReuniteErrorimplementsstd::error::Erroronly if "std" feature is valid.Fixed an. Edit2: It was split into Fix unused_imports warning on --no-default-features build #1447unused_importswarning inno_stdbuildReason to add
alloc-shimto dependenciesThe layout in the prelude module is different for
stdandalloc, soalloc::prelude::v1::*can not be used (andalloc::syncdoes not includeatomicmodule).Also, until now, we've imported everything fromstd, but from now on we'll need to import them fromallocandcore, respectively. Usingalloc-shimcan avoid these problems.alloccrate is still unstable, so I thinkalloc-shimwill be unnecessary in the future, but until then it will be possible to supportno_std+allocwith less cost by usingalloc-shim(also,alloc-shimis designed so that the build will not fail even ifatomicmodule is added toalloc::sync).Also, I've examined several other ways (1, 2, 3), but I believe this is the simplest and cleanest.Edit:
Using
alloc-shimcan avoid the first problem.Also, this is an implementation that does not use
alloc-shim: alloc-no-deps