Skip to content

Commit

Permalink
Disentangle bevy_utils/bevy_core's reexported dependencies (#12313)
Browse files Browse the repository at this point in the history
# Objective
Make bevy_utils less of a compilation bottleneck. Tackle #11478.

## Solution
* Move all of the directly reexported dependencies and move them to
where they're actually used.
* Remove the UUID utilities that have gone unused since `TypePath` took
over for `TypeUuid`.
* There was also a extraneous bytemuck dependency on `bevy_core` that
has not been used for a long time (since `encase` became the primary way
to prepare GPU buffers).
* Remove the `all_tuples` macro reexport from bevy_ecs since it's
accessible from `bevy_utils`.

---

## Changelog
Removed: Many of the reexports from bevy_utils (petgraph, uuid, nonmax,
smallvec, and thiserror).
Removed: bevy_core's reexports of bytemuck.

## Migration Guide
bevy_utils' reexports of petgraph, uuid, nonmax, smallvec, and thiserror
have been removed.

bevy_core' reexports of bytemuck's types has been removed. 

Add them as dependencies in your own crate instead.
  • Loading branch information
james7132 authored Mar 7, 2024
1 parent a1974a4 commit 512b746
Show file tree
Hide file tree
Showing 57 changed files with 81 additions and 125 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ bytemuck = "1.7"
futures-lite = "2.0.1"
crossbeam-channel = "0.5.0"
argh = "0.1.12"
thiserror = "1.0"

[[example]]
name = "hello_world"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.14.0-dev" }

# other
sha1_smol = { version = "1.0" }
uuid = { version = "1.7", features = ["v5"] }
uuid = { version = "1.7", features = ["v4"] }

[lints]
workspace = true
3 changes: 2 additions & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use bevy_render::mesh::morph::MorphWeights;
use bevy_time::Time;
use bevy_transform::{prelude::Transform, TransformSystem};
use bevy_utils::hashbrown::HashMap;
use bevy_utils::{tracing::error, NoOpHash, Uuid};
use bevy_utils::{tracing::error, NoOpHash};
use sha1_smol::Sha1;
use uuid::Uuid;

#[allow(missing_docs)]
pub mod prelude {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
serde = { version = "1.0", features = ["derive"], optional = true }
ron = { version = "0.8.0", optional = true }
downcast-rs = "1.2.0"

thiserror = "1.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2" }
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ use bevy_ecs::{
InternedScheduleLabel, ScheduleBuildSettings, ScheduleLabel,
},
};
use bevy_utils::{intern::Interned, thiserror::Error, tracing::debug, HashMap, HashSet};
use bevy_utils::{intern::Interned, tracing::debug, HashMap, HashSet};
use std::{
fmt::Debug,
panic::{catch_unwind, resume_unwind, AssertUnwindSafe},
};
use thiserror::Error;

#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ pub trait Plugins<Marker>: sealed::Plugins<Marker> {}
impl<Marker, T> Plugins<Marker> for T where T: sealed::Plugins<Marker> {}

