Skip to content

Commit a532c14

Browse files
bushrat011899mrchantey
authored andcommitted
Add no_std support to bevy_hierarchy (bevyengine#16998)
# Objective - Contributes to bevyengine#15460 ## Solution - Added the following features: - `std` (default) ## Testing - CI ## Notes - There was a minor issue with `bevy_reflect`'s `smallvec` feature noticed in this PR which I have also resolved here. I can split this out if desired, but I've left it here for now as it's a very small change and I don't consider this PR itself to be very controversial.
1 parent cfb1784 commit a532c14

File tree

6 files changed

+70
-29
lines changed

6 files changed

+70
-29
lines changed

crates/bevy_hierarchy/Cargo.toml

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,54 @@ license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

1111
[features]
12-
default = ["bevy_app"]
13-
trace = []
14-
bevy_app = ["reflect", "dep:bevy_app"]
15-
reflect = ["bevy_ecs/bevy_reflect", "bevy_reflect"]
12+
default = ["std", "bevy_app", "reflect"]
13+
14+
# Functionality
15+
16+
## Adds integration with the `bevy_app` plugin API.
17+
bevy_app = ["dep:bevy_app"]
18+
19+
## Adds runtime reflection support using `bevy_reflect`.
20+
reflect = ["bevy_ecs/bevy_reflect", "bevy_reflect", "bevy_app?/bevy_reflect"]
21+
22+
# Debugging Features
23+
24+
## Enables `tracing` integration, allowing spans and other metrics to be reported
25+
## through that framework.
26+
trace = ["dep:tracing"]
27+
28+
# Platform Compatibility
29+
30+
## Allows access to the `std` crate. Enabling this feature will prevent compilation
31+
## on `no_std` targets, but provides access to certain additional features on
32+
## supported platforms.
33+
std = [
34+
"bevy_app?/std",
35+
"bevy_ecs/std",
36+
"bevy_reflect/std",
37+
"bevy_utils/std",
38+
"disqualified/alloc",
39+
]
1640

1741
[dependencies]
1842
# bevy
19-
bevy_app = { path = "../bevy_app", version = "0.15.0-dev", optional = true }
43+
bevy_app = { path = "../bevy_app", version = "0.15.0-dev", default-features = false, optional = true }
2044
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev", default-features = false }
2145
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
22-
"bevy",
2346
"smallvec",
24-
], optional = true }
25-
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
26-
disqualified = "1.0"
47+
], default-features = false, optional = true }
48+
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev", default-features = false, features = [
49+
"alloc",
50+
] }
51+
disqualified = { version = "1.0", default-features = false }
2752

28-
smallvec = { version = "1.11", features = ["union", "const_generics"] }
53+
# other
54+
smallvec = { version = "1.11", default-features = false, features = [
55+
"union",
56+
"const_generics",
57+
] }
58+
tracing = { version = "0.1", default-features = false, optional = true }
59+
log = { version = "0.4", default-features = false }
2960

3061
[lints]
3162
workspace = true

crates/bevy_hierarchy/src/hierarchy.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bevy_ecs::{
88
system::EntityCommands,
99
world::{Command, DeferredWorld, EntityWorldMut, World},
1010
};
11-
use bevy_utils::tracing::debug;
11+
use log::debug;
1212

