Linux command
wasmtime 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run a WebAssembly file
wasmtime [program.wasm]
Run with directory access
wasmtime --dir [/path/to/dir] [program.wasm]
Invoke a specific exported function
wasmtime run --invoke [function_name] [program.wasm] [args]
Run a WASI HTTP server
wasmtime serve [component.wasm]
Compile to native ahead-of-time
wasmtime compile [program.wasm] -o [program.cwasm]
Run compiled module
wasmtime run [program.cwasm]
Enable WASI features
wasmtime -S inherit-env [program.wasm]
说明
wasmtime is a standalone WebAssembly runtime from the Bytecode Alliance. It executes WebAssembly modules and components outside the browser, supporting WASI (WebAssembly System Interface) for system access. The runtime can execute both binary (.wasm) and text (.wat) WebAssembly files. For performance-critical applications, modules can be ahead-of-time compiled to native code using the compile subcommand. By default, Wasmtime sandboxes modules with no access to system resources. Access to files, environment, and network must be explicitly granted through command-line options. The serve subcommand runs WebAssembly components implementing the wasi:http/proxy interface as HTTP servers.
参数
- --dir _path_
- Grant access to host directory.
- --env _key=value_
- Set environment variable.
- --invoke _expr_
- Invoke specific exported function.
- -O, --optimize _options_
- Optimization settings.
- -C, --codegen _options_
- Code generation settings.
- -D, --debug _options_
- Debug settings.
- -W, --wasm _options_
- WebAssembly semantics settings.
- -S, --wasi _options_
- WASI configuration (inherit-env, inherit-network).
- --config _file_
- Load settings from TOML file.
- -h, --help
- Display help.
- -V, --version
- Display version.
FAQ
What is the wasmtime command used for?
wasmtime is a standalone WebAssembly runtime from the Bytecode Alliance. It executes WebAssembly modules and components outside the browser, supporting WASI (WebAssembly System Interface) for system access. The runtime can execute both binary (.wasm) and text (.wat) WebAssembly files. For performance-critical applications, modules can be ahead-of-time compiled to native code using the compile subcommand. By default, Wasmtime sandboxes modules with no access to system resources. Access to files, environment, and network must be explicitly granted through command-line options. The serve subcommand runs WebAssembly components implementing the wasi:http/proxy interface as HTTP servers.
How do I run a basic wasmtime example?
Run `wasmtime [program.wasm]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --dir _path_ do in wasmtime?
Grant access to host directory.