Skip to content

Fix wasm32 failures and panics - #128

Open
sagikazarmark wants to merge 2 commits into
restatedev:mainfrom
sagikazarmark:wasm
Open

Fix wasm32 failures and panics#128
sagikazarmark wants to merge 2 commits into
restatedev:mainfrom
sagikazarmark:wasm

Conversation

@sagikazarmark

@sagikazarmark sagikazarmark commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This PR adds a CI job for checking the SDK on wasm32.

It also fixes a couple issues that otherwise result in panic in wasm32 environments.

Signed-off-by: Mark Sagi-Kazar <[email protected]>
@sagikazarmark sagikazarmark changed the title Fix wasm32 failures and panicy Fix wasm32 failures and panics Sep 3, 2026
@sagikazarmark
sagikazarmark marked this pull request as ready for review September 3, 2026 23:20
@sagikazarmark

Copy link
Copy Markdown
Contributor Author

Breaking build is unrelated to this change: Lokathor/tinyvec#225

@slinkydeveloper

Copy link
Copy Markdown
Contributor

Hi @sagikazarmark, why you build the sdk with wasm32? We didnt really designed the sdk to be buildable with wasm...

@sagikazarmark

sagikazarmark commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@slinkydeveloper To deploy it to Cloudflare Workers.

We talked about it here: #85 (where you indicated it should work)

The SDK is mostly wasm32 compatible by the way (or I should say, mostly Cloudflare Workers compatible): the time dependency can easily be replaced on wasm32, drain_input that uses tokio time wouldn't even work on Workers, because it only works with request-response mode)

On wasm32-unknown-unknown `std::time::{Instant, SystemTime}::now()` compile
but abort at runtime with "time not implemented on this platform", and
`tokio::time::timeout` panics without a runtime. `cargo check` cannot catch
either; `just check-wasm32` (previous commit) does, and now passes.

- Import `Instant`/`SystemTime` from `web_time` on that target. It mirrors
  the std API, so the call sites in `endpoint/context.rs` are unchanged and
  the native build keeps using std with no new dependency.
- Skip the 60s `tokio::time::timeout` around `drain_input` on that target;
  the host's request lifetime bounds the drain there instead.
- Select the `getrandom` JS backends (0.2 via shared-core -> jsonwebtoken,
  0.4 via rand) in the SDK's own wasm32 target table. Every wasm32 consumer
  needs them regardless of features, `web-time` already assumes a JS host,
  and 0.4 still honours a consumer's `--cfg getrandom_backend`. This makes
  the shim in `wasm-check` redundant, so it is removed.

Signed-off-by: Mark Sagi-Kazar <[email protected]>
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