Skip to content
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

Improve Compiler Errors for bevy_tasks #17296

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/bevy_tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extern crate std;

extern crate alloc;

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
compile_error!("Either of the `async_executor` or the `edge_executor` features must be enabled.");

#[cfg(not(target_arch = "wasm32"))]
mod conditional_send {
/// Use [`ConditionalSend`] to mark an optional Send trait bound. Useful as on certain platforms (eg. Wasm),
Expand Down Expand Up @@ -45,6 +48,7 @@ pub type BoxedFuture<'a, T> = core::pin::Pin<Box<dyn ConditionalSendFuture<Outpu

pub mod futures;

#[cfg(any(feature = "async_executor", feature = "edge_executor"))]
mod executor;

mod slice;
Expand Down
42 changes: 40 additions & 2 deletions crates/bevy_tasks/src/single_threaded_task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,50 @@ use portable_atomic_util::Arc;
#[cfg(not(feature = "portable-atomic"))]
use alloc::sync::Arc;

#[cfg(feature = "std")]
#[cfg(all(
feature = "std",
any(feature = "async_executor", feature = "edge_executor")
))]
use crate::executor::LocalExecutor;

#[cfg(not(feature = "std"))]
#[cfg(all(
not(feature = "std"),
any(feature = "async_executor", feature = "edge_executor")
))]
use crate::executor::Executor as LocalExecutor;

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
mod dummy_executor {
use async_task::Task;
use core::{future::Future, marker::PhantomData};

/// Dummy implementation of a `LocalExecutor` to allow for a cleaner compiler error
/// due to missing feature flags.
#[doc(hidden)]
#[derive(Debug)]
pub struct LocalExecutor<'a>(PhantomData<fn(&'a ())>);

impl<'a> LocalExecutor<'a> {
/// Dummy implementation
pub const fn new() -> Self {
Self(PhantomData)
}

/// Dummy implementation
pub fn try_tick(&self) -> bool {
unimplemented!()
}

/// Dummy implementation
pub fn spawn<T: 'a>(&self, _: impl Future<Output = T> + 'a) -> Task<T> {
unimplemented!()
}
}
}

#[cfg(not(any(feature = "async_executor", feature = "edge_executor")))]
use dummy_executor::LocalExecutor;

#[cfg(feature = "std")]
thread_local! {
static LOCAL_EXECUTOR: LocalExecutor<'static> = const { LocalExecutor::new() };
Expand Down
Loading