Skip to content

Latest commit

 

History

History
69 lines (44 loc) · 1.47 KB

File metadata and controls

69 lines (44 loc) · 1.47 KB

Use wstd::net::TcpStream to send HTTP(s) requests from inside WASM in WASI Preview 2 environment

Instructions for this devcontainer

Tested with Rust 1.93.0, wstd examples v0.6.5, Wasmtime v41.0.3.

Preparation

  1. Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.

  2. Install WASI Preview 2 build target into Rust toolchain:

rustup target add wasm32-wasip2

Building

  1. cd into the folder of this example:
cd wasip2-sockets-wstd
  1. Clone the wstd repo:
git clone --depth=1 https://github.com/bytecodealliance/wstd.git
  1. cd into the folder of wstd:
cd wstd
  1. Add http-enabled example to examples folder:
cp ../tcp_stream_http_client.rs ./examples/
  1. Compile all the examples:
cargo build --release --examples -p wstd --target wasm32-wasip2

Test with Wasmtime

  1. Install Wasmtime:
curl https://wasmtime.dev/install.sh -sSf | bash
  1. Run Wasmtime with bunch of network-related plugins enabled against just-compiled raw-socket-based HTTP Client example:
~/.wasmtime/bin/wasmtime run -S inherit-network -S allow-ip-name-lookup target/wasm32-wasip2/*/examples/tcp_stream_http_client.wasm
  1. See the results in terminal.

Finish

Perform your own experiments if desired.