Skip to content

Commit

Permalink
Feedback from Reviewers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bushrat011899 and hymm committed Dec 4, 2024
1 parent 1d74b75 commit f54d306
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
29 changes: 26 additions & 3 deletions crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,28 @@ keywords = ["bevy"]

[features]
default = ["std", "async_executor"]
std = ["futures-lite/std", "async-task/std", "spin/std", "edge-executor?/std"]
std = [
"futures-lite/std",
"async-task/std",
"spin/std",
"edge-executor?/std",
"portable-atomic-util?/std",
]
multi_threaded = ["std", "dep:async-channel", "dep:concurrent-queue"]
async_executor = ["std", "dep:async-executor"]
edge_executor = ["dep:edge-executor"]
critical-section = ["edge-executor/critical-section"]
portable-atomic = ["edge-executor/portable-atomic"]
critical-section = [
"dep:critical-section",
"edge-executor?/critical-section",
"portable-atomic?/critical-section",
]
portable-atomic = [
"dep:portable-atomic",
"dep:portable-atomic-util",
"edge-executor?/portable-atomic",
"async-task/portable-atomic",
"spin/portable_atomic",
]

[dependencies]
futures-lite = { version = "2.0.1", default-features = false, features = [
Expand All @@ -37,6 +53,13 @@ edge-executor = { version = "0.4.1", default-features = false, optional = true }
async-channel = { version = "2.3.0", optional = true }
async-io = { version = "2.0.0", optional = true }
concurrent-queue = { version = "2.0.0", optional = true }
critical-section = { version = "1.2.0", optional = true }
portable-atomic = { version = "1", default-features = false, features = [
"fallback",
], optional = true }
portable-atomic-util = { version = "0.2.4", features = [
"alloc",
], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ The determining factor for what kind of work should go in each pool is latency r
await receiving data from somewhere (i.e. disk) and signal other systems when the data is ready
for consumption. (likely via channels)

## `no_std` Support

To enable `no_std` support in this crate, you will need to disable default features, and enable the `edge_executor` and `critical-section` features. For platforms without full support for Rust atomics, you may also need to enable the `portable-atomic` feature.

[bevy]: https://bevyengine.org
[rayon]: https://github.com/rayon-rs/rayon
[async-executor]: https://github.com/stjepang/async-executor
8 changes: 7 additions & 1 deletion crates/bevy_tasks/src/single_threaded_task_pool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use alloc::{string::String, sync::Arc, vec::Vec};
use alloc::{string::String, vec::Vec};
use core::{cell::RefCell, future::Future, marker::PhantomData, mem};

use crate::Task;

#[cfg(feature = "portable-atomic")]
use portable_atomic_util::Arc;

#[cfg(not(feature = "portable-atomic"))]
use alloc::sync::Arc;

#[cfg(feature = "std")]
use crate::executor::LocalExecutor;

Expand Down
2 changes: 1 addition & 1 deletion tools/ci/src/commands/compile_check_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Prepare for CompileCheckNoStdCommand {
commands.push(PreparedCommand::new::<Self>(
cmd!(
sh,
"cargo check -p bevy_tasks --no-default-features --features edge_executor --features critical-section --target {target}"
"cargo check -p bevy_tasks --no-default-features --features edge_executor,critical-section --target {target}"
),
"Please fix compiler errors in output above for bevy_tasks no_std compatibility.",
));
Expand Down

0 comments on commit f54d306

Please sign in to comment.