Skip to content

build(wasm): let the mem, crdt and client test targets build and run on wasip1 - #390

Closed
EnRaiha wants to merge 1 commit into
NodeDB-Lab:mainfrom
EnRaiha:fix/wasm-dev-deps
Closed

EnRaiha wants to merge 1 commit into
NodeDB-Lab:mainfrom
EnRaiha:fix/wasm-dev-deps

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

What

Make the test targets of nodedb-mem, nodedb-crdt and nodedb-client build
and run on wasm32-wasip1.

  • nodedb-mem, nodedb-crdt: tokio becomes a
    cfg(not(target_arch = "wasm32")) dev-dependency. nodedb-mem also gates
    fluxbench, which declares its own normal tokio = { features = ["full"] }.
  • nodedb-mem/src/budget.rs, nodedb-mem/src/governor/reserve.rs: two tests that
    drive the reserve path from std::thread::spawn are native-only, because this
    target has no threads. Their Arc, thread, DatabaseId and TenantId
    imports move into the gated function, as the neighbouring budget test already
    does.
  • nodedb-client: the native dev-dependency stays, and a second one covers wasm —
    tokio = { version = "1", default-features = false, features = ["rt", "macros", "sync", "time"] }.

Why

The workspace declares tokio = { version = "1", features = ["full"] }, and Cargo
unifies dev-dependency features across the whole cargo test invocation. On this
target tokio refuses anything beyond sync,macros,io-util,rt,time, so a single
dev-dependency of that shape breaks every wasm test target in the build. All three
crates died before reaching a test:

$ RUSTFLAGS="" cargo check --profile ci --target wasm32-wasip1 -p <crate> --tests
error: Only features sync,macros,io-util,rt,time are supported on wasm.
error: could not compile `tokio` (lib) due to 1 previous error
# exit 101, for nodedb-mem, nodedb-crdt and nodedb-client

Workspace inheritance is additive, so { workspace = true, features = ["rt", "macros"] }
does not avoid full; the wasm entry therefore names the version and the features
directly. rt and macros are supported on this target, which is why
nodedb-client keeps a Tokio runtime there and needs no test gating: all of its
tests run on both targets.

The other twelve shared crates have neither tokio nor fluxbench in a
dev-dependency section, so this is the whole set for the shared-crate wasm build.
nodedb-wal has the same shape and is covered by its own change.

How to check it

export CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime -W max-wasm-stack=33554432 --dir=."

# both targets, per crate
for c in nodedb-mem nodedb-crdt nodedb-client; do
  cargo test -p $c
  RUSTFLAGS="" cargo test --profile ci --target wasm32-wasip1 -p $c
done
Crate native wasm32-wasip1
nodedb-mem 86 passed, 0 failed 83 passed, 0 failed
nodedb-crdt 168 passed, 0 failed 168 passed, 0 failed
nodedb-client 34 passed, 0 failed 34 passed, 0 failed

The three nodedb-mem tests that do not run on this target are accounted for: two
are the thread tests gated here, and one is excluded by an existing
cfg(not(target_arch = "wasm32")) in nodedb-mem/src/arena.rs.

Before the change the same three cargo check --tests invocations exit 101 with
the tokio error above; after it they exit 0 and the suites run.

cargo fmt --all -- --check exits 0; cargo clippy -p <crate> --all-targets -- -D warnings exits 0 natively and for --target wasm32-wasip1.

Scope

  • The workspace's tokio = ["full"] is untouched: narrowing it would change every
    native consumer. The narrowing is per crate, at the dev-dependency.
  • Native coverage does not shrink: the two gated tests still build and run there,
    and the native counts above are unchanged from before.
  • No public API changed. This is the build half of the wasm test work; the test
    gating in nodedb-wal and the docs/wasm.md note remain in their own changes.
  • Test targets only. nodedb-client's optional normal tokio still carries the
    workspace's full, so a wasm build with its remote or native feature enabled
    still fails; that is a question about the crate's feature set, not about its
    tests, and it is left alone here.

…on wasip1

The workspace declares `tokio = { version = "1", features = ["full"] }`, and Cargo
unifies dev-dependency features across the whole `cargo test` invocation. On
`wasm32-wasip1` tokio refuses to build with anything beyond
`sync,macros,io-util,rt,time`, so one dev-dependency of that shape breaks every
wasm test target in the build: the shared-crate run for these three crates died
before reaching a single test (cargo exit 101, `error: Only features
sync,macros,io-util,rt,time are supported on wasm.`).

- `nodedb-mem` and `nodedb-crdt`: `tokio` becomes a
  `cfg(not(target_arch = "wasm32"))` dev-dependency. `nodedb-mem` also gates
  `fluxbench`, which declares its own normal `tokio = { features = ["full"] }`.
  Native test builds keep both.
- Two tests in `nodedb-mem` drive the reserve path from real threads, which this
  target does not have, and are gated to match. Their `Arc`, `thread`,
  `DatabaseId` and `TenantId` imports move into the gated function, as the
  neighbouring budget test already does.
- `nodedb-client` keeps its native dev-dependency and gets a second one for wasm:
  `tokio = { version = "1", default-features = false, features = ["rt", "macros",
  "sync", "time"] }`. Workspace inheritance is additive, so `{ workspace = true }`
  always carries `full`; naming the version and features directly is what lets the
  wasm target keep a Tokio runtime, and `rt`/`macros` are supported there. No test
  needed gating: all of its tests run on both targets.

Measured, per crate, `cargo test --profile ci --target wasm32-wasip1 -p <crate>`
with `CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime -W max-wasm-stack=33554432 --dir=."`:

    nodedb-mem     83 passed, 0 failed      (2 thread tests gated)
    nodedb-crdt   168 passed, 0 failed
    nodedb-client  34 passed, 0 failed

and natively, unchanged:

    nodedb-mem     86 passed, 0 failed
    nodedb-crdt   168 passed, 0 failed
    nodedb-client  34 passed, 0 failed

The other twelve shared crates carry neither `tokio` nor `fluxbench` in a
dev-dependency, so this is the whole set that blocked the wasm test build for
them. `nodedb-wal` has the same problem and its own change in flight.

fmt clean; clippy clean for all three crates natively and for `wasm32-wasip1`.
Copilot AI lite review requested due to automatic review settings September 27, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@EnRaiha

EnRaiha commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Closing. This change is confined to the wasm32/wasip1 path. NodeDB is a server, does not build for either target, and will not support wasm; that work belongs to NodeDB Lite. If some part of this changes behaviour on a supported target, say which part and it returns as its own PR.

@EnRaiha EnRaiha closed this Sep 28, 2026
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.

2 participants