diff --git a/.changeset/sour-ladybugs-sin.md b/.changeset/sour-ladybugs-sin.md new file mode 100644 index 000000000..da9bc0539 --- /dev/null +++ b/.changeset/sour-ladybugs-sin.md @@ -0,0 +1,6 @@ +--- +"loro-wasm": patch +"loro-crdt": patch +--- + +Fix build script diff --git a/Cargo.lock b/Cargo.lock index 12b4ea27a..26ec524ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -695,9 +695,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -956,9 +956,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "lock_api" diff --git a/crates/loro-internal/Cargo.toml b/crates/loro-internal/Cargo.toml index 7a9610c6e..239779209 100644 --- a/crates/loro-internal/Cargo.toml +++ b/crates/loro-internal/Cargo.toml @@ -41,7 +41,7 @@ itertools = { workspace = true } enum_dispatch = { workspace = true } im = "15.1.0" generic-btree = { version = "^0.10.5" } -getrandom = "0.2.10" +getrandom = "0.2.15" once_cell = "1.18.0" leb128 = "0.2.5" num-traits = "0.2" diff --git a/crates/loro-internal/fuzz/Cargo.lock b/crates/loro-internal/fuzz/Cargo.lock index 2137903c8..c41b88d77 100644 --- a/crates/loro-internal/fuzz/Cargo.lock +++ b/crates/loro-internal/fuzz/Cargo.lock @@ -59,6 +59,12 @@ dependencies = [ "typenum", ] +[[package]] +name = "bitmaps" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d084b0137aaa901caf9f1e8b21daa6aa24d41cd806e111335541eff9683bd6" + [[package]] name = "bytecount" version = "0.6.3" @@ -210,7 +216,7 @@ dependencies = [ "arref", "fxhash", "heapless 0.7.16", - "itertools", + "itertools 0.11.0", "loro-thunderdome", "proc-macro2", ] @@ -286,7 +292,7 @@ version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" dependencies = [ - "bitmaps", + "bitmaps 2.1.0", "rand_core", "rand_xoshiro", "sized-chunks", @@ -294,6 +300,28 @@ dependencies = [ "version_check", ] +[[package]] +name = "imbl" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc3be8d8cd36f33a46b1849f31f837c44d9fa87223baee3b4bd96b8f11df81eb" +dependencies = [ + "bitmaps 3.2.1", + "imbl-sized-chunks", + "rand_core", + "rand_xoshiro", + "version_check", +] + +[[package]] +name = "imbl-sized-chunks" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "144006fb58ed787dcae3f54575ff4349755b00ccc99f4b4873860b654be1ed63" +dependencies = [ + "bitmaps 3.2.1", +] + [[package]] name = "itertools" version = "0.11.0" @@ -303,6 +331,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.4" @@ -353,7 +390,7 @@ dependencies = [ [[package]] name = "loro-common" -version = "0.5.0" +version = "0.16.2" dependencies = [ "arbitrary", "enum-as-inner 0.6.0", @@ -368,7 +405,7 @@ dependencies = [ [[package]] name = "loro-delta" -version = "0.5.0" +version = "0.16.2" dependencies = [ "arrayvec", "enum-as-inner 0.5.1", @@ -379,22 +416,24 @@ dependencies = [ [[package]] name = "loro-internal" -version = "0.5.0" +version = "0.16.2" dependencies = [ "append-only-bytes", "arbitrary", "arref", + "either", "enum-as-inner 0.5.1", "enum_dispatch", "fxhash", "generic-btree", "getrandom", "im", - "itertools", + "itertools 0.12.1", "leb128", "loro-common", "loro-delta", "loro-rle", + "loro_fractional_index", "md5", "num", "num-derive", @@ -421,7 +460,7 @@ dependencies = [ [[package]] name = "loro-rle" -version = "0.5.0" +version = "0.16.2" dependencies = [ "append-only-bytes", "arref", @@ -437,6 +476,16 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f3d053a135388e6b1df14e8af1212af5064746e9b87a06a345a7a779ee9695a" +[[package]] +name = "loro_fractional_index" +version = "0.16.2" +dependencies = [ + "imbl", + "rand", + "serde", + "smallvec", +] + [[package]] name = "md5" version = "0.7.0" @@ -752,7 +801,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5d54dd7e7a1ec134c842f8a3bdb5a1fc662d002682e0457f976f3046cf9ccf8" dependencies = [ - "itertools", + "itertools 0.11.0", "postcard", "serde", "serde_columnar_derive", @@ -805,7 +854,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" dependencies = [ - "bitmaps", + "bitmaps 2.1.0", "typenum", ] diff --git a/crates/loro-internal/fuzz/Cargo.toml b/crates/loro-internal/fuzz/Cargo.toml index 7b9d9b17f..a79c07f83 100644 --- a/crates/loro-internal/fuzz/Cargo.toml +++ b/crates/loro-internal/fuzz/Cargo.toml @@ -19,48 +19,8 @@ features = ["test_utils"] [workspace] members = ["."] -[[bin]] -name = "yata" -path = "fuzz_targets/yata.rs" -test = false -doc = false - -# [profile.dev] -# lto = true -# opt-level = 3 - -[[bin]] -name = "text_refactored" -path = "fuzz_targets/text_refactored.rs" -test = false -doc = false - -[[bin]] -name = "recursive_refactored" -path = "fuzz_targets/recursive_refactored.rs" -test = false -doc = false - [[bin]] name = "import" path = "fuzz_targets/import.rs" test = false doc = false - -[[bin]] -name = "tree" -path = "fuzz_targets/tree.rs" -test = false -doc = false - -[[bin]] -name = "richtext" -path = "fuzz_targets/richtext.rs" -test = false -doc = false - -[[bin]] -name = "map" -path = "fuzz_targets/map.rs" -test = false -doc = false diff --git a/crates/loro-internal/fuzz/fuzz_targets/map.rs b/crates/loro-internal/fuzz/fuzz_targets/map.rs deleted file mode 100644 index 1841a6d27..000000000 --- a/crates/loro-internal/fuzz/fuzz_targets/map.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_main] - -use libfuzzer_sys::fuzz_target; -use loro_internal::fuzz::crdt_fuzzer::{test_multi_sites, Action, FuzzTarget}; - -fuzz_target!(|actions: Vec| { - test_multi_sites(5, vec![FuzzTarget::Map], &mut actions.clone()) -}); diff --git a/crates/loro-internal/fuzz/fuzz_targets/recursive_refactored.rs b/crates/loro-internal/fuzz/fuzz_targets/recursive_refactored.rs deleted file mode 100644 index 564da7b3c..000000000 --- a/crates/loro-internal/fuzz/fuzz_targets/recursive_refactored.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; -use loro_internal::fuzz::recursive_refactored::{test_multi_sites, Action}; - -fuzz_target!(|actions: Vec| { test_multi_sites(5, &mut actions.clone()) }); diff --git a/crates/loro-internal/fuzz/fuzz_targets/richtext.rs b/crates/loro-internal/fuzz/fuzz_targets/richtext.rs deleted file mode 100644 index ae6b23983..000000000 --- a/crates/loro-internal/fuzz/fuzz_targets/richtext.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; -use loro_internal::fuzz::richtext::{test_multi_sites, Action}; - -fuzz_target!(|actions: Vec| { test_multi_sites(5, &mut actions.clone()) }); diff --git a/crates/loro-internal/fuzz/fuzz_targets/text_refactored.rs b/crates/loro-internal/fuzz/fuzz_targets/text_refactored.rs deleted file mode 100644 index f6714169e..000000000 --- a/crates/loro-internal/fuzz/fuzz_targets/text_refactored.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; -use loro_internal::fuzz::{test_multi_sites, Action}; - -fuzz_target!(|actions: Vec| { test_multi_sites(5, &mut actions.clone()) }); diff --git a/crates/loro-internal/fuzz/fuzz_targets/tree.rs b/crates/loro-internal/fuzz/fuzz_targets/tree.rs deleted file mode 100644 index 4a393c227..000000000 --- a/crates/loro-internal/fuzz/fuzz_targets/tree.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; -use loro_internal::fuzz::tree::{test_multi_sites, Action}; - -fuzz_target!(|actions: Vec| { test_multi_sites(5, &mut actions.clone()) }); diff --git a/crates/loro-wasm/Cargo.toml b/crates/loro-wasm/Cargo.toml index e58609077..397e8e1d0 100644 --- a/crates/loro-wasm/Cargo.toml +++ b/crates/loro-wasm/Cargo.toml @@ -15,7 +15,7 @@ wasm-bindgen = "=0.2.92" serde-wasm-bindgen = { version = "^0.6.5" } wasm-bindgen-derive = "0.2.1" console_error_panic_hook = { version = "0.1.6", optional = true } -getrandom = { version = "0.2.10", features = ["js"] } +getrandom = { version = "0.2.15", features = ["js"] } serde = { workspace = true } rle = { path = "../rle", package = "loro-rle" } tracing-wasm = "0.2.1" diff --git a/crates/loro-wasm/scripts/build.ts b/crates/loro-wasm/scripts/build.ts index 234d42035..ddce6f93a 100644 --- a/crates/loro-wasm/scripts/build.ts +++ b/crates/loro-wasm/scripts/build.ts @@ -92,6 +92,20 @@ async function buildTarget(target: string) { console.log(">", cmd); await Deno.run({ cmd: cmd.split(" "), cwd: LoroWasmDir }).status(); console.log(); + + if (target === "nodejs") { + console.log("🔨 Patching nodejs target"); + const patch = await Deno.readTextFile( + path.resolve(__dirname, "./nodejs_patch.js"), + ); + const wasm = await Deno.readTextFile( + path.resolve(targetDirPath, "loro_wasm.js"), + ); + await Deno.writeTextFile( + path.resolve(targetDirPath, "loro_wasm.js"), + wasm + "\n" + patch, + ); + } } build(); diff --git a/crates/loro-wasm/scripts/nodejs_patch.js b/crates/loro-wasm/scripts/nodejs_patch.js new file mode 100644 index 000000000..d237e63f7 --- /dev/null +++ b/crates/loro-wasm/scripts/nodejs_patch.js @@ -0,0 +1,11 @@ +// Don't patch this if it already exists (for example in Deno) +if (!globalThis.crypto) { + // We need this patch because we use `getrandom` crate in Rust, which relies on this patch + // for nodejs + // https://docs.rs/getrandom/latest/getrandom/#nodejs-es-module-support + const { webcrypto } = require("crypto"); + Object.defineProperty(globalThis, 'crypto', { + value: webcrypto, + writable: true + }); +}