Skip to content

Commit ac06ea3

Browse files
committed
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
1 parent 71f4ff4 commit ac06ea3

File tree

8 files changed

+29
-9
lines changed

8 files changed

+29
-9
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ default = [
2727
"hdr",
2828
"mp3",
2929
"x11",
30+
"filesystem_watcher"
3031
]
3132

3233
# Force dynamic linking, which improves iterative compile times
@@ -68,6 +69,9 @@ mp3 = ["bevy_internal/mp3"]
6869
vorbis = ["bevy_internal/vorbis"]
6970
wav = ["bevy_internal/wav"]
7071

72+
# Enable watching file system for asset hot reload
73+
filesystem_watcher = ["bevy_internal/filesystem_watcher"]
74+
7175
serialize = ["bevy_internal/serialize"]
7276

7377
# Display server protocol support (X11 is enabled by default)

crates/bevy_asset/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

1111
[features]
12-
default = ["filesystem_watcher"]
12+
default = []
1313
filesystem_watcher = ["notify"]
1414

1515
[dependencies]

crates/bevy_asset/src/io/file_asset_io.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
use crate::{filesystem_watcher::FilesystemWatcher, AssetIo, AssetIoError, AssetServer};
1+
#[cfg(feature = "filesystem_watcher")]
2+
use crate::{filesystem_watcher::FilesystemWatcher, AssetServer};
3+
use crate::{AssetIo, AssetIoError};
24
use anyhow::Result;
5+
#[cfg(feature = "filesystem_watcher")]
36
use bevy_ecs::system::Res;
4-
use bevy_utils::{BoxedFuture, HashSet};
7+
use bevy_utils::BoxedFuture;
8+
#[cfg(feature = "filesystem_watcher")]
9+
use bevy_utils::HashSet;
10+
#[cfg(feature = "filesystem_watcher")]
511
use crossbeam_channel::TryRecvError;
612
use fs::File;
7-
use io::Read;
13+
#[cfg(feature = "filesystem_watcher")]
814
use parking_lot::RwLock;
15+
#[cfg(feature = "filesystem_watcher")]
16+
use std::sync::Arc;
917
use std::{
10-
env, fs, io,
18+
env, fs,
19+
io::Read,
1120
path::{Path, PathBuf},
12-
sync::Arc,
1321
};
1422

1523
pub struct FileAssetIo {
@@ -21,6 +29,7 @@ pub struct FileAssetIo {
2129
impl FileAssetIo {
2230
pub fn new<P: AsRef<Path>>(path: P) -> Self {
2331
FileAssetIo {
32+
#[cfg(feature = "filesystem_watcher")]
2433
filesystem_watcher: Default::default(),
2534
root_path: Self::get_root_path().join(path.as_ref()),
2635
}

crates/bevy_core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ keywords = ["bevy"]
1111

1212
[dependencies]
1313
# bevy
14-
bevy_app = { path = "../bevy_app", version = "0.5.0" }
14+
bevy_app = { path = "../bevy_app", version = "0.5.0", features = ["bevy_reflect"] }
1515
bevy_derive = { path = "../bevy_derive", version = "0.5.0" }
16-
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" }
16+
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0", features = ["bevy_reflect"] }
1717
bevy_math = { path = "../bevy_math", version = "0.5.0" }
1818
bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] }
1919
bevy_tasks = { path = "../bevy_tasks", version = "0.5.0" }

crates/bevy_ecs/src/change_detection.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Types that detect when their internal data mutate.
22
33
use crate::{component::ComponentTicks, system::Resource};
4+
#[cfg(feature = "bevy_reflect")]
45
use bevy_reflect::Reflect;
56
use std::ops::{Deref, DerefMut};
67

@@ -188,9 +189,11 @@ impl_into_inner!(Mut<'a, T>, T,);
188189
impl_debug!(Mut<'a, T>,);
189190

190191
/// Unique mutable borrow of a Reflected component
192+
#[cfg(feature = "bevy_reflect")]
191193
pub struct ReflectMut<'a> {
192194
pub(crate) value: &'a mut dyn Reflect,
193195
pub(crate) ticks: Ticks<'a>,
194196
}
195197

198+
#[cfg(feature = "bevy_reflect")]
196199
change_detection_impl!(ReflectMut<'a>, dyn Reflect,);

crates/bevy_internal/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ mp3 = ["bevy_audio/mp3"]
2929
vorbis = ["bevy_audio/vorbis"]
3030
wav = ["bevy_audio/wav"]
3131

32+
# Enable watching file system for asset hot reload
33+
filesystem_watcher = ["bevy_asset/filesystem_watcher"]
34+
3235
serialize = ["bevy_input/serialize"]
3336

3437
# Display server protocol support (X11 is enabled by default)

crates/bevy_transform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ keywords = ["bevy"]
1111
[dependencies]
1212
# bevy
1313
bevy_app = { path = "../bevy_app", version = "0.5.0" }
14-
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" }
14+
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0", features = ["bevy_reflect"] }
1515
bevy_math = { path = "../bevy_math", version = "0.5.0" }
1616
bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] }
1717
bevy_utils = { path = "../bevy_utils", version = "0.5.0" }

docs/cargo_features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
|hdr|[HDR](https://en.wikipedia.org/wiki/High_dynamic_range) support.|
1515
|mp3|MP3 audio format support.|
1616
|x11|Make GUI applications use X11 protocol. You could enable wayland feature to override this.|
17+
|filesystem_watcher|Enable watching the file system for asset hot reload|
1718

1819
## Optional Features
1920

0 commit comments

Comments
 (0)