Skip to content

Add wasm support - #204

Merged
CoreyKaylor merged 1 commit into
mainfrom
wasm-support
Aug 8, 2026
Merged

Add wasm support#204
CoreyKaylor merged 1 commit into
mainfrom
wasm-support

Conversation

@CoreyKaylor

Copy link
Copy Markdown
Owner

Closes #182.

The liblmdb.wasm previously shipped in runtimes/browser-wasm was unusable — mono-wasm can't load emscripten side modules (dotnet/runtime#75257) and nothing references that package path on browser. Removed.

Browser-wasm now works by shipping LMDB as compilable C source (wasm/ in the nupkg). A buildTransitive targets file adds it as a NativeFileReference when RuntimeIdentifier is browser-wasm; the consumer's wasm-tools workload compiles and statically links it, so there's no emscripten version coupling. Only prerequisite: dotnet workload install wasm-tools.

Required open flags (each verified load-bearing, see test app): WriteMap | NoLock | NoThreadLocalStorage | NoSync, with Flush(force: true) as the durability point. MEMFS mmaps aren't coherent with pwrite (default mode silently loses commits) and emscripten's msync only accepts mapping base addresses (sync-at-commit panics the env).

Encryption: AesGcmCipher can't exist on wasm (no platform AEAD) and managed page callbacks can't cross the wasm boundary, so the wasm build compiles in ChaCha20-Poly1305 (RFC 8439, same format as upstream crypto.c) + keyed BLAKE2b-256 via vendored Monocypher, installed natively — NativeChaCha20Poly1305Cipher / NativeBlake2bChecksum. Experimental; known limitation: encrypted envs ignore WriteMap (REMAP_CHUNKS), so same-session reads after commit see stale data — write → flush → reopen → read is the supported pattern.

Persistence: LightningBrowserStorage.MountAsync("/persist") mounts an IndexedDB-backed directory (IDBFS, linked automatically; opt out with WasmEnableIDBFS=false) and restores prior state; PersistAsync() checkpoints after Flush(true). Checkpoint durability — survives reload after each persist, not per commit. Single tab at a time.

Tests: src/LightningDB.WasmTest (kept out of the solution — needs wasm-tools) runs 15 in-browser scenarios including controls that assert the documented failure modes, plus cross-reload persistence phases. New wasm.yml workflow runs it headless on PRs; results are polled via document.title / DevTools endpoint because --virtual-time-budget stalls on IndexedDB.

Base automatically changed from ios-unity to main August 8, 2026 01:28
@CoreyKaylor
CoreyKaylor merged commit eb15e3f into main Aug 8, 2026
5 checks passed
@CoreyKaylor
CoreyKaylor deleted the wasm-support branch August 8, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: How can the recently added liblmdb.wasm be used for SiaqoDB/LightningDB on Uno Platform/WebAssembly?

1 participant