Stream: wasmtime

Topic: ✔ getting `mio` example working again


view this post on Zulip Frank Rehwinkel (Apr 30 2024 at 15:35):

There is an example in the mio crate that claims to show there is limited support for wasm from two years ago. https://github.com/tokio-rs/mio/blob/master/examples/tcp_listenfd_server.rs

The file has the following comments:

// You can run this example from the root of the mio repo:
// cargo run --example tcp_listenfd_server --features="os-poll net"
// or with wasi:
// cargo +nightly build --target wasm32-wasi  --example tcp_listenfd_server --features="os-poll net"
// wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_listenfd_server.wasm

But the instructions seem out of date. First it doesn't compile because some warnings are treated as errors. But if that is worked around by allowing warnings so they are not treated as errors, the call to wasmtime fails because the args have changed.
The best I could come up with is this command, but it fails too.

$ wasmtime -S tcplisten=127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_listenfd_server.wasm
Error: components do not support --tcplisten
Metal I/O library for Rust. Contribute to tokio-rs/mio development by creating an account on GitHub.

view this post on Zulip Alex Crichton (May 02 2024 at 11:49):

That mio example is pretty old yeah and is built on outdated support for sockets in WASI. More-or-less the mio support needs to be updated/rewritten to use wasip2 instead of wasip1

view this post on Zulip Frank Rehwinkel (May 02 2024 at 12:09):

If I can get the -S tcplisten arg to work again, I will send a PR to mio with what I find. Just today someone else is trying to use that argument with a fresh tokio wasi build.

view this post on Zulip Joel Dice (May 02 2024 at 13:39):

This is my cue to spam everybody with my mio/tokio WASIp2 proof of concept: https://github.com/dicej/wasi-sockets-tests

Test harness for prototyping support for wasi-sockets in the Rust std library and wasi-libc - dicej/wasi-sockets-tests

view this post on Zulip Frank Rehwinkel (May 02 2024 at 13:55):

Found the new incantation (as long as mio is still being built against wasi 0.11.0).

cargo build --target wasm32-wasi --example tcp_listenfd_server --features="os-poll net"
wasmtime run -S preview2=n -S tcplisten=127.0.0.1:9000 --env 'LISTEN_FDS=1' ./target/wasm32-wasi/debug/examples/tcp_listenfd_server.wasm

It's a neat little demo of a single threaded TCP listener able to write to any nc that connections to it, and echo to stdout anything that the nc endpoints may send to it. I tried with two nc connected at the same time.

view this post on Zulip Notification Bot (May 02 2024 at 21:32):

Frank Rehwinkel has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC