8000 Build for WebAssembly (wasm32-wasip2) by arminhammer · Pull Request #51 · arminhammer/jackdaw · GitHub
[go: up one dir, main page]

Skip to content

Build for WebAssembly (wasm32-wasip2) - #51

Merged
arminhammer merged 1 commit into
mainfrom
wasm-support
Nov 6, 2026
Merged

arminhammer merged 1 commit into
mainfrom
wasm-support

Conversation

@arminhammer
Copy link
Copy Markdown
Owner

Summary

jackdaw can now be a dependency of a program that compiles to wasm32-wasip2 (wasmtime, Spin, wasmCloud). With the default features it builds and runs: the native API, the YAML interpreter and the Redb store work there. The browser target (wasm32-unknown-unknown) is not covered.

  • No threads: a new blocking module runs #[task(blocking)] tasks and every Redb operation on tokio's blocking pool, or, on wasm, where they are called. It also reads files, so tokio's fs feature is no longer needed.
  • OS-only dependencies are native-only: reqwest, sqlx, axum, tonic and the gRPC crates, bollard, openapiv3-extended and jsonschema are declared for non-wasm targets, together with tokio's process and rt-multi-thread.
  • What wasm can't do, and how it says so:
    • ctx.run_shell, ctx.run_script, ctx.run_container and ctx.http are not compiled there.
    • YAML run: shell, run: script, call: http and remote catalogs fail with "… is not available on wasm".
    • Building for wasm with sqlite, postgres, docker, http-listener, grpc-listener or openapi stops with an error that names the feature.
  • Checks: just wasm lints the library for the target across six feature sets and runs the @wasm specs. A new WebAssembly (WASI) CI job runs it, and JACKDAW_REQUIRE_WASM makes a missing wasmtime or target fail the job instead of skipping.
  • Docs: a new guide::wasm chapter, plus README, CONTRIBUTING and CHANGELOG updates.

Native builds

Nothing changes for native users, except that tokio's rt-multi-thread feature is now always enabled on native targets (it adds no crates, and yaml no longer asks for it), and tokio's fs feature is no longer enabled. The semver check, MSRV build and cargo deny are clean.

Tests

The specs were written before the implementation. platform/wasm.feature has 17 scenarios; each builds a small program from jackdaw/tests/wasm for wasm32-wasip2 and runs it under wasmtime:

  • a workflow, a fan-out with a retry, and a real-time sleep;
  • blocking tasks, with limits still capping the calls that wait;
  • a workflow resuming from a Redb file after the program stops during a timer, with the effect log showing a single charge;
  • YAML workflows that give the same output as the native engine, with checks that the loop, fork and calls actually ran;
  • the "not available on wasm" runtime errors and the build-time errors for six features.

Steps 2 and 4 of the plan passed as soon as the step before them was done, without work of their own. The scenarios were checked to fail on a wrong expectation.

Results: all 376 lib scenarios, CTK 21, listener 8, nested 3, lib 57, Rust API 76 and doctests 53 pass. Clippy is clean for each feature alone and for the full set.

Notes for review

  • The CI job hasn't run on GitHub yet. I ran its command locally (just wasm, exit 0), but the bytecodealliance/actions/wasmtime/setup@v1 action and the cache workspaces entry can only be checked by this PR's run.
  • A panicking task aborts the program on wasm instead of failing the step. I checked this, and the guide says so.
  • Not fixed, found on the way: durableengine/graph.rs::build_graph only creates sequential edges if no task in the workflow has a then, so mixing switch or then: with plain tasks ends the workflow early. It is unrelated to wasm. The new YAML workflows are written around it.

🤖 Generated with Claude Code

The library builds for wasm32-wasip2 with its default features and runs
under wasmtime: the native API, the YAML interpreter and the Redb store.

- A `blocking` module runs #[task(blocking)] tasks and Redb's operations on
  tokio's blocking pool, or where they are called on wasm, which has no
  threads. It also reads files, so tokio's `fs` feature is no longer needed.
- Dependencies that need an operating system (reqwest, sqlx, axum, tonic and
  the gRPC crates, bollard, openapiv3-extended, jsonschema) are declared for
  non-wasm targets only, with tokio's `process` and `rt-multi-thread`.
- Left out on wasm: ctx.run_shell/run_script/run_container/http (not
  compiled), and YAML `run: shell`, `run: script`, `call: http` and remote
  catalogs (they fail with "... is not available on wasm").
- Building for wasm with sqlite, postgres, docker, http-listener,
  grpc-listener or openapi stops with a message that names the feature.
- `just wasm` and a `WebAssembly (WASI)` CI job check the library for the
  target and run example programs under wasmtime.

Specs: platform/wasm.feature (17 scenarios) builds the programs under
tests/wasm for wasm32-wasip2 and runs them with wasmtime; they are skipped
without the target and wasmtime. New guide chapter `guide::wasm`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@arminhammer
arminhammer merged commit b49a8f4 into main Nov 6, 2026
19 checks passed
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

0