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

Add no_std support to bevy_state #17028

Merged
merged 4 commits into from
Dec 29, 2024
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
64 changes: 54 additions & 10 deletions crates/bevy_state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_state/src/app.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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."
));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_state/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy_ecs::{system::Commands, world::World};
use bevy_utils::tracing::debug;
use log::debug;

use crate::state::{FreelyMutableState, NextState};

Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_state/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_state/src/state_scoped_events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use core::marker::PhantomData;

use bevy_app::{App, SubApp};
Expand Down
8 changes: 8 additions & 0 deletions tools/ci/src/commands/compile_check_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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