Add no_std
support to bevy_state
(#17028)
# Objective - Contributes to #15460 ## Solution - Added the following features: - `std` (default) - `portable-atomic` - `critical-section` ## Testing - CI ## Notes - `portable-atomic`, and `critical-section` are shortcuts to enable the relevant features in dependencies, making the usage of this crate on atomically challenged platforms possible and simpler. - This PR is blocked until #17027 is merged (as it depends on fixes for the `once!` macro). Once merged, the change-count for this PR should reduce.
This commit is contained in:
parent
150eec7535
commit
79a367db16
@ -8,23 +8,67 @@ repository = "https://github.com/bevyengine/bevy"
|
||||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["bevy"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["bevy_reflect", "bevy_app", "bevy_hierarchy"]
|
||||
bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"]
|
||||
bevy_app = ["dep:bevy_app"]
|
||||
default = ["std", "bevy_reflect", "bevy_app", "bevy_hierarchy"]
|
||||
|
||||
# Functionality
|
||||
|
||||
## Adds runtime reflection support using `bevy_reflect`.
|
||||
bevy_reflect = [
|
||||
"dep:bevy_reflect",
|
||||
"bevy_ecs/bevy_reflect",
|
||||
"bevy_hierarchy?/reflect",
|
||||
"bevy_app?/bevy_reflect",
|
||||
]
|
||||
|
||||
## Adds integration with the `bevy_app` plugin API.
|
||||
bevy_app = ["dep:bevy_app", "bevy_hierarchy?/bevy_app"]
|
||||
|
||||
## Adds integration with the `bevy_hierarchy` `Parent` and `Children` API.
|
||||
bevy_hierarchy = ["dep:bevy_hierarchy"]
|
||||
|
||||
# Platform Compatibility
|
||||
|
||||
## Allows access to the `std` crate. Enabling this feature will prevent compilation
|
||||
## on `no_std` targets, but provides access to certain additional features on
|
||||
## supported platforms.
|
||||
std = [
|
||||
"bevy_ecs/std",
|
||||
"bevy_utils/std",
|
||||
"bevy_reflect?/std",
|
||||
"bevy_app?/std",
|
||||
"bevy_hierarchy?/std",
|
||||
]
|
||||
|
||||
## `critical-section` provides the building blocks for synchronization primitives
|
||||
## on all platforms, including `no_std`.
|
||||
critical-section = [
|
||||
"bevy_ecs/critical-section",
|
||||
"bevy_utils/critical-section",
|
||||
"bevy_app?/critical-section",
|
||||
]
|
||||
|
||||
## `portable-atomic` provides additional platform support for atomic types and
|
||||
## operations, even on targets without native support.
|
||||
portable-atomic = [
|
||||
"bevy_ecs/portable-atomic",
|
||||
"bevy_utils/portable-atomic",
|
||||
"bevy_app?/portable-atomic",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" }
|
||||
# bevy
|
||||
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev", default-features = false }
|
||||
bevy_state_macros = { path = "macros", version = "0.15.0-dev" }
|
||||
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
|
||||
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", optional = true }
|
||||
bevy_app = { path = "../bevy_app", version = "0.15.0-dev", optional = true }
|
||||
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.15.0-dev", optional = true }
|
||||
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev", default-features = false }
|
||||
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", default-features = false, optional = true }
|
||||
bevy_app = { path = "../bevy_app", version = "0.15.0-dev", default-features = false, optional = true }
|
||||
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.15.0-dev", default-features = false, optional = true }
|
||||
variadics_please = "1.1"
|
||||
|
||||
# other
|
||||
log = { version = "0.4", default-features = false }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use bevy_app::{App, MainScheduleOrder, Plugin, PreStartup, PreUpdate, SubApp};
|
||||
use bevy_ecs::{event::Events, schedule::IntoSystemConfigs, world::FromWorld};
|
||||
use bevy_utils::{tracing::warn, warn_once};
|
||||
use bevy_utils::once;
|
||||
use log::warn;
|
||||
|
||||
use crate::{
|
||||
state::{
|
||||
@ -87,7 +88,9 @@ pub trait AppExtStates {
|
||||
/// Separate function to only warn once for all state installation methods.
|
||||
fn warn_if_no_states_plugin_installed(app: &SubApp) {
|
||||
if !app.is_plugin_added::<StatesPlugin>() {
|
||||
warn_once!("States were added to the app, but `StatesPlugin` is not installed.");
|
||||
once!(warn!(
|
||||
"States were added to the app, but `StatesPlugin` is not installed."
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use bevy_ecs::{system::Commands, world::World};
|
||||
use bevy_utils::tracing::debug;
|
||||
use log::debug;
|
||||
|
||||
use crate::state::{FreelyMutableState, NextState};
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
//! In Bevy, states are app-wide interdependent, finite state machines that are generally used to model the large scale structure of your program: whether a game is paused, if the player is in combat, if assets are loaded and so on.
|
||||
//!
|
||||
//! This module provides 3 distinct types of state, all of which implement the [`States`](state::States) trait:
|
||||
@ -36,6 +38,8 @@
|
||||
)]
|
||||
#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "bevy_app")]
|
||||
/// Provides [`App`](bevy_app::App) and [`SubApp`](bevy_app::SubApp) with state installation methods
|
||||
pub mod app;
|
||||
|
@ -1,3 +1,4 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use bevy_app::{App, SubApp};
|
||||
|
@ -126,6 +126,14 @@ impl Prepare for CompileCheckNoStdCommand {
|
||||
"Please fix compiler errors in output above for bevy_input no_std compatibility.",
|
||||
));
|
||||
|
||||
commands.push(PreparedCommand::new::<Self>(
|
||||
cmd!(
|
||||
sh,
|
||||
"cargo check -p bevy_state --no-default-features --features bevy_reflect,bevy_app,bevy_hierarchy --target {target}"
|
||||
),
|
||||
"Please fix compiler errors in output above for bevy_state no_std compatibility.",
|
||||
));
|
||||
|
||||
commands
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user