Skip to content

Commit 3a9e273

Browse files
committed
feat(turbo-tasks-fs): enable fs watcher on wasm
1 parent 686e57d commit 3a9e273

File tree

6 files changed

+176
-22
lines changed

6 files changed

+176
-22
lines changed

Cargo.lock

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ napi = { version = "2", default-features = false, features = [
387387
"compat-mode",
388388
] }
389389
notify = "8.1.0"
390+
notify-types = "2.0.0"
390391
once_cell = "1.17.1"
391392
owo-colors = "3.5.0"
392393
parcel_selectors = "0.28.2"

turbopack/crates/turbo-tasks-fs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ turbo-rcstr = { workspace = true }
5050
turbo-tasks = { workspace = true }
5151
turbo-tasks-hash = { workspace = true }
5252
urlencoding = { workspace = true }
53+
notify-types = { workspace = true }
5354

5455
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
5556
notify = { workspace = true }
5657

5758
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
58-
tokio-fs-ext = { version = "0.5.6", features = ["wasm_offload"] }
59+
tokio-fs-ext = { version = "0.6.0", features = ["opfs_offload", "opfs_watch"] }
5960
wasm_thread = { git = "https://github.com/utooland/wasm_thread.git", default-features = false, features = [
6061
"spawn_from_worker",
6162
] }

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod rope;
2222
pub mod source_context;
2323
pub mod util;
2424
pub(crate) mod virtual_fs;
25-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
2625
mod watcher;
2726
use std::{
2827
borrow::Cow,
@@ -66,7 +65,6 @@ use turbo_tasks::{
6665
use turbo_tasks_hash::{DeterministicHash, DeterministicHasher, hash_xxh3_hash64};
6766
use util::{extract_disk_access, join_path, normalize_path, sys_to_unix, unix_to_sys};
6867
pub use virtual_fs::VirtualFileSystem;
69-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
7068
use watcher::DiskWatcher;
7169

7270
use self::{invalidation::Write, json::UnparsableJson, mutex_map::MutexMap};
@@ -245,7 +243,6 @@ struct DiskFileSystemInner {
245243
semaphore: tokio::sync::Semaphore,
246244

247245
#[turbo_tasks(debug_ignore, trace_ignore)]
248-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
249246
watcher: DiskWatcher,
250247
}
251248

@@ -387,7 +384,6 @@ impl DiskFileSystemInner {
387384
}
388385

389386
#[tracing::instrument(level = "info", name = "start filesystem watching", skip_all, fields(path = %self.root))]
390-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
391387
async fn start_watching_internal(
392388
self: &Arc<Self>,
393389
report_invalidation_reason: bool,
@@ -396,6 +392,7 @@ impl DiskFileSystemInner {
396392
let root_path = self.root_path().to_path_buf();
397393

398394
// create the directory for the filesystem on disk, if it doesn't exist
395+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
399396
retry_blocking(root_path.clone(), move |path| {
400397
let _tracing =
401398
tracing::info_span!("create root directory", name = display(path.display()))
@@ -406,9 +403,20 @@ impl DiskFileSystemInner {
406403
.concurrency_limited(&self.semaphore)
407404
.await?;
408405

406+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
407+
wasm_fs_offload::CLIENT
408+
.create_dir_all(root_path.clone())
409+
.await?;
410+
411+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
409412
self.watcher
410413
.start_watching(self.clone(), report_invalidation_reason, poll_interval)?;
411414

415+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
416+
self.watcher
417+
.start_watching(self.clone(), report_invalidation_reason, poll_interval)
418+
.await?;
419+
412420
Ok(())
413421
}
414422

@@ -469,14 +477,12 @@ impl DiskFileSystem {
469477
self.inner.invalidate_with_reason(reason);
470478
}
471479

472-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
473480
pub async fn start_watching(&self, poll_interval: Option<Duration>) -> Result<()> {
474481
self.inner
475482
.start_watching_internal(false, poll_interval)
476483
.await
477484
}
478485

479-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
480486
pub async fn start_watching_with_invalidation_reason(
481487
&self,
482488
poll_interval: Option<Duration>,
@@ -550,7 +556,6 @@ impl DiskFileSystem {
550556
invalidator_map: InvalidatorMap::new(),
551557
dir_invalidator_map: InvalidatorMap::new(),
552558
semaphore: create_semaphore(),
553-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
554559
watcher: DiskWatcher::new(
555560
ignored_subpaths.into_iter().map(PathBuf::from).collect(),
556561
),

turbopack/crates/turbo-tasks-fs/src/wasm_fs_offload.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use std::sync::LazyLock;
1+
use std::{
2+
path::{Path, PathBuf},
3+
sync::LazyLock,
4+
};
25

36
use anyhow::{Context, Result};
47
use parking_lot::Mutex;
8+
use serde::{Deserialize, Serialize};
59
use tokio::sync::oneshot;
610
use tokio_fs_ext::offload::{self, FsOffload};
711

0 commit comments

Comments
 (0)