WASM build of the parser libraries #301

Closed
opened 2026-07-23 20:52:09 +02:00 by jqueuniet · 1 comment
Owner

The parsers are pure-Rust and &[u8]-driven, so a WASM target should be mostly free. Exposes graphics/dungeon/saves/music decoding to the browser and underpins a future web viewer.

The parsers are pure-Rust and `&[u8]`-driven, so a WASM target should be mostly free. Exposes graphics/dungeon/saves/music decoding to the browser and underpins a future web viewer.
jqueuniet added this to the dm2-tools project 2026-07-23 21:43:33 +02:00
Author
Owner

Investigated feasibility and scoped the work.

WASM readiness — confirmed. All four parser crates cross-compile cleanly to
wasm32-unknown-unknown (verified — libdm2_{graphics,dungeon,saves,music}.rlib all
build). No C / FFI / -sys deps in the parser chain; getrandom / libc / tempfile
are dev-only via dm2-cli and never reach the libraries. The audio chain
(sms-audio / opl-audio / xmrs / xmrsplayer) also builds: xmrsplayer's
thread/time usage is confined to its cpal_player binary, and xmrs's std::fs loaders
are never called (mod-audio feeds &[u8]). So the dm2-wasm cdylib wrapper itself is
small.

(One unrelated aside surfaced: binrw 0.15.1 throws a future-incompat warning on every
build, host and wasm alike — worth its own tracking issue for a version bump, not a
blocker here.)

But the useful boundary is JSON, and the current JSON isn't ready. A browser
viewer/editor needs to hand structured data across the wasm boundary. dm2-dungeon's
json::skproject dump is one-way and lossy (retired-C#-tool interop; start_map
hardcoded to 0), and dm2-saves has no JSON at all. To avoid baking a lossy contract
into the web API, the plan is lossless-JSON-first, then wrap:

  1. Lossless, byte-exact-round-trippable JSON in the parser crates — #308 (saves,
    first) and #309 (dungeon). The parsers already round-trip byte-exact at the binary
    level, so this is mostly a faithful serde projection guarded by a round-trip test.
  2. A web-facing serialization-scheme decision — #307 — because the existing JSON
    assumes a filesystem with sidecar binaries (PNGs / sounds), which the browser lacks.
  3. Then this issue: the dm2-wasm cdylib exposing the settled JSON, graphics as PNG
    bytes, and music as PCM (via wasm-pack --target web).

Keeping this open as the wrapper/exposure step; it is now gated on #307 / #308 / #309.

Investigated feasibility and scoped the work. **WASM readiness — confirmed.** All four parser crates cross-compile cleanly to `wasm32-unknown-unknown` (verified — `libdm2_{graphics,dungeon,saves,music}.rlib` all build). No C / FFI / `-sys` deps in the parser chain; `getrandom` / `libc` / `tempfile` are dev-only via `dm2-cli` and never reach the libraries. The audio chain (`sms-audio` / `opl-audio` / `xmrs` / `xmrsplayer`) also builds: `xmrsplayer`'s thread/time usage is confined to its `cpal_player` binary, and `xmrs`'s `std::fs` loaders are never called (`mod-audio` feeds `&[u8]`). So the `dm2-wasm` cdylib wrapper itself is small. (One unrelated aside surfaced: `binrw 0.15.1` throws a future-incompat warning on every build, host and wasm alike — worth its own tracking issue for a version bump, not a blocker here.) **But the useful boundary is JSON, and the current JSON isn't ready.** A browser viewer/editor needs to hand structured data across the wasm boundary. `dm2-dungeon`'s `json::skproject` dump is one-way and lossy (retired-C#-tool interop; `start_map` hardcoded to 0), and `dm2-saves` has no JSON at all. To avoid baking a lossy contract into the web API, the plan is **lossless-JSON-first, then wrap**: 1. Lossless, byte-exact-round-trippable JSON in the parser crates — **#308** (saves, first) and **#309** (dungeon). The parsers already round-trip byte-exact at the binary level, so this is mostly a faithful serde projection guarded by a round-trip test. 2. A web-facing serialization-scheme decision — **#307** — because the existing JSON assumes a filesystem with sidecar binaries (PNGs / sounds), which the browser lacks. 3. Then this issue: the `dm2-wasm` cdylib exposing the settled JSON, graphics as PNG bytes, and music as PCM (via `wasm-pack --target web`). Keeping this open as the wrapper/exposure step; it is now gated on #307 / #308 / #309.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools#301
No description provided.