From 7a37c4a109b99720ea6b7855e44c09f37cc240d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Tue, 25 Mar 2025 05:09:46 +0100 Subject: [PATCH] Update bincode to 2.0 (#18396) # Objective Update bincode ## Solution Fix compilation for #18352 by reading the [migration guide](https://github.com/bincode-org/bincode/blob/trunk/docs/migration_guide.md) Also fixes an unused import warning I got when running the tests for bevy_reflect. --- crates/bevy_reflect/Cargo.toml | 2 +- crates/bevy_reflect/src/serde/de/mod.rs | 8 +++----- crates/bevy_reflect/src/serde/ser/mod.rs | 6 ++++-- crates/bevy_scene/Cargo.toml | 2 +- crates/bevy_scene/src/serde.rs | 11 +++++------ 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 0f54d8cccf..5409726474 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -118,7 +118,7 @@ wgpu-types = { version = "24", features = [ [dev-dependencies] ron = "0.8.0" rmp-serde = "1.1" -bincode = "1.3" +bincode = { version = "2.0", features = ["serde"] } serde_json = "1.0" serde = { version = "1", features = ["derive"] } static_assertions = "1.1.0" diff --git a/crates/bevy_reflect/src/serde/de/mod.rs b/crates/bevy_reflect/src/serde/de/mod.rs index c6907b56ec..c11e75dec1 100644 --- a/crates/bevy_reflect/src/serde/de/mod.rs +++ b/crates/bevy_reflect/src/serde/de/mod.rs @@ -30,7 +30,6 @@ mod tests { vec, vec::Vec, }; - use bincode::Options; use core::{any::TypeId, f32::consts::PI, ops::RangeInclusive}; use serde::{de::DeserializeSeed, Deserialize}; use serde::{de::IgnoredAny, Deserializer}; @@ -470,10 +469,9 @@ mod tests { let deserializer = ReflectDeserializer::new(®istry); - let dynamic_output = bincode::DefaultOptions::new() - .with_fixint_encoding() - .deserialize_seed(deserializer, &input) - .unwrap(); + let config = bincode::config::standard().with_fixed_int_encoding(); + let (dynamic_output, _read_bytes) = + bincode::serde::seed_decode_from_slice(deserializer, &input, config).unwrap(); let output = ::from_reflect(dynamic_output.as_ref()).unwrap(); assert_eq!(expected, output); diff --git a/crates/bevy_reflect/src/serde/ser/mod.rs b/crates/bevy_reflect/src/serde/ser/mod.rs index 3844c2a2cb..6027a0effa 100644 --- a/crates/bevy_reflect/src/serde/ser/mod.rs +++ b/crates/bevy_reflect/src/serde/ser/mod.rs @@ -24,8 +24,9 @@ mod tests { serde::{ReflectSerializer, ReflectSerializerProcessor}, PartialReflect, Reflect, ReflectSerialize, Struct, TypeRegistry, }; + #[cfg(feature = "functions")] + use alloc::boxed::Box; use alloc::{ - boxed::Box, string::{String, ToString}, vec, vec::Vec, @@ -348,7 +349,8 @@ mod tests { let registry = get_registry(); let serializer = ReflectSerializer::new(&input, ®istry); - let bytes = bincode::serialize(&serializer).unwrap(); + let config = bincode::config::standard().with_fixed_int_encoding(); + let bytes = bincode::serde::encode_to_vec(&serializer, config).unwrap(); let expected: Vec = vec![ 1, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 98, 101, 118, 121, 95, 114, 101, 102, diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index d7fb04aaba..54cb344a82 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -43,7 +43,7 @@ uuid = { version = "1.13.1", default-features = false, features = ["js"] } [dev-dependencies] postcard = { version = "1.0", features = ["alloc"] } -bincode = "1.3" +bincode = { version = "2.0", features = ["serde"] } rmp-serde = "1.1" [lints] diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 103e48e50a..35b68b85be 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -522,7 +522,6 @@ mod tests { world::FromWorld, }; use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; - use bincode::Options; use serde::{de::DeserializeSeed, Deserialize, Serialize}; use std::io::BufReader; @@ -894,8 +893,9 @@ mod tests { let scene = DynamicScene::from_world(&world); + let config = bincode::config::standard().with_fixed_int_encoding(); let scene_serializer = SceneSerializer::new(&scene, registry); - let serialized_scene = bincode::serialize(&scene_serializer).unwrap(); + let serialized_scene = bincode::serde::encode_to_vec(&scene_serializer, config).unwrap(); assert_eq!( vec![ @@ -913,10 +913,9 @@ mod tests { type_registry: registry, }; - let deserialized_scene = bincode::DefaultOptions::new() - .with_fixint_encoding() - .deserialize_seed(scene_deserializer, &serialized_scene) - .unwrap(); + let (deserialized_scene, _read_bytes) = + bincode::serde::seed_decode_from_slice(scene_deserializer, &serialized_scene, config) + .unwrap(); assert_eq!(1, deserialized_scene.entities.len()); assert_scene_eq(&scene, &deserialized_scene);