Skip to content

wasip2-examples: Tokio example apps for wasm32-wasip2#1

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/add-examples-for-tokio-wasip2
Draft

wasip2-examples: Tokio example apps for wasm32-wasip2#1
Copilot wants to merge 2 commits intomasterfrom
copilot/add-examples-for-tokio-wasip2

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 2, 2026

PR tokio-rs#7933 landed networking support for wasm32-wasip2. This adds a wasip2-examples/ crate that documents the current support scope and validates it with runnable examples.

What works on wasm32-wasip2

Feature Status
current_thread runtime, tokio::spawn, tokio::select!
tokio::time (sleep, interval, timeout)
tokio::sync (mpsc, oneshot, Mutex, Semaphore, Barrier)
TcpListener / TcpStream / TcpSocket ✅ requires tokio_unstable + wasmtime -Sinherit-network
UdpSocket (send/recv) ✅ requires tokio_unstable + wasmtime -Sinherit-network
rt-multi-thread, tokio::fs, tokio::process, DNS
SO_LINGER, POLLHUP, broadcast, multicast, peek

New crate: wasip2-examples/

Standalone crate (outside workspace) — only needs rt, macros, net, io-util, time, sync:

  • 01-hello.rs — timers, mpsc/oneshot channels, spawn, select!, timeout; no network
  • 02-tcp-echo.rsTcpListener binds ephemeral port, echo-server task accepts, TcpStream client round-trips three messages
  • 03-udp-echo.rs — two UdpSockets exchange datagrams with send_to/recv_from
  • 04-concurrent-tasks.rs — work queue (mpsc), shared counter (Mutex), rate limiter (Semaphore), rendezvous (Barrier)

All four use #[tokio::main(flavor = "current_thread")] — the multi-thread runtime is unavailable on wasip2.

Running

rustup target add wasm32-wasip2

# No-network examples
RUSTFLAGS="--cfg tokio_unstable" cargo run --target wasm32-wasip2 --bin 01-hello

# Network examples (wasmtime must be in PATH)
RUSTFLAGS="--cfg tokio_unstable" \
  CARGO_TARGET_WASM32_WASIP2_RUNNER="wasmtime run -Sinherit-network" \
  cargo run --target wasm32-wasip2 --bin 02-tcp-echo

CI

Build + run steps added to the existing wasm32-wasip2 job in ci.yml.

Copilot AI changed the title [WIP] Add examples for running Tokio with Wasip2 wasip2-examples: Tokio example apps for wasm32-wasip2 Apr 2, 2026
Copilot AI requested a review from Heap-Hop April 2, 2026 10:31
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