Skip to content

Commit 110c82c

Browse files
committed
[Fixes #6030] Bevy scene optional serde (#6076)
# Objective Fixes #6030, making ``serde`` optional. ## Solution This was solved by making a ``serialize`` feature that can activate ``serde``, which is now optional. When ``serialize`` is deactivated, the ``Plugin`` implementation for ``ScenePlugin`` does nothing. Co-authored-by: Linus Käll <[email protected]>
1 parent 3ac06b5 commit 110c82c

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ wav = ["bevy_audio/wav"]
4545
# Enable watching file system for asset hot reload
4646
filesystem_watcher = ["bevy_asset/filesystem_watcher"]
4747

48-
serialize = ["bevy_core/serialize", "bevy_input/serialize", "bevy_time/serialize", "bevy_window/serialize", "bevy_transform/serialize", "bevy_math/serialize"]
48+
serialize = ["bevy_core/serialize", "bevy_input/serialize", "bevy_time/serialize", "bevy_window/serialize", "bevy_transform/serialize", "bevy_math/serialize", "bevy_scene/serialize"]
4949

5050
# Display server protocol support (X11 is enabled by default)
5151
wayland = ["bevy_winit/wayland"]

crates/bevy_scene/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repository = "https://github.com/bevyengine/bevy"
88
license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

11+
[features]
12+
default = ["serialize"]
13+
serialize = ["dep:serde", "uuid/serde"]
14+
1115
[dependencies]
1216
# bevy
1317
bevy_app = { path = "../bevy_app", version = "0.9.0" }
@@ -21,9 +25,9 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0" }
2125
bevy_render = { path = "../bevy_render", version = "0.9.0" }
2226

2327
# other
24-
serde = { version = "1.0", features = ["derive"] }
28+
serde = { version = "1.0", features = ["derive"], optional = true }
2529
ron = "0.8.0"
26-
uuid = { version = "1.1", features = ["v4", "serde"] }
30+
uuid = { version = "1.1", features = ["v4"] }
2731
anyhow = "1.0.4"
2832
thiserror = "1.0"
2933

crates/bevy_scene/src/dynamic_scene.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{serde::SceneSerializer, DynamicSceneBuilder, Scene, SceneSpawnError};
1+
use crate::{DynamicSceneBuilder, Scene, SceneSpawnError};
22
use anyhow::Result;
33
use bevy_app::AppTypeRegistry;
44
use bevy_ecs::{
@@ -7,6 +7,10 @@ use bevy_ecs::{
77
world::World,
88
};
99
use bevy_reflect::{Reflect, TypeRegistryArc, TypeUuid};
10+
11+
#[cfg(feature = "serialize")]
12+
use crate::serde::SceneSerializer;
13+
#[cfg(feature = "serialize")]
1014
use serde::Serialize;
1115

1216
/// A collection of serializable dynamic entities, each with its own run-time defined set of components.
@@ -116,12 +120,14 @@ impl DynamicScene {
116120

117121
// TODO: move to AssetSaver when it is implemented
118122
/// Serialize this dynamic scene into rust object notation (ron).
123+
#[cfg(feature = "serialize")]
119124
pub fn serialize_ron(&self, registry: &TypeRegistryArc) -> Result<String, ron::Error> {
120125
serialize_ron(SceneSerializer::new(self, registry))
121126
}
122127
}
123128

124129
/// Serialize a given Rust data structure into rust object notation (ron).
130+
#[cfg(feature = "serialize")]
125131
pub fn serialize_ron<S>(serialize: S) -> Result<String, ron::Error>
126132
where
127133
S: Serialize,

crates/bevy_scene/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod dynamic_scene_builder;
44
mod scene;
55
mod scene_loader;
66
mod scene_spawner;
7+
8+
#[cfg(feature = "serialize")]
79
pub mod serde;
810

911
pub use bundle::*;
@@ -27,6 +29,7 @@ use bevy_ecs::prelude::*;
2729
#[derive(Default)]
2830
pub struct ScenePlugin;
2931

32+
#[cfg(feature = "serialize")]
3033
impl Plugin for ScenePlugin {
3134
fn build(&self, app: &mut App) {
3235
app.add_asset::<DynamicScene>()
@@ -38,3 +41,8 @@ impl Plugin for ScenePlugin {
3841
.add_system_to_stage(CoreStage::PreUpdate, scene_spawner);
3942
}
4043
}
44+
45+
#[cfg(not(feature = "serialize"))]
46+
impl Plugin for ScenePlugin {
47+
fn build(&self, _: &mut App) {}
48+
}

crates/bevy_scene/src/scene_loader.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
55
use bevy_ecs::world::{FromWorld, World};
66
use bevy_reflect::TypeRegistryArc;
77
use bevy_utils::BoxedFuture;
8+
9+
#[cfg(feature = "serialize")]
810
use serde::de::DeserializeSeed;
911

1012
#[derive(Debug)]
@@ -21,6 +23,7 @@ impl FromWorld for SceneLoader {
2123
}
2224
}
2325

26+
#[cfg(feature = "serialize")]
2427
impl AssetLoader for SceneLoader {
2528
fn load<'a>(
2629
&'a self,

0 commit comments

Comments
 (0)