Skip to content

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

Notifications You must be signed in to change notification settings

dicej/wasi-sockets-tests

Repository files navigation

wasi-sockets test harness

This is a test harness for prototyping support for wasi-sockets in the Rust std library and wasi-libc.

Note that you can already use wasi-sockets by calling host functions directly from C, Rust, Python, and other languages with Component Model support. What's missing as of this writing is standard library support for those languages, which is what this repository is intended to exercise as progress is made.

Directory structure

  • server: test host using wasmtime and wasmtime-wasi to provide a host environment
  • client: Rust test guest using wasi-sockets host functions directly
  • client-std: Rust test guest using std::net. Note that, as of this writing, tests using this guest will fail unless you use forks of Rust and wasi-libc as described below.
  • client-tokio: Rust test guest using tokio::net. As with client-std, you'll need to use the forks discussed below.
  • client-tokio-postgres: Rust test guest using tokio-postgres on top of tokio::net. As with client-std, you'll need to use the forks discussed below.
  • client-python: Python test using asyncio, built as a component by componentize-py
  • client-python-redis: Python test using redis-py

Building and running

Prerequisites

  • Unix-style host (e.g. Linux, MacOS, Mingw, WSL2)
  • Python
  • Rust (with the wasm32-wasi and wasm32-unknown-unknown targets installed)

In the commands that follow, replace aarch64-apple-darwin with your host platform's target triple, and replace macos with linux or mingw (Windows) as appropriate.

Note that cloning the llvm-project submodule of the rust repo may take a long time.

TODO: Can we speed up the Rust build by excluding tools we don't need?

curl -LO https://github.com/dicej/wasi-sdk/releases/download/wasi-sockets-alpha-5/wasi-sdk-20.46gf3a1f8991535-macos.tar.gz
tar xf wasi-sdk-20.46gf3a1f8991535-macos.tar.gz
export WASI_SDK_PATH=$(pwd)/wasi-sdk-20.46gf3a1f8991535
export WASI_SDK_SYSROOT=$WASI_SDK_PATH/share/wasi-sysroot
cd ..
git clone https://github.com/dicej/rust -b sockets
cd rust
./configure \
    --target=wasm32-wasi,wasm32-unknown-unknown,aarch64-apple-darwin \
    --set=target.wasm32-wasi.wasi-root=$WASI_SDK_SYSROOT \
    --enable-lld \
    --tools=cargo \
    --prefix=$(pwd)/build/install \
    --sysconfdir=$(pwd)/build/etc \
    --set=build.docs=false
./x.py install
rustup toolchain link wasi-sockets build/install
export WASI_SOCKETS_TESTS_TOOLCHAIN=wasi-sockets
cd ..

Once the above is complete, you can switch to the server directory in your clone of this repo and run the tests:

cd server
cargo test --release

All tests should pass. If they don't, please open an issue on this repo.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published