1313
/// Despawns the given entity and all its children recursively
1414
#[derive(Debug)]
@@ -69,11 +69,11 @@ fn despawn_children_recursive(world: &mut World, entity: Entity, warn: bool) {
6969
impl Command for DespawnRecursive {
7070
fn apply(self, world: &mut World) {
7171
#[cfg(feature = "trace")]
72-
let _span = bevy_utils::tracing::info_span!(
72+
let _span = tracing::info_span!(
7373
"command",
7474
name = "DespawnRecursive",
75-
entity = bevy_utils::tracing::field::debug(self.entity),
76-
warn = bevy_utils::tracing::field::debug(self.warn)
75+
entity = tracing::field::debug(self.entity),
76+
warn = tracing::field::debug(self.warn)
7777
)
7878
.entered();
7979
despawn_with_children_recursive(world, self.entity, self.warn);
@@ -83,11 +83,11 @@ impl Command for DespawnRecursive {
8383
impl Command for DespawnChildrenRecursive {
8484
fn apply(self, world: &mut World) {
8585
#[cfg(feature = "trace")]
86-
let _span = bevy_utils::tracing::info_span!(
86+
let _span = tracing::info_span!(
8787
"command",
8888
name = "DespawnChildrenRecursive",
89-
entity = bevy_utils::tracing::field::debug(self.entity),
90-
warn = bevy_utils::tracing::field::debug(self.warn)
89+
entity = tracing::field::debug(self.entity),
90+
warn = tracing::field::debug(self.warn)
9191
)
9292
.entered();
9393

@@ -150,10 +150,10 @@ fn despawn_recursive_inner(world: EntityWorldMut, warn: bool) {
150150
let entity = world.id();
151151

152152
#[cfg(feature = "trace")]
153-
let _span = bevy_utils::tracing::info_span!(
153+
let _span = tracing::info_span!(
154154
"despawn_recursive",
155-
entity = bevy_utils::tracing::field::debug(entity),
156-
warn = bevy_utils::tracing::field::debug(warn)
155+
entity = tracing::field::debug(entity),
156+
warn = tracing::field::debug(warn)
157157
)
158158
.entered();
159159

@@ -167,10 +167,10 @@ fn despawn_descendants_inner<'v, 'w>(
167167
let entity = world.id();
168168

169169
#[cfg(feature = "trace")]
170-
let _span = bevy_utils::tracing::info_span!(
170+
let _span = tracing::info_span!(
171171
"despawn_descendants",
172-
entity = bevy_utils::tracing::field::debug(entity),
173-
warn = bevy_utils::tracing::field::debug(warn)
172+
entity = tracing::field::debug(entity),
173+
warn = tracing::field::debug(warn)
174174
)
175175
.entered();
176176

crates/bevy_hierarchy/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
html_logo_url = "https://bevyengine.org/assets/icon.png",
55
html_favicon_url = "https://bevyengine.org/assets/icon.png"
66
)]
7+
#![cfg_attr(not(feature = "std"), no_std)]
78

89
//! Parent-child relationships for Bevy entities.
910
//!
@@ -98,8 +99,9 @@ pub struct HierarchyPlugin;
9899
#[cfg(feature = "bevy_app")]
99100
impl Plugin for HierarchyPlugin {
100101
fn build(&self, app: &mut App) {
101-
app.register_type::<Children>()
102-
.register_type::<Parent>()
103-
.add_event::<HierarchyEvent>();
102+
#[cfg(feature = "reflect")]
103+
app.register_type::<Children>().register_type::<Parent>();
104+
105+
app.add_event::<HierarchyEvent>();
104106
}
105107
}

crates/bevy_hierarchy/src/valid_parent_check_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::marker::PhantomData;
33
use bevy_ecs::prelude::*;
44

55
#[cfg(feature = "bevy_app")]
6-
use {crate::Parent, bevy_utils::HashSet, disqualified::ShortName};
6+
use {crate::Parent, alloc::format, bevy_utils::HashSet, disqualified::ShortName};
77

88
/// When enabled, runs [`check_hierarchy_component_has_valid_parent<T>`].
99
///
@@ -63,7 +63,7 @@ pub fn check_hierarchy_component_has_valid_parent<T: Component>(
6363
let parent = parent.get();
6464
if !component_query.contains(parent) && !already_diagnosed.contains(&entity) {
6565
already_diagnosed.insert(entity);
66-
bevy_utils::tracing::warn!(
66+
log::warn!(
6767
"warning[B0004]: {name} with the {ty_name} component has a parent without {ty_name}.\n\
6868
This will cause inconsistent behaviors! See: https://bevyengine.org/learn/errors/b0004",
6969
ty_name = ShortName::of::<T>(),

crates/bevy_reflect/src/impls/smallvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::any::Any;
44
use smallvec::{Array as SmallArray, SmallVec};
55

66
#[cfg(not(feature = "std"))]
7-
use alloc::{format, vec};
7+
use alloc::{format, vec, vec::Vec};
88

99
use crate::{
1010
self as bevy_reflect, utility::GenericTypeInfoCell, ApplyError, FromReflect, FromType,

tools/ci/src/commands/compile_check_no_std.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ impl Prepare for CompileCheckNoStdCommand {
110110
"Please fix compiler errors in output above for bevy_app no_std compatibility.",
111111
));
112112

113+
commands.push(PreparedCommand::new::<Self>(
114+
cmd!(
115+
sh,
116+
"cargo check -p bevy_hierarchy --no-default-features --features bevy_app,reflect --target {target}"
117+
),
118+
"Please fix compiler errors in output above for bevy_hierarchy no_std compatibility.",
119+
));
120+
113121
commands
114122
}
115123
}

0 commit comments

Comments
 (0)