From ac06ea3d17b4ebbdaf7e68d2ba0e8283e33be226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 13 Nov 2021 21:15:22 +0000 Subject: [PATCH] default features from `bevy_asset` and `bevy_ecs` can actually be disabled (#3097) # Objective - `bevy_ecs` exposes as an optional feature `bevy_reflect`. Disabling it doesn't compile. - `bevy_asset` exposes as an optional feature `filesystem_watcher`. Disabling it doesn't compile. It is also not possible to disable this feature from Bevy ## Solution - Fix compilation errors when disabling the default features. Make it possible to disable the feature `filesystem_watcher` from Bevy --- Cargo.toml | 4 ++++ crates/bevy_asset/Cargo.toml | 2 +- crates/bevy_asset/src/io/file_asset_io.rs | 19 ++++++++++++++----- crates/bevy_core/Cargo.toml | 4 ++-- crates/bevy_ecs/src/change_detection.rs | 3 +++ crates/bevy_internal/Cargo.toml | 3 +++ crates/bevy_transform/Cargo.toml | 2 +- docs/cargo_features.md | 1 + 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f2c2941978..6386d902d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ default = [ "hdr", "mp3", "x11", + "filesystem_watcher" ] # Force dynamic linking, which improves iterative compile times @@ -68,6 +69,9 @@ mp3 = ["bevy_internal/mp3"] vorbis = ["bevy_internal/vorbis"] wav = ["bevy_internal/wav"] +# Enable watching file system for asset hot reload +filesystem_watcher = ["bevy_internal/filesystem_watcher"] + serialize = ["bevy_internal/serialize"] # Display server protocol support (X11 is enabled by default) diff --git a/crates/bevy_asset/Cargo.toml b/crates/bevy_asset/Cargo.toml index 771421c968..1685b9ee1a 100644 --- a/crates/bevy_asset/Cargo.toml +++ b/crates/bevy_asset/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] -default = ["filesystem_watcher"] +default = [] filesystem_watcher = ["notify"] [dependencies] diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index ee23a6c730..efebb81e49 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -1,15 +1,23 @@ -use crate::{filesystem_watcher::FilesystemWatcher, AssetIo, AssetIoError, AssetServer}; +#[cfg(feature = "filesystem_watcher")] +use crate::{filesystem_watcher::FilesystemWatcher, AssetServer}; +use crate::{AssetIo, AssetIoError}; use anyhow::Result; +#[cfg(feature = "filesystem_watcher")] use bevy_ecs::system::Res; -use bevy_utils::{BoxedFuture, HashSet}; +use bevy_utils::BoxedFuture; +#[cfg(feature = "filesystem_watcher")] +use bevy_utils::HashSet; +#[cfg(feature = "filesystem_watcher")] use crossbeam_channel::TryRecvError; use fs::File; -use io::Read; +#[cfg(feature = "filesystem_watcher")] use parking_lot::RwLock; +#[cfg(feature = "filesystem_watcher")] +use std::sync::Arc; use std::{ - env, fs, io, + env, fs, + io::Read, path::{Path, PathBuf}, - sync::Arc, }; pub struct FileAssetIo { @@ -21,6 +29,7 @@ pub struct FileAssetIo { impl FileAssetIo { pub fn new>(path: P) -> Self { FileAssetIo { + #[cfg(feature = "filesystem_watcher")] filesystem_watcher: Default::default(), root_path: Self::get_root_path().join(path.as_ref()), } diff --git a/crates/bevy_core/Cargo.toml b/crates/bevy_core/Cargo.toml index 2378644498..c94dd5ffc8 100644 --- a/crates/bevy_core/Cargo.toml +++ b/crates/bevy_core/Cargo.toml @@ -11,9 +11,9 @@ keywords = ["bevy"] [dependencies] # bevy -bevy_app = { path = "../bevy_app", version = "0.5.0" } +bevy_app = { path = "../bevy_app", version = "0.5.0", features = ["bevy_reflect"] } bevy_derive = { path = "../bevy_derive", version = "0.5.0" } -bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } +bevy_ecs = { path = "../bevy_ecs", version = "0.5.0", features = ["bevy_reflect"] } bevy_math = { path = "../bevy_math", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] } bevy_tasks = { path = "../bevy_tasks", version = "0.5.0" } diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 3b59303de4..d7dd0067fe 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -1,6 +1,7 @@ //! Types that detect when their internal data mutate. use crate::{component::ComponentTicks, system::Resource}; +#[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; use std::ops::{Deref, DerefMut}; @@ -188,9 +189,11 @@ impl_into_inner!(Mut<'a, T>, T,); impl_debug!(Mut<'a, T>,); /// Unique mutable borrow of a Reflected component +#[cfg(feature = "bevy_reflect")] pub struct ReflectMut<'a> { pub(crate) value: &'a mut dyn Reflect, pub(crate) ticks: Ticks<'a>, } +#[cfg(feature = "bevy_reflect")] change_detection_impl!(ReflectMut<'a>, dyn Reflect,); diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 821e543d14..1a052cdc88 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -29,6 +29,9 @@ mp3 = ["bevy_audio/mp3"] vorbis = ["bevy_audio/vorbis"] wav = ["bevy_audio/wav"] +# Enable watching file system for asset hot reload +filesystem_watcher = ["bevy_asset/filesystem_watcher"] + serialize = ["bevy_input/serialize"] # Display server protocol support (X11 is enabled by default) diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index 1efb017beb..567ba74aad 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } +bevy_ecs = { path = "../bevy_ecs", version = "0.5.0", features = ["bevy_reflect"] } bevy_math = { path = "../bevy_math", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] } bevy_utils = { path = "../bevy_utils", version = "0.5.0" } diff --git a/docs/cargo_features.md b/docs/cargo_features.md index 0bc35f06aa..ff5d4bb1ed 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -14,6 +14,7 @@ |hdr|[HDR](https://en.wikipedia.org/wiki/High_dynamic_range) support.| |mp3|MP3 audio format support.| |x11|Make GUI applications use X11 protocol. You could enable wayland feature to override this.| +|filesystem_watcher|Enable watching the file system for asset hot reload| ## Optional Features