Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Support building in no_std environments #69

Closed
wants to merge 3 commits into from

Conversation

Nemo157
Copy link
Contributor

@Nemo157 Nemo157 commented Mar 8, 2018

This doesn't actually build on targets that don't provide a std crate because of some missing changes in futures 0.2.0-alpha, but it does successfully build a no_std version of the futures-await crate on targets that provide a std crate.

This branch + rust-lang/futures-rs#845 + a custom executor is capable of running self-referential #[async] futures on alloc-less bare-metal devices 🎉

I'm really not sure what to do about the context storage, as far as I'm aware this is safe on single-threaded devices, but I'm not sure if this might ever be used on a non-single-threaded device.

thread_local!(static CTX: Cell<StaticContext> = Cell::new(ptr::null_mut()));

#[cfg(not(feature = "std"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this impl here? It seems totally unsafe to me-- no_std systems can still have threads, so accesses to CTX would be unsound, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was kinda hoping someone else might have some idea how to make this safe on threaded no_std. The best solution I see is using generator arguments to avoid CTX entirely with and without no_std, but I don’t know what the current status on those are.

I guess there’s the old design of futures 0.1 where you have to call an init routine to setup the thread locals on no_std, pushing the safety requirements onto the user of the library.

Copy link
Contributor Author

@Nemo157 Nemo157 Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After glancing at the futures 0.1 task::init setup, I really don't want to have to fully understand that to make sure it's safe here. It's also really not how we would want to have the library work in the end since futures-await should be a private library able to be used by dependencies without the application needing to know about it.

Nemo157 and others added 3 commits March 26, 2018 16:53
@Nemo157
Copy link
Contributor Author

Nemo157 commented Apr 3, 2018

Moved to rust-lang/futures-rs#935

@Nemo157 Nemo157 closed this Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants