Wasmtime
Docs
https://wasmtime.dev/
https://docs.wasmtime.dev/introduction.html
GitHub.icon https://github.com/bytecodealliance/wasmtime
概要
WASM の処理系 の 1 つ
WebAssembly Component をコンパイルし、サンドボックス 上で実行することが可能
Rust などのコード上からも、CLI からも実行可能
コード: https://docs.wasmtime.dev/cli.html
CLI: https://docs.wasmtime.dev/lang.html
CLI のインストール
$ cargo install wasmtime-cli
warning.icon
サンドボックス上で実行されるため、shell とは異なるファイルシステムツリーが提供される
そのため、shell からは存在が確認できるファイルも、Wasmtime 上で動作する WebAssembly Component からは存在しないものとして扱われる
回避策
実行時に --dir を使ってアクセスできるディレクトリを明示する必要がある
code:sh
$ wasmtime --help
...
--dir <HOST_DIR::GUEST_DIR>
Grant access of a host directory to a guest.
If specified as just HOST_DIR then the same directory name on the host is made
available within the guest.
If specified as HOST::GUEST then the HOST directory is opened and made available as
the name GUEST in the guest.
code:sh
$ wasmtime --dir . target/wasm32-wasip1/debug/grep-wasi.wasm file src/main.rs
その他、以下のような値も Wasmtime が動作している環境から切り離されて提供されている
環境変数とその値
code:rs
use std::env;
fn main() {
for (key, value) in env::vars() {
println!("{key}: {value}");
}
}
cargo run で実行した場合: 設定されている環境変数の一覧が表示される
code:sh
$ cargo run
CARGO_HOME: /.../.cargo
CARGO_MANIFEST_DIR: /.../grep-wasi
...
Wasmtime 上で実行した場合: 何も表示されない
code:sh
$ wasmtime target/wasm32-wasip1/debug/process-list.wasm
ソケット の状態
WebAssembly Component の使用するメモリ空間
#WebAssembly