-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add no_std
support to bevy_tasks
#15464
base: main
Are you sure you want to change the base?
Conversation
`thread_local`, `getrandom`, and `web-time` were being included even in `no_std` configurations. Additionally, `hashbrown` had extra features enabled that should've been gated.
Is it possible to try and upstream the no_std changes to async executor? I'm not sure bevy wants to pick which executor to use yet. See #6762 or #11995. If we do want to do this, we shouldn't just copy the code, but tests, benches, and CI too. (This would probably be a separate PR for ease of review.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Very clean.
It might be possible! The reason I didn't start there is the crate describes itself as a reference implementation, and that you should write your own executor using the underlying
Perfectly reasonable! I've copied over all the tests as well (this executor was only a single file), but I do agree that something like Tokio or Rayon could also work. But, I specifically just want to get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still good
Tests are actually here: https://github.com/smol-rs/async-executor/tree/master/tests. The async-executor repo also runs loom on the tests. If this is merged we should figure out how to run loom on bevy_tasks. But I'm really not sure if forking async executor is worth it just for no-std support. We're potentially locking bevy out from future upstream improvements. For consoles I imagine that they'll need to have their own fork of async executor anyways as they should be able to park and unpark threads, so would be able to have their own Mutex implementation, which would be better than spin locking. If no_std is only single threaded is there a different async executor we can use and then have a separate no_std task pool? |
Thanks for pointing that out, not sure how I missed it! So used to having unit tests within the same file I got complacent.
These are excellent points and I generally agree. There was some discussion in the Discord around potentially using |
Objective
no_std
Bevy #15460Solution
std
feature (enabled by default)async-executor
dependency with an in-tree alternative based on said dependency.single_threaded_task_pool
to work inno_std
environments by gating its reliance onthread_local
.Testing
cargo clippy -p bevy_tasks --target "x86_64-unknown-none" --no-default-features
Notes
executor.rs
is heavily inspired byasync-executor
's lib.rs. Comparing to the source may help with understanding what changes needed to be made forno_std
compatibility.thread_local
inno_std
, we cannot guarantee access toLOCAL_EXECUTOR
is within the same thread. This is why inno_std
, there is a stricter requirement on tasks to beSend
and possiblySync
. These cases are annotated withMaybeSync
andMaybeSend
bounds.This PR is blocked until Minor fixes forbevy_utils
inno_std
#15463 is merged, asbevy_utils
needs to successfully compile inno_std
contexts forbevy_tasks
to also compile successfully.