Skip to content

Commit 610b9d1

Browse files
committed
fix(turbo-tasks): make turbo-tasks fn callable on wasm
1 parent 1320d83 commit 610b9d1

File tree

9 files changed

+49
-6
lines changed

9 files changed

+49
-6
lines changed

Cargo.lock

Lines changed: 16 additions & 0 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
@@ -441,6 +441,7 @@ urlencoding = "2.1.2"
441441
vergen = { version = "9.0.6", features = ["cargo"] }
442442
vergen-gitcl = { version = "1.0.8", features = ["cargo"] }
443443
webbrowser = "0.8.7"
444+
wasmtimer = "0.4.2"
444445

445446
[patch.crates-io]
446447
hyper = { git = "https://github.com/bgw/hyper-rs.git", branch = "v1.6.0-with-macos-intel-miscompilation-workaround" }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ turbo-tasks-testing = { workspace = true }
5757
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
5858
turbo-persistence = { workspace = true }
5959

60+
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
61+
wasmtimer = { workspace = true }
62+
6063
[dev-dependencies]
6164
criterion = { workspace = true, features = ["async_tokio"] }
6265
regex = { workspace = true }

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
1515
},
1616
thread::available_parallelism,
17+
time::Duration,
1718
};
1819

1920
use anyhow::{Result, bail};
@@ -22,7 +23,8 @@ use indexmap::IndexSet;
2223
use parking_lot::{Condvar, Mutex};
2324
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
2425
use smallvec::{SmallVec, smallvec};
25-
use tokio::time::{Duration, Instant};
26+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
27+
use tokio::time::{Instant, sleep_until};
2628
use tracing::field::Empty;
2729
use turbo_tasks::{
2830
CellId, FxDashMap, KeyValuePair, RawVc, ReadCellOptions, ReadConsistency, SessionId,
@@ -40,6 +42,8 @@ use turbo_tasks::{
4042
turbo_tasks,
4143
util::IdFactoryWithReuse,
4244
};
45+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
46+
use wasmtimer::{std::Instant, tokio::sleep_until};
4347

4448
pub use self::{operation::AnyOperation, storage::TaskDataCategory};
4549
#[cfg(feature = "trace_task_dirty")]
@@ -2158,10 +2162,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
21582162
idle_time = until + IDLE_TIMEOUT;
21592163
idle_end_listener = self.idle_end_event.listen()
21602164
},
2161-
_ = tokio::time::sleep_until(until) => {
2165+
_ = sleep_until(until) => {
21622166
break;
21632167
},
2164-
_ = tokio::time::sleep_until(idle_time) => {
2168+
_ = sleep_until(idle_time) => {
21652169
if turbo_tasks.is_idle() {
21662170
break;
21672171
}

turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
2+
use std::time::Instant;
13
use std::{
24
cmp::{Ordering, max},
35
collections::{VecDeque, hash_map::Entry as HashMapEntry},
@@ -6,7 +8,7 @@ use std::{
68
num::NonZeroU32,
79
ops::ControlFlow,
810
thread::yield_now,
9-
time::{Duration, Instant},
11+
time::Duration,
1012
};
1113

1214
use anyhow::Result;
@@ -21,6 +23,8 @@ use smallvec::{SmallVec, smallvec};
2123
))]
2224
use tracing::{span::Span, trace_span};
2325
use turbo_tasks::{FxIndexMap, SessionId, TaskExecutionReason, TaskId};
26+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
27+
use wasmtimer::std::Instant;
2428

2529
#[cfg(feature = "trace_task_dirty")]
2630
use crate::backend::operation::invalidate::TaskDirtyCause;

turbopack/crates/turbo-tasks/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ turbo-tasks-macros = { workspace = true }
6060
turbo-tasks-malloc = { workspace = true }
6161
unsize = { workspace = true }
6262

63+
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
64+
wasmtimer = { workspace = true }
65+
6366
[build-dependencies]
6467
turbo-tasks-build = { workspace = true }

turbopack/crates/turbo-tasks/src/capture_future.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
2+
use std::time::Instant;
13
use std::{
24
borrow::Cow,
35
cell::RefCell,
@@ -6,13 +8,15 @@ use std::{
68
panic,
79
pin::Pin,
810
task::{Context, Poll},
9-
time::{Duration, Instant},
11+
time::Duration,
1012
};
1113

1214
use anyhow::Result;
1315
use pin_project_lite::pin_project;
1416
use serde::{Deserialize, Serialize};
1517
use turbo_tasks_malloc::{AllocationInfo, TurboMalloc};
18+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
19+
use wasmtimer::std::Instant;
1620

1721
use crate::{backend::TurboTasksExecutionErrorMessage, panic_hooks::LAST_ERROR_LOCATION};
1822

turbopack/crates/turbo-tasks/src/duration_span.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
12
use std::time::Instant;
23

4+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
5+
use wasmtimer::std::Instant;
6+
37
/// Guard that emits a tracing event when dropped with the duration of the
48
/// lifetime of the guard.
59
pub struct DurationSpanGuard<F: FnOnce(u64)> {

turbopack/crates/turbo-tasks/src/manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
2+
use std::time::Instant;
13
use std::{
24
any::Any,
35
future::Future,
@@ -9,7 +11,7 @@ use std::{
911
atomic::{AtomicBool, AtomicUsize, Ordering},
1012
},
1113
thread,
12-
time::{Duration, Instant},
14+
time::Duration,
1315
};
1416

1517
use anyhow::{Result, anyhow};
@@ -21,6 +23,8 @@ use tokio::{runtime::Handle, select, sync::mpsc::Receiver, task_local};
2123
use tokio_util::task::TaskTracker;
2224
use tracing::{Instrument, Level, Span, info_span, instrument, trace_span};
2325
use turbo_tasks_malloc::TurboMalloc;
26+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
27+
use wasmtimer::std::Instant;
2428

2529
use crate::{
2630
Completion, InvalidationReason, InvalidationReasonSet, OutputContent, ReadCellOptions,

0 commit comments

Comments
 (0)