Skip to content

Add compiler_error!() description for error when multi_threaded feature is enabled but async_executor is not #19334

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DeveloperMindset123
Copy link

@DeveloperMindset123 DeveloperMindset123 commented May 22, 2025

Objective

Fixes #19051.


Solution

The compile_error!() is added to bevy_tasks/src/lib.rs. It triggers specifically when the multi_threaded feature is active, but async_executor is not.

The error message is user-friendly, detailing:

  • The missing dependency.
  • Why it's needed (multi-threaded pools require an executor).
  • The exact Cargo.toml snippet for a fix.
  • A note about how Bevy's DefaultPlugins usually handles this automatically.

Testing

These changes were tested using a minimal, external project designed to specifically trigger the new compile_error!().

How it was tested:

  1. A compile_fail_tasks 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 src/main.rs referenced a bevy_tasks component (bevy_tasks::ComputeTaskPool::new();) to ensure compilation paths were hit.
  4. The project was built using cargo build -p compile_fail_tasks from the Bevy root.

Results:

The build failed as expected, prominently displaying the custom compile_error!() message. While other Send/Sync errors also appeared (confirming the underlying problem this fix addresses), the primary goal of providing a clear compile-time error was achieved.

How to test:

Reviewers can easily verify this by:

  1. Checking out this PR.
  2. Creating tests/compile_fail_tasks/Cargo.toml with:
    # bevy/tests/compile_fail_tasks/Cargo.toml
    [package]
    name = "compile_fail_tasks"
    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"] }
  3. Running cargo build -p compile_fail_tasks or simply cargo build within the current directory.

Platforms tested:

macOS (aarch64). As a #[cfg] based compile-time check, behavior should be consistent across platforms.


Tagging @bushrat011899 for review.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@DeveloperMindset123
Copy link
Author

P.S. Do let me know if I should use a specific PR name when making PRs, since this was my first PR 😅. This is a temporary fix as the original author(s) would need to make this update and push the changes with a new version onto crates.io. If it's too tedious and feels unnecessary, feel free to close the PR rather than merging it.

This is just to get familiar with PR process within Bevy Ecosystem and building up more contextual awareness.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Actually. on second thought, I think that just improving the way the features depend on each other is a much better fix.

@alice-i-cecile
Copy link
Member

P.S. Do let me know if I should use a specific PR name when making PRs, since this was my first PR 😅

We're pretty flexible on this sort of thing: the main thing to do is communicate what was fixed so you can quickly scan the git commit history. I'll go ahead and tweak the title to show you how it might have been better here.

@alice-i-cecile alice-i-cecile changed the title chore:added compiler_error!() for additional description to vague error Add compiler_error!() description for error when multi_threaded feature is enabled but async_executor is not May 26, 2025
@bushrat011899
Copy link
Contributor

I think the nicer fix is to just add async_executor to multi_threaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature bevy_tasks/multi_threaded does not compile alone
3 participants