Skip to content

[Impl/WASM][Plan/CWIST v3.6] CWIST WASM #93

Description

@gg582

Where WASM support actually stands today

Verified directly (real Emscripten build + node smoke test, not just reading the roadmap checkmarks):

  • make wasm builds libcwist_wasm.a clean from src/core/{sstring,seq,seq_auth}, sys/err/error.c, net/http/{http,mux,query,cookie,session}.c, sys/app/{app,middleware,config,logger,shutdown,big_dumb_reply,test_client}.c, core/{siphash,utils/json_builder,utils/json_heal,utils/zod,template,html/builder,html/css_composer,validation/bind,mem/alloc,mem/arena}.c, and cJSON.c. Deliberately excludes sockets, TLS, QUIC/HTTP-3, gRPC (needs HTTP/2), WebSocket transport, threads/scheduler, compression, DB/sync clients.
  • cwist_app_dispatch_memory() + <cwist/wasm/typedarray.h> (CWIST_WASM_EXPOSE_*, CWIST_WASM_INSTALL_VIEWS, Module.cwistView.{u8,i32,f64}) work end to end: make wasm-smoke actually runs a real request through a real handler and reads the response back as a zero-copy Uint8Array from JS. Confirmed passing right now.

This is a real, working foundation — but it's a library artifact you have to build yourself and wire up by hand. "Usable enough to actually reach for" needs the gaps below closed.

Gaps found while verifying

  1. cwist_db WASM claim doesn't match the build. ROADMAP.md marks cwist_db_open_memory()/cwist_db_serialize() as a shipped WASM feature (v3.4 checklist), but src/core/db/db.c and lib/sqlite3/sqlite3.c are not in Makefile's WASM_SRCS. Either the roadmap entry is wrong, or the wiring was never finished — needs one or the other fixed before anyone tries to use it.
  2. No WASM CI. wasm-smoke is explicitly "not part of make test since CI has no Emscripten toolchain" (Makefile comment). Nothing catches a WASM-only regression except someone manually running it — which is how gap Add doxygen style comments #1 above went unnoticed.
  3. No packaged/published artifact. There's no npm package, no versioned .wasm/.js release asset, nothing beyond "clone the repo, install Emscripten yourself, run make wasm". Every consumer re-derives the EM_JS glue from scratch.
  4. No docs. No docs/api/wasm.md. The only end-user-facing mention is a few lines in the Korean tutorial about css_composer.c being WASM-buildable — nothing documenting cwist_app_dispatch_memory, the TypedArray helpers, or which subsystems are actually in-scope.
  5. Browser/Emscripten only. Everything here targets Module.cwistView + EM_JS, i.e. a browser or Node-with-Emscripten host. No WASI target, so CWIST handlers can't run on WASI-based edge runtimes (Cloudflare Workers, wasmtime, Fastly Compute) — which is presumably what ROADMAP.md's separate, still-🔮 "Serverless / WASM Runtime: Edge deployment target" line is actually after. Worth deciding whether that's this workstream's endgame or a genuinely separate effort.
  6. No streaming. cwist_app_dispatch_memory() is whole-request-in, whole-response-out. Fine for a single edge-function invocation; not fine for anything that wants to stream a large response back to JS incrementally.
  7. Session/cookie story is unclear under WASM. cookie.c/session.c compile into libcwist_wasm.a, but nothing documents or tests how session state is expected to persist across calls when the host (a Service Worker, a JS fetch handler) may not keep the same WASM instance alive between requests.
  8. No example app. tests/wasm_smoke.c is a smoke test (one route, asserts response bytes), not a demonstration of a realistic app — no example showing routing + validation (zod.c, already compiled in) + templating (template.c/html/builder.c, already compiled in) actually being used together from JS.

Proposed roadmap (toward "comfortable to actually use")

Phase 1 — Fix what's already claimed done

  • Resolve the cwist_db WASM gap: either wire db.c/sqlite3.c into WASM_SRCS and verify cwist_db_open_memory/cwist_db_serialize really work under Emscripten, or correct ROADMAP.md to stop claiming it.
  • Add a WASM build+smoke job to CI (install Emscripten in the runner image or use emsdk's Docker image) so wasm/wasm-smoke stop being a manual-only check.

Phase 2 — Developer experience / packaging

  • Write docs/api/wasm.md: what's in scope, the dispatch_memory + TypedArray pattern, a minimal end-to-end example.
  • Publish a versioned build artifact (npm package wrapping the .wasm/.js glue, or a GitHub Release asset alongside native binaries) so npm install replaces "clone + install emsdk + make wasm".
  • A small first-party JS wrapper module (thin fetch-shaped API over Module.cwistView/ccall) so consumers don't hand-roll EM_JS glue for the common case.

Phase 3 — Expand the supported surface

  • Decide and scope a WASI target for edge runtimes, separate from the browser/Emscripten target — this is the actual gap between today's WASM support and ROADMAP's "Serverless / WASM Runtime" line.
  • Streaming response support for dispatch_memory (or a parallel streaming entry point) for larger payloads.
  • Document (and add a test for) the session/cookie persistence model under a request-per-call WASM host.

Phase 4 — Real example

  • A full example app (routing + zod validation + template/html/builder rendering + cwist_db once Phase 1 lands) as a Cloudflare Worker or Service Worker demo, checked into example/ alongside the existing native examples.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions