From 934f2cfadf69adc455a3c01bc4a30e904bea67c2 Mon Sep 17 00:00:00 2001 From: James Liu Date: Mon, 8 Apr 2024 12:45:42 -0700 Subject: [PATCH] Clean up some low level dependencies (#12858) # Objective Minimize the number of dependencies low in the tree. ## Solution * Remove the dependency on rustc-hash in bevy_ecs (not used) and bevy_macro_utils (only used in one spot). * Deduplicate the dependency on `sha1_smol` with the existing blake3 dependency already being used for bevy_asset. * Remove the unused `ron` dependency on `bevy_app` * Make the `serde` dependency for `bevy_ecs` optional. It's only used for serializing Entity. * Change the `wgpu` dependency to `wgpu-types`, and make it optional for `bevy_color`. * Remove the unused `thread-local` dependency on `bevy_render`. * Make multiple dependencies for `bevy_tasks` optional and enabled only when running with the `multi-threaded` feature. Preferably they'd be disabled all the time on wasm, but I couldn't find a clean way to do this. --- ## Changelog TODO ## Migration Guide TODO --- crates/bevy_animation/Cargo.toml | 2 +- crates/bevy_animation/src/lib.rs | 11 ++++++----- crates/bevy_app/Cargo.toml | 2 +- crates/bevy_color/Cargo.toml | 2 +- crates/bevy_color/src/linear_rgba.rs | 5 +++-- crates/bevy_ecs/Cargo.toml | 5 ++--- crates/bevy_ecs/src/entity/mod.rs | 12 +++++++++--- crates/bevy_macro_utils/Cargo.toml | 1 - crates/bevy_macro_utils/src/label.rs | 4 ++-- crates/bevy_pbr/Cargo.toml | 6 +++--- crates/bevy_render/Cargo.toml | 2 +- crates/bevy_scene/Cargo.toml | 2 +- crates/bevy_tasks/Cargo.toml | 8 ++++---- 13 files changed, 34 insertions(+), 28 deletions(-) diff --git a/crates/bevy_animation/Cargo.toml b/crates/bevy_animation/Cargo.toml index 52c2786b84..02788870d7 100644 --- a/crates/bevy_animation/Cargo.toml +++ b/crates/bevy_animation/Cargo.toml @@ -33,7 +33,7 @@ fixedbitset = "0.5" petgraph = { version = "0.6", features = ["serde-1"] } ron = "0.8" serde = "1" -sha1_smol = { version = "1.0" } +blake3 = { version = "1.0" } thiserror = "1" thread_local = "1" uuid = { version = "1.7", features = ["v4"] } diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index c4f8bc9248..5837c86511 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -39,7 +39,6 @@ use graph::{AnimationGraph, AnimationNodeIndex}; use petgraph::graph::NodeIndex; use petgraph::Direction; use prelude::{AnimationGraphAssetLoader, AnimationTransitions}; -use sha1_smol::Sha1; use thread_local::ThreadLocal; use uuid::Uuid; @@ -1160,10 +1159,12 @@ impl AnimationTargetId { /// Typically, this will be the path from the animation root to the /// animation target (e.g. bone) that is to be animated. pub fn from_names<'a>(names: impl Iterator) -> Self { - let mut sha1 = Sha1::new(); - sha1.update(ANIMATION_TARGET_NAMESPACE.as_bytes()); - names.for_each(|name| sha1.update(name.as_bytes())); - let hash = sha1.digest().bytes()[0..16].try_into().unwrap(); + let mut blake3 = blake3::Hasher::new(); + blake3.update(ANIMATION_TARGET_NAMESPACE.as_bytes()); + for name in names { + blake3.update(name.as_bytes()); + } + let hash = blake3.finalize().as_bytes()[0..16].try_into().unwrap(); Self(*uuid::Builder::from_sha1_bytes(hash).as_uuid()) } diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 75136f9db9..64333bfc98 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -13,6 +13,7 @@ trace = [] bevy_debug_stepping = [] default = ["bevy_reflect"] bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"] +serialize = ["bevy_ecs/serde"] [dependencies] # bevy @@ -24,7 +25,6 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } # other serde = { version = "1.0", features = ["derive"], optional = true } -ron = { version = "0.8.0", optional = true } downcast-rs = "1.2.0" thiserror = "1.0" diff --git a/crates/bevy_color/Cargo.toml b/crates/bevy_color/Cargo.toml index 733a0ad3cc..68e1dde3ea 100644 --- a/crates/bevy_color/Cargo.toml +++ b/crates/bevy_color/Cargo.toml @@ -16,7 +16,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [ bytemuck = "1" serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" -wgpu = { version = "0.19.3", default-features = false } +wgpu-types = { version = "0.19", default-features = false, optional = true } encase = { version = "0.7", default-features = false } [features] diff --git a/crates/bevy_color/src/linear_rgba.rs b/crates/bevy_color/src/linear_rgba.rs index 946e461694..bd75054ba7 100644 --- a/crates/bevy_color/src/linear_rgba.rs +++ b/crates/bevy_color/src/linear_rgba.rs @@ -293,9 +293,10 @@ impl From for Vec4 { } } -impl From for wgpu::Color { +#[cfg(feature = "wgpu-types")] +impl From for wgpu_types::Color { fn from(color: LinearRgba) -> Self { - wgpu::Color { + wgpu_types::Color { r: color.red as f64, g: color.green as f64, b: color.blue as f64, diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 5c6f7c8c47..62a7fce655 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -21,13 +21,12 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", optional = tr bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } bevy_ecs_macros = { path = "macros", version = "0.14.0-dev" } -petgraph = "0.6" +petgraph = "0.6" bitflags = "2.3" concurrent-queue = "2.4.0" fixedbitset = "0.5" -rustc-hash = "1.1" -serde = "1" +serde = { version = "1", optional = true, default-features = false } thiserror = "1.0" nonmax = "0.5" arrayvec = { version = "0.7.4", optional = true } diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 3013b9bb8a..721102a3cd 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -37,7 +37,9 @@ //! [`EntityWorldMut::remove`]: crate::world::EntityWorldMut::remove mod map_entities; #[cfg(feature = "bevy_reflect")] -use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::Reflect; +#[cfg(all(feature = "bevy_reflect", feature = "serde"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; pub use map_entities::*; mod hash; @@ -55,6 +57,7 @@ use crate::{ }, storage::{SparseSetIndex, TableId, TableRow}, }; +#[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use std::{fmt, hash::Hash, mem, num::NonZeroU32, sync::atomic::Ordering}; @@ -141,9 +144,10 @@ type IdCursor = isize; /// [SemVer]: https://semver.org/ #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "bevy_reflect", derive(Reflect))] +#[cfg_attr(feature = "bevy_reflect", reflect_value(Hash, PartialEq))] #[cfg_attr( - feature = "bevy_reflect", - reflect_value(Hash, PartialEq, Serialize, Deserialize) + all(feature = "bevy_reflect", feature = "serde"), + reflect_value(Serialize, Deserialize) )] // Alignment repr necessary to allow LLVM to better output // optimised codegen for `to_bits`, `PartialEq` and `Ord`. @@ -364,6 +368,7 @@ impl From for Identifier { } } +#[cfg(feature = "serde")] impl Serialize for Entity { fn serialize(&self, serializer: S) -> Result where @@ -373,6 +378,7 @@ impl Serialize for Entity { } } +#[cfg(feature = "serde")] impl<'de> Deserialize<'de> for Entity { fn deserialize(deserializer: D) -> Result where diff --git a/crates/bevy_macro_utils/Cargo.toml b/crates/bevy_macro_utils/Cargo.toml index 408716edd4..397cb0fcad 100644 --- a/crates/bevy_macro_utils/Cargo.toml +++ b/crates/bevy_macro_utils/Cargo.toml @@ -14,7 +14,6 @@ toml_edit = { version = "0.22.7", default-features = false, features = [ ] } syn = "2.0" quote = "1.0" -rustc-hash = "1.0" proc-macro2 = "1.0" [lints] diff --git a/crates/bevy_macro_utils/src/label.rs b/crates/bevy_macro_utils/src/label.rs index a9fe177cb3..43f393739b 100644 --- a/crates/bevy_macro_utils/src/label.rs +++ b/crates/bevy_macro_utils/src/label.rs @@ -1,6 +1,6 @@ use proc_macro::{TokenStream, TokenTree}; use quote::{quote, quote_spanned}; -use rustc_hash::FxHashSet; +use std::collections::HashSet; use syn::{spanned::Spanned, Ident}; /// Finds an identifier that will not conflict with the specified set of tokens. @@ -15,7 +15,7 @@ pub fn ensure_no_collision(value: Ident, haystack: TokenStream) -> Ident { // List of token streams that will be visited in future loop iterations. let mut unvisited = vec![haystack]; // Identifiers we have found while searching tokens. - let mut found = FxHashSet::default(); + let mut found = HashSet::new(); while let Some(tokens) = unvisited.pop() { for t in tokens { match t { diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index dc5b35a97b..425dbb3426 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -16,7 +16,7 @@ shader_format_glsl = ["bevy_render/shader_format_glsl"] trace = ["bevy_render/trace"] ios_simulator = ["bevy_render/ios_simulator"] # Enables the meshlet renderer for dense high-poly scenes (experimental) -meshlet = [] +meshlet = ["dep:range-alloc", "dep:bincode"] # Enables processing meshes into meshlet meshes meshlet_processor = ["dep:meshopt", "dep:thiserror"] @@ -47,8 +47,8 @@ bytemuck = { version = "1", features = ["derive", "must_cast"] } radsort = "0.1" smallvec = "1.6" serde = { version = "1", features = ["derive", "rc"] } -bincode = "1" -range-alloc = "0.1" +bincode = { version = "1", optional = true } +range-alloc = { version = "0.1", optional = true } nonmax = "0.5" static_assertions = "1" diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 388c850e61..bed0496b44 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -41,6 +41,7 @@ bevy_app = { path = "../bevy_app", version = "0.14.0-dev" } bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" } bevy_color = { path = "../bevy_color", version = "0.14.0-dev", features = [ "serialize", + "wgpu-types", ] } bevy_core = { path = "../bevy_core", version = "0.14.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" } @@ -82,7 +83,6 @@ serde = { version = "1", features = ["derive"] } bitflags = { version = "2.3", features = ["serde"] } bytemuck = { version = "1.5", features = ["derive", "must_cast"] } downcast-rs = "1.2.0" -thread_local = "1.1" thiserror = "1.0" futures-lite = "2.0.1" hexasphere = "10.0" diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 7a3236be8a..5cf1904f7a 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"] +serialize = ["dep:serde", "uuid/serde", "bevy_app/serialize"] [dependencies] # bevy diff --git a/crates/bevy_tasks/Cargo.toml b/crates/bevy_tasks/Cargo.toml index b3a70bafbd..98c4edbb8d 100644 --- a/crates/bevy_tasks/Cargo.toml +++ b/crates/bevy_tasks/Cargo.toml @@ -9,15 +9,15 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] -multi-threaded = [] +multi-threaded = ["dep:async-channel", "dep:async-task", "dep:concurrent-queue"] [dependencies] futures-lite = "2.0.1" async-executor = "1.7.2" -async-channel = "2.2.0" +async-channel = { version = "2.2.0", optional = true } async-io = { version = "2.0.0", optional = true } -async-task = "4.2.0" -concurrent-queue = "2.0.0" +async-task = { version = "4.2.0", optional = true } +concurrent-queue = { version = "2.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-futures = "0.4"