-
-
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
Add no_std
support to bevy_tasks
#15464
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 |
Haven't forgotten about this PR! I'm planning to redo this to instead use |
That sounds like a good approach. Please ping/request review from me when you have that ready and I'll try to review it quickly. |
I believe this PR is now at a point where it is ready for review! I've reset the branch back to |
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.
I'm pretty happy with this approach now. I only did a code review and the code changes seem reasonable. I haven't tried running this yet.
The one thing that is hard to understand is which combination of features we're supporting. Could we add some documentation in the bevy_tasks readme for what the different features are and how to use them?
We should probably manually test wasm32 and make sure it is working correctly. Did you try running this on a no_std platform?
Properly implement `portable-atomic` and `critical-section` features to enable compilation on `thumbv6m-none-eabi` (as an example platform) Co-Authored-By: Mike <[email protected]>
I've updated the
I had previously tested this in QEMU for |
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.
The technical strategy here looks solid, but I want more docs. This crate isn't far off from warn(missing_docs): let's not make it work. Simple doc strings for all of the new types and modules please? I think it will really help reviewers / contributors understand the purpose and structure of this.
Co-Authored-By: Alice Cecile <[email protected]>
I've updated the documentation for the entire crate, ensuring all public items have at least a simple docstring. |
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.
Much better! These are good docs.
Objective
no_std
Bevy #15460Solution
std
(default)async_executor
(default)edge_executor
critical-section
portable-atomic
edge-executor
as ano_std
alternative toasync-executor
.single_threaded_task_pool
to work inno_std
environments by gating its reliance onthread_local
.Testing
compile-check-no-std
CI commandNotes
async-executor
alternative was vendored in. This raised concerns around maintenance and testing. In this iteration, an existing version of that same vendoring is now used, but only inno_std
contexts. For existingstd
contexts, the originalasync-executor
is used.TaskPool
operations have added restrictions aroundSend
/Sync
inno_std
. This is because there isn't a straightforward way to create a thread-local inno_std
. If these added constraints pose an issue we can revisit this at a later date.async_executor
andedge_executor
features, we will default to usingasync-executor
. Since enablingasync_executor
requiresstd
, we can safely assume we are in anstd
context and use the original library.