Skip to content

Commit 2159110

Browse files
lodyai[bot]zxch3n
andauthored
fix: support Emscripten timestamp path (#966)
* fix: support emscripten timestamp path * chore: add changeset for emscripten fix --------- Co-authored-by: Zixuan Chen <[email protected]>
1 parent 32b1260 commit 2159110

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

.changeset/fresh-points-serve.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 Emscripten builds by using the native system timestamp path instead of the wasm-bindgen Date.now binding.

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(target_arch = "wasm32")'.dependencies.getrandom]
67+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies.getrandom]
6868
version = "0.2.15"
6969
features = ["js"]
7070

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

7474
[dev-dependencies]

crates/loro-internal/src/change.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ 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(not(target_arch = "wasm32"))]
287+
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
288288
pub(crate) fn get_sys_timestamp() -> f64 {
289289
use std::time::{SystemTime, UNIX_EPOCH};
290290
SystemTime::now()
@@ -295,8 +295,8 @@ pub(crate) fn get_sys_timestamp() -> f64 {
295295
}
296296

297297
/// [Unix time](https://en.wikipedia.org/wiki/Unix_time)
298-
/// It is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970.
299-
#[cfg(target_arch = "wasm32")]
298+
/// 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")))]
300300
pub fn get_sys_timestamp() -> f64 {
301301
use wasm_bindgen::prelude::wasm_bindgen;
302302
#[wasm_bindgen]

0 commit comments

Comments
 (0)