-
Notifications
You must be signed in to change notification settings - Fork 626
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
[WIP] Add no_std + alloc support #1438
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
alloc
features tofutures
,futures-core
,futures-sink
, andfutures-util
.This allows to use
Box<Future>
,alloc::task
, many*Ext
traits's methods etc in theno_std
+alloc
environment.This PR adds alloc-shim crate as an optional dependency.
This is only valid if thealloc
feature is enabled.alloc-shim
will re-export items ofcore
andalloc
in the same layout asstd
. This allows addingno_std
+alloc
support without changing existing imports.Edit: The current
alloc-shim
has the same layout as the alloc crate.Some other points:
When using the
alloc
feature, thenightly
feature 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.rs
was added for this).Edit: The implementation was changed to use
#[cfg(feature = "alloc")]
(thanks! @Nemo157).futures::stream::ReuniteError
implementsstd::error::Error
only if "std" feature is valid.Fixed an. Edit2: It was split into Fix unused_imports warning on --no-default-features build #1447unused_imports
warning inno_std
buildReason to add
alloc-shim
to dependenciesThe layout in the prelude module is different for
std
andalloc
, soalloc::prelude::v1::*
can not be used (andalloc::sync
does not includeatomic
module).Also, until now, we've imported everything fromstd
, but from now on we'll need to import them fromalloc
andcore
, respectively. Usingalloc-shim
can avoid these problems.alloc
crate is still unstable, so I thinkalloc-shim
will be unnecessary in the future, but until then it will be possible to supportno_std
+alloc
with less cost by usingalloc-shim
(also,alloc-shim
is designed so that the build will not fail even ifatomic
module 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-shim
can avoid the first problem.Also, this is an implementation that does not use
alloc-shim
: alloc-no-deps