WASI Virtual Layer is a virtual file system layer for WebAssembly System Interface (WASI) modules. It allows you to run WASI modules with a virtual file system that can be customized and extended.
- Install the CLI tool with
cargo binstall wasi_virt_layer-cli- Prepare a WebAssembly module built for wasip1 (e.g. wasm32-wasip1 or wasm32-wasip1-threads).
- Create a new virtual filesystem (VFS) project with
cargo new --lib nameand add the following to your Cargo.toml:
[lib]
crate-type = ["cdylib"]- Add wasi_virt_layer and wit-bindgen as dependencies, and create a wit directory.
- Use the import_wasm! macro to prepare for using the wasm module.
- Use the plug! macro series (plug_process!, plug_env!, etc.) to connect to the wasip1 ABI, and link virtual filesystems or virtual environment variables.
- Run the command
wasi_virt_layer wasm_pathto execute the program. 7. The built files will be generated in the dist directory. 8. Run it with
deno run dist/test_run.tsor start a static server and open test_run.html in your browser.
By using plug! to block all WASIp1 ABIs and creating the ABI solely with wit-bindgen, it is entirely possible to treat it as a component. However, wasip1-threads is not supported as per the specification. For further details, please refer to the example.
- Support non-binary Wasm modules
- Enable specifying multiple Wasm modules
- Support self binary
- support flush sync to file system
- Fake global allocator and center allocator and merge with vfs
- Access Time Trait
- Multiple lfs file system (VFS)
- Static file system
- Feature Access time etc traits
- Separate mode (connect function by javascript)
- threading vfs with non threading wasm
- valider with error on threads
- Unicode support
cargo r -r -- -p example_vfs examples/test_wasm/example/test_wasm_opt.wasm
cargo r -r -- -p threads_vfs test_threads -t single --threads true- support wasm-bindgen because it cannot use wasi
cargo r -- -p threads_vfs test_threads -t multi --threads true _resetなしだとsingleもmultiも成功
test_threads::_reset();
test_threads::_start();
test_threads::_main();
だとmultiで成功。singleでunreacable
ここら辺もテストに追加 build target dirのキャッシュ(--no-cache) 同時実行対策 超絶長い引数で失敗するかも 自分自身を呼び出す(フォールバック)