Skip to content

Commit 8f1b542

Browse files
committed
feat(wasm): gate turbo-tasks no-restore fast path behind wasm cfg
- Update next.js submodule with wasm cfg gate - Move OPFS_PROJECT and helpers from project.rs to pm.rs - Update opfs_offload.rs and pack.rs for new deps - Regenerate utoo-web type declarations
1 parent 3698e02 commit 8f1b542

8 files changed

Lines changed: 64 additions & 57 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ include_dir = { git = "https://github.com/vercel-labs/include_dir", branch
132132
lightningcss = { git = "https://github.com/utooland/lightningcss", branch = "support-css-module-global" }
133133
mdxjs = { git = "https://github.com/vercel-labs/mdxjs-rs-turbopack.git", branch = "turbopack" }
134134
mimalloc = { git = "https://github.com/utooland/mimalloc_rust.git" }
135+
opfs-project = { path = "../opfs-project" }
135136
parcel_selectors = { git = "https://github.com/utooland/lightningcss", branch = "support-css-module-global" }
136137
tokio = { package = "tokio", git = "https://github.com/utooland/tokio.git" }
137-
tokio-util = { package = "tokio-util", git = "https://github.com/utooland/tokio.git" }
138-
opfs-project = { path = "../opfs-project" }
139138
tokio-fs-ext = { path = "../tokio-fs-ext" }
139+
tokio-util = { package = "tokio-util", git = "https://github.com/utooland/tokio.git" }
140140
virtue = { git = "https://github.com/bgw/virtue.git", branch = "bgw/fix-generic-default-parsing" }
141141

142142
[profile.release]

crates/utoo-wasm/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use utoo_ruborist::service::Glob;
1111
use wasm_bindgen::prelude::*;
1212

1313
use crate::errors::to_js_error;
14-
use crate::project::OPFS_PROJECT;
14+
use crate::pm::OPFS_PROJECT;
1515
use crate::tokio_runtime::runtime;
1616

1717
/// OPFS-backed glob implementation.

crates/utoo-wasm/src/opfs_offload.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{io, path::Path};
22
use tokio_fs_ext::{offload, watch, Metadata, ReadDir};
33

4-
use crate::project::{with_project, OPFS_PROJECT};
4+
use crate::pm::{with_project, OPFS_PROJECT};
55

66
pub struct OpfsOffload;
77

@@ -51,7 +51,11 @@ impl offload::FsOffload for OpfsOffload {
5151
}
5252

5353
async fn metadata(&self, path: impl AsRef<Path>) -> io::Result<Metadata> {
54-
tokio_fs_ext::metadata(path).await
54+
let guard = OPFS_PROJECT.read();
55+
let project = guard
56+
.as_ref()
57+
.ok_or_else(|| io::Error::other("OpfsProject not initialised"))?;
58+
project.metadata(path).await
5559
}
5660

5761
async fn watch_dir(

crates/utoo-wasm/src/pack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub async fn init_pack_project(dev: bool) -> Result<()> {
242242
// Drop the old project
243243
GLOBAL_PACK_PROJECT.write().take();
244244

245-
let cwd = crate::project::with_project(|p| p.cwd().to_string_lossy().to_string());
245+
let cwd = crate::pm::with_project(|p| p.cwd().to_string_lossy().to_string());
246246
let project_root = if cwd.starts_with('/') {
247247
cwd
248248
} else {
@@ -276,6 +276,7 @@ pub async fn init_pack_project(dev: bool) -> Result<()> {
276276
build_id: project_path.clone(),
277277
watch: WatchOptions {
278278
enable: true,
279+
ignored: vec![],
279280
..Default::default()
280281
},
281282
dev,

crates/utoo-wasm/src/pm.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,39 @@
55
//! - Gzip archive creation
66
//! - Dependency resolution
77
//! - Package installation
8+
//! - Global OpfsProject instance management
89
910
use anyhow::{anyhow, Result};
1011
use opfs_project::archive::PackFile;
12+
use parking_lot::RwLock;
1113
use std::path::Path;
1214
use wasm_bindgen::JsCast;
1315

14-
use crate::project::{with_project, OPFS_PROJECT};
1516
use crate::tokio_runtime::{runtime, TOKIO_RUNTIME};
1617

18+
/// Global OpfsProject instance, initialised the first time `Project::init` is called.
19+
pub(crate) static OPFS_PROJECT: RwLock<Option<opfs_project::OpfsProject>> = RwLock::new(None);
20+
21+
/// Get a reference to the global OpfsProject for reading.
22+
///
23+
/// Panics if the project has not been initialised via `Project::init`.
24+
pub(crate) fn with_project<R>(f: impl FnOnce(&opfs_project::OpfsProject) -> R) -> R {
25+
let guard = OPFS_PROJECT.read();
26+
let project = guard
27+
.as_ref()
28+
.expect("OpfsProject not initialised — call Project.init() first");
29+
f(project)
30+
}
31+
32+
/// Get a mutable reference to the global OpfsProject.
33+
pub(crate) fn with_project_mut<R>(f: impl FnOnce(&mut opfs_project::OpfsProject) -> R) -> R {
34+
let mut guard = OPFS_PROJECT.write();
35+
let project = guard
36+
.as_mut()
37+
.expect("OpfsProject not initialised — call Project.init() first");
38+
f(project)
39+
}
40+
1741
/// Calculate MD5 hash of byte content
1842
pub async fn sig_md5(content: Vec<u8>) -> Result<String> {
1943
let result = runtime()
@@ -59,6 +83,7 @@ pub async fn gzip(files: wasm_bindgen::JsValue) -> Result<Vec<u8>> {
5983
/// Generate package-lock.json by resolving dependencies
6084
pub async fn deps(registry: Option<&str>, concurrency: Option<usize>) -> Result<String> {
6185
let cwd = with_project(|p| p.cwd().to_path_buf());
86+
6287
let package_lock =
6388
crate::deps::build_deps_from_file(Path::new(&cwd), registry, concurrency).await?;
6489

crates/utoo-wasm/src/project.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,14 @@ use parking_lot::RwLock;
99
use wasm_bindgen::prelude::*;
1010

1111
use crate::errors::to_js_error;
12-
use crate::pm;
12+
use crate::pm::{self, with_project, OPFS_PROJECT};
1313
use crate::tokio_runtime::init_tokio_runtime;
1414

1515
#[cfg(feature = "utoopack")]
1616
use crate::pack::{self, RootTask};
1717

1818
static GLOBAL_THREAD_URL: RwLock<Option<String>> = RwLock::new(None);
1919

20-
/// Global OpfsProject instance, initialised the first time `Project::init` is called.
21-
pub(crate) static OPFS_PROJECT: RwLock<Option<opfs_project::OpfsProject>> = RwLock::new(None);
22-
23-
/// Get a reference to the global OpfsProject for reading.
24-
///
25-
/// Panics if the project has not been initialised via `Project::init`.
26-
pub(crate) fn with_project<R>(f: impl FnOnce(&opfs_project::OpfsProject) -> R) -> R {
27-
let guard = OPFS_PROJECT.read();
28-
let project = guard
29-
.as_ref()
30-
.expect("OpfsProject not initialised — call Project.init() first");
31-
f(project)
32-
}
33-
34-
/// Get a mutable reference to the global OpfsProject.
35-
pub(crate) fn with_project_mut<R>(f: impl FnOnce(&mut opfs_project::OpfsProject) -> R) -> R {
36-
let mut guard = OPFS_PROJECT.write();
37-
let project = guard
38-
.as_mut()
39-
.expect("OpfsProject not initialised — call Project.init() first");
40-
f(project)
41-
}
42-
4320
#[wasm_bindgen]
4421
pub struct Project;
4522

packages/utoo-web/src/utoo/index.d.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -194,31 +194,6 @@ export function workerCreated(worker_id: number): void;
194194
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
195195

196196
export interface InitOutput {
197-
readonly ERR_ABORT: () => [number, number];
198-
readonly ERR_INVALID_STATE: () => [number, number];
199-
readonly ERR_KEY_ALREADY_EXISTS: () => [number, number];
200-
readonly ERR_NOT_ALLOWED: () => [number, number];
201-
readonly ERR_NOT_FOUND: () => [number, number];
202-
readonly ERR_NO_MODIFICATION_ALLOWED: () => [number, number];
203-
readonly ERR_QUOTA_EXCEEDED: () => [number, number];
204-
readonly ERR_TYPE_MISMATCH: () => [number, number];
205-
readonly getWasmMemory: () => any;
206-
readonly getWasmModule: () => any;
207-
readonly initLogFilter: (a: number, b: number) => void;
208-
readonly init_pack: () => void;
209-
readonly __wbg_project_free: (a: number, b: number) => void;
210-
readonly project_build: () => any;
211-
readonly project_cwd: () => [number, number];
212-
readonly project_deps: (a: number, b: number, c: number) => any;
213-
readonly project_entrypointsSubscribe: (a: any) => any;
214-
readonly project_gzip: (a: any) => any;
215-
readonly project_hmrEvents: (a: number, b: number, c: any) => any;
216-
readonly project_init: (a: number, b: number) => void;
217-
readonly project_install: (a: number, b: number, c: number) => any;
218-
readonly project_setCwd: (a: number, b: number) => void;
219-
readonly project_sigMd5: (a: any) => any;
220-
readonly project_updateInfoSubscribe: (a: number, b: any) => void;
221-
readonly project_writeAllToDisk: (a: any) => void;
222197
readonly __wbg_direntry_free: (a: number, b: number) => void;
223198
readonly __wbg_fs_free: (a: number, b: number) => void;
224199
readonly __wbg_get_direntry_name: (a: number) => [number, number];
@@ -250,9 +225,34 @@ export interface InitOutput {
250225
readonly fs_write: (a: number, b: number, c: any) => any;
251226
readonly fs_writeString: (a: number, b: number, c: number, d: number) => any;
252227
readonly fs_writeSync: (a: number, b: number, c: any) => [number, number];
228+
readonly initLogFilter: (a: number, b: number) => void;
229+
readonly init_pack: () => void;
230+
readonly getWasmMemory: () => any;
231+
readonly getWasmModule: () => any;
232+
readonly __wbg_project_free: (a: number, b: number) => void;
233+
readonly project_build: () => any;
234+
readonly project_cwd: () => [number, number];
235+
readonly project_deps: (a: number, b: number, c: number) => any;
236+
readonly project_entrypointsSubscribe: (a: any) => any;
237+
readonly project_gzip: (a: any) => any;
238+
readonly project_hmrEvents: (a: number, b: number, c: any) => any;
239+
readonly project_init: (a: number, b: number) => void;
240+
readonly project_install: (a: number, b: number, c: number) => any;
241+
readonly project_setCwd: (a: number, b: number) => void;
242+
readonly project_sigMd5: (a: any) => any;
243+
readonly project_updateInfoSubscribe: (a: number, b: any) => void;
244+
readonly project_writeAllToDisk: (a: any) => void;
253245
readonly __wbg_roottask_free: (a: number, b: number) => void;
254246
readonly registerWorkerScheduler: (a: any, b: any) => void;
255247
readonly workerCreated: (a: number) => void;
248+
readonly ERR_ABORT: () => [number, number];
249+
readonly ERR_INVALID_STATE: () => [number, number];
250+
readonly ERR_KEY_ALREADY_EXISTS: () => [number, number];
251+
readonly ERR_NOT_ALLOWED: () => [number, number];
252+
readonly ERR_NOT_FOUND: () => [number, number];
253+
readonly ERR_NO_MODIFICATION_ALLOWED: () => [number, number];
254+
readonly ERR_QUOTA_EXCEEDED: () => [number, number];
255+
readonly ERR_TYPE_MISMATCH: () => [number, number];
256256
readonly rust_mi_get_default_heap: () => number;
257257
readonly rust_mi_get_thread_id: () => number;
258258
readonly rust_mi_set_default_heap: (a: number) => void;

0 commit comments

Comments
 (0)