Open2

Rustのwasm32-wasip2に関するPull requests, Crates, Cargo.tomlとか集めるスレ

黒ヰ樹黒ヰ樹

Why

Rust Version 1.82.0 (2024-10-17)にPromote wasm32-wasip2 to Tier 2.がきたのでaxumをWASMで動かすための情報収集をしたい。
自力でaxumをWASMで動かせるようになったらクローズ予定。

Pull requests

https://github.com/tokio-rs/mio/pull/1836
https://github.com/tokio-rs/tokio/pull/6893
https://github.com/rust-lang/libc/pull/3981
https://github.com/rust-lang/socket2/pull/532
https://github.com/seanmonstar/reqwest/pull/2453
https://github.com/servo/rust-url/pull/983
https://github.com/leptos-rs/leptos/pull/3063

mioがwasm32-wasip2サポートしたらtokioもwasm32-wasip2サポート予定。

https://github.com/rust-lang/rust/pull/129638
https://github.com/rust-lang/rust/pull/131449

socket2の

The wasm32-wasip2 target will be a tier 2 target starting with Rust 1.82 and will gain improved socket support in Rust 1.83, so it felt like it made sense to add support for WASIp2 now.

はこのPull requestsのことっぽい。

httpはwasi Crates使う予定なさそう。

https://github.com/hyperium/http/pull/720
https://github.com/bytecodealliance/wasi-rs/pull/90
https://github.com/wasmCloud/wasmCloud/pull/3444

現時点でhyper, axumはPull requestsなさそう。

https://github.com/hyperium/hyper
https://github.com/tokio-rs/axum

Crates

getrandomは使える。

https://crates.io/crates/getrandom

chronoも使える?

https://crates.io/crates/chrono-wasi

WASI専用のHTTPリクエストクライアント&Webサーバーライブラリ。
wasm32-wasip2で使える。

https://crates.io/crates/waki

leptosはwasm32-wasip2サポート予定。

https://crates.io/crates/leptos
https://github.com/leptos-rs/leptos_wasi

Cargo.toml

https://github.com/WasmEdge/wasmedge_hyper_demo/blob/main/server-axum/Cargo.toml
https://github.com/WasmEdge/wasmedge_reqwest_demo/blob/main/Cargo.toml
https://github.com/wasix-org/wasix-rust-examples/blob/main/wasix-axum/Cargo.toml

数ヶ月前まではlibc, socket2, tokio, hyper, reqwestのPatchを作っていた。

Runtime

https://github.com/bytecodealliance/wasmtime

$ wasmtime -V
wasmtime-cli 24.0.0 (6fc3d274c 2024-08-20)
$ wasmtime -h
Wasmtime WebAssembly Runtime

Usage: wasmtime [OPTIONS] <WASM>...
       wasmtime <COMMAND>

Commands:
  run       Runs a WebAssembly module
  config    Controls Wasmtime configuration settings
  compile   Compiles a WebAssembly module
  explore   Explore the compilation of a WebAssembly module to native code
  serve     Serves requests from a wasi-http proxy component
  settings  Displays available Cranelift settings for a target
  wast      Runs a WebAssembly test script file
  help      Print this message or the help of the given subcommand(s)

Arguments:
  <WASM>...  The WebAssembly module to run and arguments to pass to it

Options:
  -O, --optimize <KEY[=VAL[,..]]>    Optimization and tuning related options for wasm performance, `-O help` to see all
  -C, --codegen <KEY[=VAL[,..]]>     Codegen-related configuration options, `-C help` to see all
  -D, --debug <KEY[=VAL[,..]]>       Debug-related configuration options, `-D help` to see all
  -W, --wasm <KEY[=VAL[,..]]>        Options for configuring semantic execution of WebAssembly, `-W help` to see all
  -S, --wasi <KEY[=VAL[,..]]>        Options for configuring WASI and its proposals, `-S help` to see all
      --allow-precompiled            Allow executing precompiled WebAssembly modules as `*.cwasm` files
      --profile <STRATEGY>           Profiling strategy (valid options are: perfmap, jitdump, vtune, guest)
      --dir <HOST_DIR[::GUEST_DIR]>  Grant access of a host directory to a guest
      --env <NAME[=VAL]>             Pass an environment variable to the program
      --invoke <FUNCTION>            The name of the function to run
      --preload <NAME=MODULE_PATH>   Load the given WebAssembly module before the main module
      --argv0 <ARGV0>                Override the value of `argv[0]`, typically the name of the executable of the application being run
  -h, --help                         Print help (see more with '--help')
  -V, --version                      Print version

If a subcommand is not provided, the `run` subcommand will be used.

Usage examples:

Running a WebAssembly module with a start function:

  wasmtime example.wasm
                  
Passing command line arguments to a WebAssembly module:

  wasmtime example.wasm arg1 arg2 arg3

Invoking a specific function (e.g. `add`) in a WebAssembly module:

  wasmtime --invoke add example.wasm 1 2