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
This commit is contained in:
James Liu 2024-04-08 12:45:42 -07:00 committed by GitHub
parent 627ad6d2cc
commit 934f2cfadf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 34 additions and 28 deletions

View file

@ -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"] }

View file

@ -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<Item = &'a Name>) -> 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())
}

View file

@ -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"

View file

@ -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]

View file

@ -293,9 +293,10 @@ impl From<LinearRgba> for Vec4 {
}
}
impl From<LinearRgba> for wgpu::Color {
#[cfg(feature = "wgpu-types")]
impl From<LinearRgba> 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,

View file

@ -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 }

View file

@ -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<Entity> for Identifier {
}
}
#[cfg(feature = "serde")]
impl Serialize for Entity {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@ -373,6 +378,7 @@ impl Serialize for Entity {
}
}
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for Entity {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where

View file

@ -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]

View file

@ -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 {

View file

@ -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"

View file

@ -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"

View file

@ -10,7 +10,7 @@ keywords = ["bevy"]
[features]
default = ["serialize"]
serialize = ["dep:serde", "uuid/serde"]
serialize = ["dep:serde", "uuid/serde", "bevy_app/serialize"]
[dependencies]
# bevy

View file

@ -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"