WasmEdge command line tool (CLI)
After installing WasmEdge or starting the WasmEdge app dev Docker container, there are several ways to run compiled WebAssembly programs.
wasmedge
The wasmedge binary file is a command line interface (CLI) program that runs WebAssembly bytecode programs.
- If the WebAssembly program contains a
main()function,wasmedgewould execute it as a standalone program in the command mode. - If the WebAssembly program contains one or more public functions,
wasmedgecould execute individual functions in the reactor mode.
Command line options
The options and flags for the wasmedge command are as follows.
- (Optional) Statistics information:
- Use
--enable-time-measuringto show the execution time. - Use
--enable-gas-measuringto show the amount of used gas. - Use
--enable-instruction-countto display the number of executed instructions. - Or use
--enable-all-statisticsto enable all of the statistics options.
- Use
- (Optional) Resource limitation:
- Use
--gas-limitto limit the execution cost. - Use
--memory-page-limitto set the limitation of pages(as size of 64 KiB) in every memory instance.
- Use
- (Optional) Reactor mode: use
--reactorto enable reactor mode. In the reactor mode,wasmedgeruns a specified function from the WebAssembly program.- WasmEdge will execute the function which name should be given in
ARG[0]. - If there’s exported function which names
_initialize, the function will be executed with the empty parameter at first.
- WasmEdge will execute the function which name should be given in
- (Optional) Binding directories into WASI virtual filesystem.
- Each directory can be specified as
--dir guest_path:host_path.
- Each directory can be specified as
- (Optional) Environ variables.
- Each variable can be specified as
--env NAME=VALUE.
- Each variable can be specified as
- Wasm file (
/path/to/wasm/file). - (Optional) Arguments.
- In reactor mode, the first argument will be the function name, and the arguments after
ARG[0]will be parameters of wasm functionARG[0]. - In command mode, the arguments will be parameters of function
_start. They are also known as command line arguments for a standalone program.
- In reactor mode, the first argument will be the function name, and the arguments after
Once installed, you can review and run our examples.
wasmedgec
The wasmedgec binary file is a program to compile WebAssembly bytecode programs into native machine code (i.e., the AOT compiler). The compiled machine code could be stored in the original wasm file, and the wasmedge CLI will automatically choose to execute the native machine code whenever it is available.
The options and flags for the wasmedgec are as follows.
- Input Wasm file(
/path/to/input/wasm/file). - Output file name(
/path/to/output/file).- By default, it will generate the universal Wasm binary format.
- Users can still generate native binary only by specifying the
.so,.dylib, or.dllextensions.
# This is slowwasmedge app.wasm# AOT compilewasmedgec app.wasm app.wasm# This is now MUCH fasterwasmedge app.wasm
On Linux systems, it could generate a so shared library file, which is then executed by the wasmedge CLI.
wasmedgec app.wasm app.sowasmedge app.so