-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add no_std
support to bevy_app
#16874
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
Changes from all commits
3472656
dda4dc2
5200f5b
eb8fc79
eab7df6
2589853
87fbca8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
html_logo_url = "https://bevyengine.org/assets/icon.png", | ||
html_favicon_url = "https://bevyengine.org/assets/icon.png" | ||
)] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
//! This crate is about everything concerning the highest-level, application layer of a Bevy app. | ||
|
||
|
@@ -23,7 +24,7 @@ mod plugin; | |
mod plugin_group; | ||
mod schedule_runner; | ||
mod sub_app; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "std"))] | ||
mod terminal_ctrl_c_handler; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't use Control-C in the terminal if your platform doesn't have a terminal...or a keyboard... |
||
|
||
pub use app::*; | ||
|
@@ -33,7 +34,7 @@ pub use plugin::*; | |
pub use plugin_group::*; | ||
pub use schedule_runner::*; | ||
pub use sub_app::*; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "std"))] | ||
pub use terminal_ctrl_c_handler::*; | ||
|
||
/// The app prelude. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
// TODO: Upstream `portable-atomic` support to `downcast_rs` and unconditionally | ||
// include it as a dependency. | ||
// See https://github.com/marcianx/downcast-rs/pull/22 for details | ||
#[cfg(feature = "downcast")] | ||
use downcast_rs::{impl_downcast, Downcast}; | ||
|
||
use crate::App; | ||
use core::any::Any; | ||
|
||
/// Dummy trait with the same name as `downcast_rs::Downcast`. This is to ensure | ||
/// the `Plugin: Downcast` bound can remain even when `downcast` isn't enabled. | ||
#[cfg(not(feature = "downcast"))] | ||
#[doc(hidden)] | ||
pub trait Downcast {} | ||
|
||
#[cfg(not(feature = "downcast"))] | ||
impl<T: ?Sized> Downcast for T {} | ||
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/// A collection of Bevy app logic and configuration. | ||
/// | ||
/// Plugins configure an [`App`]. When an [`App`] registers a plugin, | ||
|
@@ -92,6 +105,7 @@ pub trait Plugin: Downcast + Any + Send + Sync { | |
} | ||
} | ||
|
||
#[cfg(feature = "downcast")] | ||
impl_downcast!(Plugin); | ||
|
||
impl<T: Fn(&mut App) + Send + Sync + 'static> Plugin for T { | ||
|
@@ -129,6 +143,7 @@ pub trait Plugins<Marker>: sealed::Plugins<Marker> {} | |
impl<Marker, T> Plugins<Marker> for T where T: sealed::Plugins<Marker> {} | ||
|
||
mod sealed { | ||
use alloc::boxed::Box; | ||
use variadics_please::all_tuples; | ||
|
||
use crate::{App, AppError, Plugin, PluginGroup}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ use crate::{ | |
plugin::Plugin, | ||
PluginsState, | ||
}; | ||
use bevy_utils::{Duration, Instant}; | ||
use bevy_utils::Duration; | ||
|
||
#[cfg(any(target_arch = "wasm32", feature = "std"))] | ||
use bevy_utils::Instant; | ||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of how we bring this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes please! |
||
|
||
#[cfg(target_arch = "wasm32")] | ||
use { | ||
|
@@ -76,7 +79,7 @@ impl Plugin for ScheduleRunnerPlugin { | |
let plugins_state = app.plugins_state(); | ||
if plugins_state != PluginsState::Cleaned { | ||
while app.plugins_state() == PluginsState::Adding { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "bevy_tasks"))] | ||
bevy_tasks::tick_global_task_pools_on_main_thread(); | ||
} | ||
app.finish(); | ||
|
@@ -95,8 +98,9 @@ impl Plugin for ScheduleRunnerPlugin { | |
} | ||
RunMode::Loop { wait } => { | ||
let tick = move |app: &mut App, | ||
wait: Option<Duration>| | ||
_wait: Option<Duration>| | ||
-> Result<Option<Duration>, AppExit> { | ||
#[cfg(any(target_arch = "wasm32", feature = "std"))] | ||
let start_time = Instant::now(); | ||
|
||
app.update(); | ||
|
@@ -105,9 +109,11 @@ impl Plugin for ScheduleRunnerPlugin { | |
return Err(exit); | ||
}; | ||
|
||
#[cfg(any(target_arch = "wasm32", feature = "std"))] | ||
let end_time = Instant::now(); | ||
|
||
if let Some(wait) = wait { | ||
#[cfg(any(target_arch = "wasm32", feature = "std"))] | ||
if let Some(wait) = _wait { | ||
let exe_time = end_time - start_time; | ||
if exe_time < wait { | ||
return Ok(Some(wait - exe_time)); | ||
|
@@ -121,7 +127,10 @@ impl Plugin for ScheduleRunnerPlugin { | |
{ | ||
loop { | ||
match tick(&mut app, wait) { | ||
Ok(Some(delay)) => std::thread::sleep(delay), | ||
Ok(Some(_delay)) => { | ||
#[cfg(feature = "std")] | ||
std::thread::sleep(_delay); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without access to |
||
} | ||
Ok(None) => continue, | ||
Err(exit) => return exit, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
use crate::{App, AppLabel, InternedAppLabel, Plugin, Plugins, PluginsState}; | ||
use alloc::{boxed::Box, string::String, vec::Vec}; | ||
use bevy_ecs::{ | ||
event::EventRegistry, | ||
prelude::*, | ||
schedule::{InternedScheduleLabel, ScheduleBuildSettings, ScheduleLabel}, | ||
system::{SystemId, SystemInput}, | ||
}; | ||
|
||
#[cfg(feature = "trace")] | ||
use bevy_utils::tracing::info_span; | ||
use bevy_utils::{HashMap, HashSet}; | ||
use core::fmt::Debug; | ||
|
||
#[cfg(feature = "trace")] | ||
use tracing::info_span; | ||
|
||
type ExtractFn = Box<dyn Fn(&mut World, &mut World) + Send>; | ||
|
||
/// A secondary application with its own [`World`]. These can run independently of each other. | ||
|
@@ -332,6 +333,7 @@ impl SubApp { | |
} | ||
|
||
/// See [`App::get_added_plugins`]. | ||
#[cfg(feature = "downcast")] | ||
bushrat011899 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn get_added_plugins<T>(&self) -> Vec<&T> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only real consequence of losing |
||
where | ||
T: Plugin, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ std = [ | |
## on all platforms, including `no_std`. | ||
critical-section = [ | ||
"dep:critical-section", | ||
"bevy_tasks/critical-section", | ||
"bevy_tasks?/critical-section", | ||
"portable-atomic?/critical-section", | ||
] | ||
|
||
|
@@ -88,8 +88,9 @@ critical-section = [ | |
portable-atomic = [ | ||
"dep:portable-atomic", | ||
"dep:portable-atomic-util", | ||
"bevy_tasks/portable-atomic", | ||
"bevy_tasks?/portable-atomic", | ||
"concurrent-queue/portable-atomic", | ||
"spin/portable_atomic", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes to |
||
] | ||
|
||
[dependencies] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,14 @@ impl Prepare for CompileCheckNoStdCommand { | |
"Please fix compiler errors in output above for bevy_ecs no_std compatibility.", | ||
)); | ||
|
||
commands.push(PreparedCommand::new::<Self>( | ||
cmd!( | ||
sh, | ||
"cargo check -p bevy_app --no-default-features --features bevy_reflect --target {target}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that |
||
), | ||
"Please fix compiler errors in output above for bevy_app no_std compatibility.", | ||
)); | ||
|
||
commands | ||
} | ||
} |
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.
As with
bevy_ecs
, I'm flattening our relationship withbevy_utils::tracing
and also relying onlog
for non-span logging. It's already been mentioned that we should probably move things likelog
andtracing
into workspace dependencies, but I'm just maintaining status quo for now.