Skip to content

Commit c35df3c

Browse files
Added async_executor to the array of features enabled by multi_threaded within bevy_tasks crate to prevent compile-time error when default-features are disabled. (#19334)
## Objective Fixes #19051. --- ## Solution Originally implemented `compiler_error!()` within bevy_tasks/src/lib.rs file to provide descriptive message regarding missing feature. However, a cleaner approach was to add `async_executor` to the array of features enabled by `multi_threaded` instead. This removes the need for users to manually add `features = ["multi_threaded", "async_executor"]` separately as needed to be done previously. --- ## Testing These changes were tested using a minimal, external project designed to specifically test whether the standalone `multi_threaded` feature for `bevy_tasks` with `default-features` disabled worked as intended without running into any compile-time error. ### How it was tested: 1. A `bevy_tasks_test` binary project was set up in an external directory. 2. Its `Cargo.toml` was configured to depend on the local `bevy_tasks`, explicitly disabling default features and enabling only `multi_threaded`. 3. A simple `bevy_tasks_test/bin/bevy_crates_test.rs` was created and configured within `Cargo.toml` file where bevy_tasks was set to the local version of the crate with the modified changes and `cargo add bevy_platform` was executed through the terminal since that dependency is also needed to execute the sample examples. 4. Then both the `examples/busy_behavior.rs` and `examples/idle_behavior.rs` code was added and tested with just the `multi_threaded` feature was enabled and the code executed successfully. ### Results: The code executed successfully for both examples where a threadPool was utilized with 4 tasks and spawning 40 tasks that spin for 100ms. Demonstrating how the threads finished executing all the tasks simultaneously after a brief delay of less than a second (this is referencing `bevy_tasks/examples/busy_behavior.rs`). Alongside the second example where one thread per logical core was was utilized for a single spinning task and aside from utilizing the single thread, system was intended to remain idle as part of good practice when it comes to handling small workloads. (this is referencing `bevy_tasks/examples/idle_behavior.rs`). ### How to test: Reviewers can easily verify this by: 1. Checking out this PR. 2. Creating `cargo new bevy_tasks_test` and the `Cargo.toml` should look something like this: ```toml # bevy/tests/compile_fail_tasks/Cargo.toml [package] name = "bevy_tasks_test" version = "0.1.0" edition = "2021" publish = false [dependencies] # path to bevy_tasks sub-crate to test locally bevy_tasks = { path = "../../bevy_tasks", default-features = false, features = ["multi_threaded"] } bevy_platform = "0.16.1" ``` 3. Copying the examples within bevy_creates/examples one by one and testing them separately within `src/main.rs` to check whether the examples work. 4. Then simply running `cargo run` within the terminal should suffice to test if the single `multi_threaded` feature works without the need for separately adding `async_executor` as `multi_threaded` already uses `async_executor` internally. ### Platforms tested: macOS (aarch64). As a `#[cfg]` based compile-time check, behavior should be consistent across platforms.
1 parent 0e805eb commit c35df3c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/bevy_tasks/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ default = ["std", "async_executor"]
1515

1616
## Enables multi-threading support.
1717
## Without this feature, all tasks will be run on a single thread.
18-
multi_threaded = ["std", "dep:async-channel", "dep:concurrent-queue"]
18+
multi_threaded = [
19+
"std",
20+
"dep:async-channel",
21+
"dep:concurrent-queue",
22+
"async_executor",
23+
]
1924

2025
## Uses `async-executor` as a task execution backend.
2126
## This backend is incompatible with `no_std` targets.

0 commit comments

Comments
 (0)