Skip to content

feat(wasm): cwist_db in WASM build, EM_JS format-corruption fix, wasm docs (issue #93) - #176

Draft
gg582 wants to merge 4 commits into
devfrom
feat/wasm-v36
Draft

gg582 wants to merge 4 commits into
devfrom
feat/wasm-v36

Conversation

@gg582

@gg582 gg582 commented Sep 16, 2026

Copy link
Copy Markdown
Member

Part of #93 (Phase 1 + start of Phase 2). Draft.

What's here

  • Makefile: src/core/db/db.c + lib/sqlite3/sqlite3.c added to WASM_SRCS - the ROADMAP claim that cwist_db_open_memory()/cwist_db_serialize() work under WASM is now actually true (gap 1). Compiles clean with emcc.
  • tests/wasm_smoke.c: cwist_db round trip - create + insert, serialize to an image blob, reopen read-only via cwist_db_open_memory(), query the row back. Also fixes JS that the tree-wide clang-format pass corrupted (=> rewritten to = >): EM_JS stringifies its raw argument, so brace-block bodies are now wrapped in clang-format off/on or make format silently breaks the WASM build.
  • include/cwist/wasm/typedarray.h: same clang-format protection for CWIST_WASM_INSTALL_VIEWS.
  • docs/api/wasm.md: initial documentation (gap 4) - build, scope, dispatch_memory pattern, TypedArray helpers, db round trip, session caveats.
  • .github/workflows/wasm.yml: Emscripten 5.0.0 build + wasm-smoke on every push/PR to main/dev (gap 2). Includes a workaround for the actions/cache emsdk exec-bit loss; NODE is now overridable in the Makefile.

Verified

  • make wasm + make wasm-smoke locally (Emscripten 5.0.0 + node), make format idempotent wrt EM_JS bodies.
  • WASM CI job green on this PR.

Still open (later PRs)

  • npm/release packaging, first-party JS wrapper (Phase 2)
  • WASI target, streaming, session persistence model, example app (Phases 3-4)

…n, add wasm docs (issue #93)

Phase 1+2 initial work for the CWIST WASM workstream:

- Makefile: add src/core/db/db.c and lib/sqlite3/sqlite3.c to WASM_SRCS so
  the ROADMAP claim for cwist_db_open_memory/cwist_db_serialize under WASM
  is actually true. Builds clean with emcc.
- tests/wasm_smoke.c: add a cwist_db round trip (create + insert, serialize
  to an image blob, reopen read-only via cwist_db_open_memory, query back).
  Also fix JS that the tree-wide clang-format pass had corrupted ('=>'
  rewritten to '= >'): EM_JS stringifies its raw argument, so brace-block
  bodies must be protected with clang-format off/on or make format silently
  breaks the WASM build - exactly the regression class issue #93 gap 2 warns
  about.
- include/cwist/wasm/typedarray.h: same clang-format off/on protection for
  CWIST_WASM_INSTALL_VIEWS.
- docs/api/wasm.md: initial documentation - build, in-scope/excluded
  subsystems, dispatch_memory pattern, TypedArray helpers, db round trip,
  session/cookie caveats.

Verified: make wasm and make wasm-smoke pass under Emscripten 5.0.0 + node;
format-check stable.
The WASM archive and smoke test were manual-only, so WASM-only
regressions (like the EM_JS corruption from the tree-wide format) went
unnoticed. Install emsdk 5.0.0 on the runner, build libcwist_wasm.a, and
run wasm-smoke under node on every push/PR to main and dev.
actions/cache restores the emsdk cache without the executable bit on its
bundled node binary, so 'node wasm_smoke.js' failed with Permission
denied on cache hits.
The chmod -R on the cache folder did not cover the node binary that ends
up on PATH. Parameterize NODE in the Makefile and have the workflow chmod
the exact resolved node binary, falling back to the runner's system node.
@gg582

gg582 commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@Bhumika-1432006
Thanks for picking up issue #93 from Discord. Reviewed the WASM changes themselves (Makefile, wasm.yml, wasm_smoke.c, typedarray.h, wasm.md) and they look solid; the Emscripten CI job is a real gap-closer.

One structural request before this leaves draft:

Scope the diff to the 5 WASM files. The branch currently carries a merge of #175 and a main-side benchmark report refresh, so the diff is 14 files and includes README/benchmark numbers from main. Please rebase onto current dev (or drop the merge commits) so the PR only touches the WASM work. Mergeable is CLEAN either way, but merging as-is would land main's benchmark numbers into dev's README.

When you do, one thing to keep: the FIN=1 orphan CONTINUATION check from #175 that rides along in this branch is genuinely missing on dev (an orphan CONTINUATION with FIN=1 falls through both branches in cwist_websocket_receive() and is delivered as a complete message). If the rebase drops it, please split it into its own small PR and we will merge that first.

And a few follow-ups we would appreciate, roughly in priority order. Items 1 and 2 are small enough to fold into this PR; 3 and 4 can be separate issues if you prefer:

  1. WASM binary size report. Adding src/core/db/db.c + lib/sqlite3/sqlite3.c pulls all of SQLite into the wasm archive. A before/after size for libcwist_wasm.a and the linked wasm_smoke.wasm gives us the data to decide on a future opt-out or split build for users who do not need cwist_db.

  2. Run make format-check in the wasm CI job. The EM_JS => corruption you fixed recurs silently the next time anyone runs make format. The new job builds and smokes, but does not guard the formatter; adding one line to wasm.yml closes that loop for good.

  3. Turn the "session caveats" in wasm.md into measured behavior. The doc lists session persistence limits, but nothing tests what actually works vs fails under the WASM dispatch model. A short writeup (or a few smoke assertions) of observed behavior would anchor the Phase 3 session design.

  4. Phase 2 handoff. npm packaging and a first-party JS wrapper are the bulk of the next phase. Let us know if you want to keep going; if not, even a short API sketch (what to expose, module shape) would let someone else pick it up.

Happy to re-review quickly once the branch is rebased.

gg582 added a commit that referenced this pull request Sep 17, 2026
Tags already exist for v3.4 (2026-09-12), v3.4.1 (2026-09-14), and v3.5
(2026-09-15), but the milestone sections still read as plans. Convert
them to released, reference the unprofiled full-GC overhead follow-up
(#65), and add the v3.6 milestone (WASM client-side support, issue #93)
with the Phase 1-4 structure from PR #176 and its review follow-ups.
Also fix the stale v3.2 pin reference; the contract app tracks v3.3.
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.

1 participant