mod sealed {

use bevy_ecs::all_tuples;
use bevy_utils::all_tuples;

use crate::{App, AppError, Plugin, PluginGroup};

Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ watch = []
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
bevy_asset_macros = { path = "macros", version = "0.14.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
"uuid",
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }

Expand All @@ -37,6 +39,7 @@ parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
ron = "0.8"
serde = { version = "1", features = ["derive"] }
thiserror = "1.0"
uuid = { version = "1.0", features = ["v4"] }

[target.'cfg(target_os = "android")'.dependencies]
bevy_winit = { path = "../bevy_winit", version = "0.14.0-dev" }
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_ecs::{
system::{Res, ResMut, Resource},
};
use bevy_reflect::{Reflect, TypePath};
use bevy_utils::{HashMap, Uuid};
use bevy_utils::HashMap;
use crossbeam_channel::{Receiver, Sender};
use serde::{Deserialize, Serialize};
use std::{
Expand All @@ -17,6 +17,7 @@ use std::{
sync::{atomic::AtomicU32, Arc},
};
use thiserror::Error;
use uuid::Uuid;

/// A generational runtime-only identifier for a specific [`Asset`] stored in [`Assets`]. This is optimized for efficient runtime
/// usage and is not suitable for identifying assets across app runs.
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use crate::{
};
use bevy_ecs::prelude::*;
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
use bevy_utils::{get_short_name, Uuid};
use bevy_utils::get_short_name;
use crossbeam_channel::{Receiver, Sender};
use std::{
any::TypeId,
hash::{Hash, Hasher},
sync::Arc,
};
use thiserror::Error;
use uuid::Uuid;

/// Provides [`Handle`] and [`UntypedHandle`] _for a specific asset type_.
/// This should _only_ be used for one specific asset type.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Asset, AssetIndex};
use bevy_reflect::Reflect;
use bevy_utils::Uuid;
use uuid::Uuid;

use std::{
any::TypeId,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }

# other
bytemuck = "1.5"
serde = { version = "1.0", optional = true }
uuid = "1.0"

[features]
serialize = ["dep:serde"]
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod serde;
mod task_pool_options;

use bevy_ecs::system::Resource;
pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable};
pub use name::*;
pub use task_pool_options::*;

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
serde = { version = "1", features = ["derive"] }
bitflags = "2.3"
radsort = "0.1"
nonmax = "0.5"

[lints]
workspace = true
3 changes: 2 additions & 1 deletion crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ use bevy_render::{
render_resource::CachedRenderPipelineId,
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::{nonmax::NonMaxU32, FloatOrd};
use bevy_utils::FloatOrd;
use nonmax::NonMaxU32;

use crate::{tonemapping::TonemappingNode, upscaling::UpscalingNode};

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ use bevy_render::{
view::{ExtractedView, ViewDepthTexture, ViewTarget},
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::{nonmax::NonMaxU32, tracing::warn, FloatOrd, HashMap};
use bevy_utils::{tracing::warn, FloatOrd, HashMap};
use nonmax::NonMaxU32;

use crate::{
core_3d::main_transmissive_pass_3d_node::MainTransmissivePass3dNode,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/deferred/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevy_render::{
render_phase::{CachedRenderPipelinePhaseItem, DrawFunctionId, PhaseItem},
render_resource::{CachedRenderPipelineId, TextureFormat},
};
use bevy_utils::nonmax::NonMaxU32;
use nonmax::NonMaxU32;

pub const DEFERRED_PREPASS_FORMAT: TextureFormat = TextureFormat::Rgba32Uint;
pub const DEFERRED_LIGHTING_PASS_ID_FORMAT: TextureFormat = TextureFormat::R8Uint;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use bevy_render::{
render_resource::{CachedRenderPipelineId, Extent3d, TextureFormat, TextureView},
texture::ColorAttachment,
};
use bevy_utils::nonmax::NonMaxU32;
use nonmax::NonMaxU32;

pub const NORMAL_PREPASS_FORMAT: TextureFormat = TextureFormat::Rgb10a2Unorm;
pub const MOTION_VECTOR_PREPASS_FORMAT: TextureFormat = TextureFormat::Rg16Float;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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"

bitflags = "2.3"
concurrent-queue = "2.4.0"
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub mod prelude {
};
}

pub use bevy_utils::all_tuples;

#[cfg(test)]
mod tests {
use crate as bevy_ecs;
Expand Down
6 changes: 2 additions & 4 deletions crates/bevy_ecs/src/schedule/graph_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::fmt::Debug;

use bevy_utils::{
petgraph::{algo::TarjanScc, graphmap::NodeTrait, prelude::*},
HashMap, HashSet,
};
use bevy_utils::{HashMap, HashSet};
use fixedbitset::FixedBitSet;
use petgraph::{algo::TarjanScc, graphmap::NodeTrait, prelude::*};

use crate::schedule::set::*;

Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use std::{
use bevy_utils::tracing::info_span;
use bevy_utils::{default, tracing::info};
use bevy_utils::{
petgraph::{algo::TarjanScc, prelude::*},
thiserror::Error,
tracing::{error, warn},
HashMap, HashSet,
};

use fixedbitset::FixedBitSet;
use petgraph::{algo::TarjanScc, prelude::*};
use thiserror::Error;

use crate::{
self as bevy_ecs,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/stepping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::{
system::{IntoSystem, ResMut, Resource},
};
use bevy_utils::{
thiserror::Error,
tracing::{error, info, warn},
TypeIdMap,
};
use thiserror::Error;

#[cfg(test)]
use bevy_utils::tracing::debug;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_gizmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.14.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_core = { path = "../bevy_core", version = "0.14.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.14.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.14.0-dev" }
bevy_gizmos_macros = { path = "macros", version = "0.14.0-dev" }

bytemuck = "1.0"

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use aabb::AabbGizmoPlugin;
use bevy_app::{App, Last, Plugin};
use bevy_asset::{load_internal_asset, Asset, AssetApp, Assets, Handle};
use bevy_color::LinearRgba;
use bevy_core::cast_slice;
use bevy_ecs::{
component::Component,
query::ROQueryItem,
Expand All @@ -83,6 +82,7 @@ use bevy_render::{
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::TypeIdMap;
use bytemuck::cast_slice;
use config::{
DefaultGizmoConfigGroup, GizmoConfig, GizmoConfigGroup, GizmoConfigStore, GizmoMeshConfig,
};
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ base64 = "0.21.5"
percent-encoding = "2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
smallvec = "1.11"

[lints]
workspace = true
6 changes: 2 additions & 4 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ use bevy_scene::Scene;
use bevy_tasks::IoTaskPool;
use bevy_transform::components::Transform;
use bevy_utils::tracing::{error, info_span, warn};
use bevy_utils::{
smallvec::{smallvec, SmallVec},
HashMap, HashSet,
};
use bevy_utils::{HashMap, HashSet};
use gltf::{
accessor::Iter,
mesh::{util::ReadIndices, Mode},
texture::{Info, MagFilter, MinFilter, TextureTransform, WrappingMode},
Material, Node, Primitive, Semantic,
};
use serde::{Deserialize, Serialize};
use smallvec::{smallvec, SmallVec};
use std::io::Error;
use std::{
collections::VecDeque,
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_hierarchy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ bevy_core = { path = "../bevy_core", version = "0.14.0-dev", optional = true }
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev", default-features = false }
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
"bevy",
"smallvec",
], optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }

smallvec = { version = "1.11", features = ["union", "const_generics"] }

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/bevy_hierarchy/src/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_ecs::{
system::{Commands, EntityCommands},
world::{Command, EntityWorldMut, World},
};
use bevy_utils::smallvec::{smallvec, SmallVec};
use smallvec::{smallvec, SmallVec};

// Do not use `world.send_event_batch` as it prints error message when the Events are not available in the world,
// even though it's a valid use case to execute commands on a world without events. Loading a GLTF file for example
Expand Down Expand Up @@ -696,7 +696,7 @@ mod tests {
components::{Children, Parent},
HierarchyEvent::{self, ChildAdded, ChildMoved, ChildRemoved},
};
use bevy_utils::smallvec::{smallvec, SmallVec};
use smallvec::{smallvec, SmallVec};

use bevy_ecs::{
component::Component,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_hierarchy/src/components/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bevy_ecs::{
prelude::FromWorld,
world::World,
};
use bevy_utils::smallvec::SmallVec;
use core::slice;
use smallvec::SmallVec;
use std::ops::Deref;

/// Contains references to the child entities of this entity.
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fixedbitset = "0.4"
bytemuck = { version = "1", features = ["derive"] }
radsort = "0.1"
smallvec = "1.6"
nonmax = "0.5"

[lints]
workspace = true
6 changes: 2 additions & 4 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ use bevy_render::{
use bevy_transform::{components::GlobalTransform, prelude::Transform};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
use bevy_utils::{
nonmax::NonMaxU32,
tracing::{error, warn},
};
use bevy_utils::tracing::{error, warn};
use nonmax::NonMaxU32;
use std::{hash::Hash, num::NonZeroU64, ops::Range};

use crate::*;
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ keywords = ["bevy"]
readme = "README.md"

[features]
default = []
default = ["smallvec"]
# When enabled, provides Bevy-related reflection implementations
bevy = ["smallvec", "bevy_math", "smol_str"]
glam = ["dep:glam"]
bevy_math = ["glam", "dep:bevy_math"]
smallvec = []
smallvec = ["dep:smallvec"]
uuid = ["dep:uuid"]
# When enabled, allows documentation comments to be accessed via reflection
documentation = ["bevy_reflect_derive/documentation"]

Expand All @@ -33,9 +34,11 @@ erased-serde = "0.4"
downcast-rs = "1.2"
thiserror = "1.0"
serde = "1"
smallvec = { version = "1.11", optional = true }

glam = { version = "0.25", features = ["serde"], optional = true }
smol_str = { version = "0.2.0", optional = true }
uuid = { version = "1.0", optional = true, features = ["v4", "serde"] }

[dev-dependencies]
ron = "0.8.0"
Expand Down
Loading

0 comments on commit 512b746

Please sign in to comment.