diff --git a/Cargo.lock b/Cargo.lock index 9a68b64..1108d29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -410,10 +410,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5c4c0e4..a72b43f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,9 +50,9 @@ include_dir = "0.7" libc = { version = "0.2", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -# No `wasmbind`: keeps cdylib free of wasm-bindgen imports (raw mq_* ABI). +# Custom entropy — no `js`/wasm-bindgen imports (raw mq_* ABI + marqdo-bridge.js). chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] } -getrandom = { version = "=0.2.17", default-features = false, features = ["js"] } +getrandom = { version = "=0.2.17", default-features = false, features = ["custom"] } [workspace] members = [ diff --git a/crates/marqdo-wasm/src/lib.rs b/crates/marqdo-wasm/src/lib.rs index ee768ed..0b12333 100644 --- a/crates/marqdo-wasm/src/lib.rs +++ b/crates/marqdo-wasm/src/lib.rs @@ -185,7 +185,38 @@ fn pack_json(v: &serde_json::Value) -> *mut u8 { ptr::copy_nonoverlapping(len.to_le_bytes().as_ptr(), out, 4); ptr::copy_nonoverlapping(bytes.as_ptr(), out.add(4), bytes.len()); } - out + out +} + +/// getrandom `custom` backend for wasm32 — no wasm-bindgen / JS glue imports. +/// Preferable to the `js` feature which pulls `__wbindgen_*` and breaks raw mq_* ABI. +#[cfg(target_arch = "wasm32")] +#[no_mangle] +unsafe extern "Rust" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 { + // xorshift64* seeded once; fine for uuid/non-crypto browser host helpers. + use std::cell::Cell; + thread_local! { + static STATE: Cell = const { Cell::new(0x4d51_5241_4e44_4f21) }; + } + if dest.is_null() || len == 0 { + return 0; + } + let mut s = STATE.with(|c| { + let mut v = c.get(); + if v == 0 { + v = 0x4d51_5241_4e44_4f21; + } + v + }); + let buf = unsafe { std::slice::from_raw_parts_mut(dest, len) }; + for b in buf.iter_mut() { + s ^= s << 13; + s ^= s >> 7; + s ^= s << 17; + *b = (s >> 8) as u8; + } + STATE.with(|c| c.set(s)); + 0 } #[cfg(test)]