Skip to content

Commit

Permalink
Fix wasm builds with file_watcher enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Leinnan committed Nov 16, 2023
1 parent 7b2213a commit 2f9a82f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
ron = "0.8"
serde = { version = "1", features = ["derive"] }
thiserror = "1.0"
notify-debouncer-full = { version = "0.3.1", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
bevy_winit = { path = "../bevy_winit", version = "0.12.0" }
Expand All @@ -49,5 +48,8 @@ web-sys = { version = "0.3", features = ["Request", "Window", "Response"] }
wasm-bindgen-futures = "0.4"
js-sys = "0.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
notify-debouncer-full = { version = "0.3.1", optional = true }

[dev-dependencies]
bevy_core = { path = "../bevy_core", version = "0.12.0" }
14 changes: 7 additions & 7 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
mod embedded_watcher;

#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
pub use embedded_watcher::*;

use crate::io::{
Expand All @@ -21,7 +21,7 @@ pub const EMBEDDED: &str = "embedded";
#[derive(Resource, Default)]
pub struct EmbeddedAssetRegistry {
dir: Dir,
#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
root_paths: std::sync::Arc<
parking_lot::RwLock<bevy_utils::HashMap<std::path::PathBuf, std::path::PathBuf>>,
>,
Expand All @@ -34,7 +34,7 @@ impl EmbeddedAssetRegistry {
/// or a [`Vec<u8>`].
#[allow(unused)]
pub fn insert_asset(&self, full_path: PathBuf, asset_path: &Path, value: impl Into<Value>) {
#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
self.root_paths
.write()
.insert(full_path.to_owned(), asset_path.to_owned());
Expand All @@ -47,7 +47,7 @@ impl EmbeddedAssetRegistry {
/// or a [`Vec<u8>`].
#[allow(unused)]
pub fn insert_meta(&self, full_path: &Path, asset_path: &Path, value: impl Into<Value>) {
#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
self.root_paths
.write()
.insert(full_path.to_owned(), asset_path.to_owned());
Expand All @@ -68,7 +68,7 @@ impl EmbeddedAssetRegistry {
})
});

#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
{
let root_paths = self.root_paths.clone();
let dir = self.dir.clone();
Expand Down Expand Up @@ -196,7 +196,7 @@ macro_rules! embedded_asset {
.world
.resource_mut::<$crate::io::embedded::EmbeddedAssetRegistry>();
let path = $crate::embedded_path!($source_path, $path);
#[cfg(feature = "embedded_watcher")]
#[cfg(all(feature = "embedded_watcher", not(target_arch = "wasm32")))]
let full_path = std::path::Path::new(file!()).parent().unwrap().join($path);
#[cfg(not(feature = "embedded_watcher"))]
let full_path = std::path::PathBuf::new();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/io/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[cfg(feature = "file_watcher")]
#[cfg(all(feature = "file_watcher", not(target_arch = "wasm32")))]
mod file_watcher;

#[cfg(feature = "multi-threaded")]
mod file_asset;
#[cfg(not(feature = "multi-threaded"))]
mod sync_file_asset;

#[cfg(feature = "file_watcher")]
#[cfg(all(feature = "file_watcher", not(target_arch = "wasm32")))]
pub use file_watcher::*;

use std::{
Expand Down

0 comments on commit 2f9a82f

Please sign in to comment.