From 93f3432400deab424901c43512e7c174814fa7b1 Mon Sep 17 00:00:00 2001 From: Periwink Date: Mon, 10 Jun 2024 12:37:59 -0400 Subject: [PATCH] Update serialize flag for bevy_ecs (#13740) # Objective There were some issues with the `serialize` feature: - `bevy_app` had a `serialize` feature and a dependency on `serde` even there is no usage of serde at all inside `bevy_app` - the `bevy_app/serialize` feature enabled `bevy_ecs/serde`, which is strange - `bevy_internal/serialize` did not enable `bevy_app/serialize` so there was no way of serializing an Entity in bevy 0.14 ## Solution - Remove `serde` and `bevy_app/serialize` - Add a `serialize` flag on `bevy_ecs` that enables `serde` - ` bevy_internal/serialize` now enables `bevy_ecs/serialize` --- crates/bevy_app/Cargo.toml | 2 -- crates/bevy_ecs/Cargo.toml | 1 + crates/bevy_ecs/src/entity/mod.rs | 10 +++++----- crates/bevy_internal/Cargo.toml | 1 + crates/bevy_scene/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 64333bfc98..5f968f64af 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -13,7 +13,6 @@ trace = [] bevy_debug_stepping = [] default = ["bevy_reflect"] bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"] -serialize = ["bevy_ecs/serde"] [dependencies] # bevy @@ -24,7 +23,6 @@ bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } # other -serde = { version = "1.0", features = ["derive"], optional = true } downcast-rs = "1.2.0" thiserror = "1.0" diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 8b7eee8098..87f23a574b 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -15,6 +15,7 @@ trace = [] multi_threaded = ["bevy_tasks/multi_threaded", "arrayvec"] bevy_debug_stepping = [] default = ["bevy_reflect"] +serialize = ["dep:serde"] [dependencies] bevy_ptr = { path = "../bevy_ptr", version = "0.14.0-dev" } diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index d104eb4777..5cefe6a1df 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -38,7 +38,7 @@ mod map_entities; #[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; -#[cfg(all(feature = "bevy_reflect", feature = "serde"))] +#[cfg(all(feature = "bevy_reflect", feature = "serialize"))] use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; pub use map_entities::*; @@ -57,7 +57,7 @@ use crate::{ }, storage::{SparseSetIndex, TableId, TableRow}, }; -#[cfg(feature = "serde")] +#[cfg(feature = "serialize")] use serde::{Deserialize, Serialize}; use std::{fmt, hash::Hash, mem, num::NonZeroU32, sync::atomic::Ordering}; @@ -146,7 +146,7 @@ type IdCursor = isize; #[cfg_attr(feature = "bevy_reflect", derive(Reflect))] #[cfg_attr(feature = "bevy_reflect", reflect_value(Hash, PartialEq))] #[cfg_attr( - all(feature = "bevy_reflect", feature = "serde"), + all(feature = "bevy_reflect", feature = "serialize"), reflect_value(Serialize, Deserialize) )] // Alignment repr necessary to allow LLVM to better output @@ -368,7 +368,7 @@ impl From for Identifier { } } -#[cfg(feature = "serde")] +#[cfg(feature = "serialize")] impl Serialize for Entity { fn serialize(&self, serializer: S) -> Result where @@ -378,7 +378,7 @@ impl Serialize for Entity { } } -#[cfg(feature = "serde")] +#[cfg(feature = "serialize")] impl<'de> Deserialize<'de> for Entity { fn deserialize(deserializer: D) -> Result where diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 8b4b91483e..64264595a2 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -71,6 +71,7 @@ shader_format_spirv = ["bevy_render/shader_format_spirv"] serialize = [ "bevy_core/serialize", "bevy_input/serialize", + "bevy_ecs/serialize", "bevy_time/serialize", "bevy_window/serialize", "bevy_winit?/serialize", diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 5cf1904f7a..ef530a88af 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["bevy"] [features] default = ["serialize"] -serialize = ["dep:serde", "uuid/serde", "bevy_app/serialize"] +serialize = ["dep:serde", "uuid/serde", "bevy_ecs/serialize"] [dependencies] # bevy