Skip to content

Commit eb9c18a

Browse files
authored
fix: exclude wasi from js-specific build deps (#986)
1 parent d4fdfda commit eb9c18a

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.changeset/tough-eggs-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"loro-crdt": patch
3+
---
4+
5+
Fix WASI builds by using native calls instead of js-only wasm32 bindings (`Date.now`, `getrandom`)

crates/loro-internal/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ loom = { version = "0.7", features = ["checkpoint"] }
6464
[lints.rust]
6565
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }
6666

67-
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies.getrandom]
67+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(target_os = "wasi")))'.dependencies.getrandom]
6868
version = "0.2.15"
6969
features = ["js"]
7070

71-
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
71+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(target_os = "wasi")))'.dependencies]
7272
wasm-bindgen = "0.2.100"
7373

7474
[dev-dependencies]

crates/loro-internal/src/change.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ impl Change {
284284

285285
/// [Unix time](https://en.wikipedia.org/wiki/Unix_time)
286286
/// It is the number of milliseconds that have elapsed since 00:00:00 UTC on 1 January 1970.
287-
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
287+
#[cfg(any(
288+
not(target_arch = "wasm32"),
289+
target_os = "emscripten",
290+
target_os = "wasi"
291+
))]
288292
pub(crate) fn get_sys_timestamp() -> f64 {
289293
use std::time::{SystemTime, UNIX_EPOCH};
290294
SystemTime::now()
@@ -296,7 +300,11 @@ pub(crate) fn get_sys_timestamp() -> f64 {
296300

297301
/// [Unix time](https://en.wikipedia.org/wiki/Unix_time)
298302
/// It is the number of milliseconds that have elapsed since 00:00:00 UTC on 1 January 1970.
299-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
303+
#[cfg(all(
304+
target_arch = "wasm32",
305+
not(target_os = "emscripten"),
306+
not(target_os = "wasi")
307+
))]
300308
pub fn get_sys_timestamp() -> f64 {
301309
use wasm_bindgen::prelude::wasm_bindgen;
302310
#[wasm_bindgen]

0 commit comments

Comments
 (0)