Overview
WebAssembly(WASM) is the binary format, can be compiled with C/C++/Rust and so on.
2 different file formats, a binary WebAssembly file (.wasm) as well as the text format for WebAssembly (.wat)
a *.wast file which is the test format for the official WebAssembly spec test suite.
Ahead-Of-Time (AOT) compile a WebAssembly module to produce a "compiled wasm" (.cwasm) file.
-
A standalone runtime for WebAssembly, WASI, and the Component Model by the Bytecode Alliance.
Wasmtime can be used as a library to embed WebAssembly execution support within applications.
Using wasmtime API allow user application like Rust/C to instantiate wasm module to be called from the application. -
WebAssembly System Interface, defines interfaces that provide a secure and portable way to access several operating-system-like features such as filesystems, networking, clocks, and random numbers.
Components can use WASI 0.2, but modules can use APIs from WASI 0.1, an earlier stage of WASI's development.According to the below, if you want to access the standard interfaces to the platform, WASI 0.2 is mandatory.
API Repository Version I/O wasi-io 0.2.0 Clocks wasi-clocks 0.2.0 Random wasi-random 0.2.0 Filesystem wasi-filesystem 0.2.0 Sockets wasi-sockets 0.2.0 CLI wasi-cli 0.2.0 HTTP wasi-http 0.2.0 -
WebAssembly Component Model is a broad-reaching architecture for building interoperable Wasm libraries, applications, and environments.
.wasm
core modules are defined by WebAssembly Core Specification, thosemodules
can run in the browser, or runtime such as wasmtime or WAMR. But core modules are limited in how they expose their functionality to the outside world to functions that take and return only a small number of core WebAssembly types (essentially only integers and floating-point numbers).
Against this, in the component model, those type interfaces are described in a language called WIT Wasm Interface Type, so component is wrapping core module to import and export the wit interfaces to interoperate.
This increases the wasm portability significantly. Not only for architectures and operating system, but also programming languages.
Combined with Wasm's strong sandboxing, this opens the door to yet further benefits.A WIT world is a higher-level contract that describes a component's capabilities and needs.
For example, WASI (the WebAssembly System Interface) defines a "command line" world which imports interfaces that command line programs typically expect to have available to them such as file I/O, random number generation, clocks and so on. This world has a single export for running the command line tool.
Examples
-
wasmtime examples
- Provides most of the major examples with C and Rust, with aligned rust tutorials and c tutorials.
- component tutorial
Runtime
Not to mention wasmtime as standard, there are many runtime supported for WASM.
Runtime | Features | Performance | Trade-offs |
---|---|---|---|
WAMR | Designed for resource-constrained environments, supports interpreter and AOT compilation, compatible with WASI | Optimized for low memory and low power devices | Sacrifices some performance for reduced resource consumption |
Wasmedge | Supports JIT compilation, AOT compilation, and interpreter modes, focuses on performance and platform compatibility | Emphasizes speed and efficiency | May require more memory and processing power compared to lightweight runtimes |
Wazero | Lightweight and minimalistic runtime, optimized for simplicity and efficiency | Prioritizes minimal resource consumption | Limited feature set compared to more comprehensive runtimes |
Wasmer | Provides support for JIT compilation, AOT compilation, and interpreter modes, focuses on performance, security, and flexibility | Offers competitive performance with a balance between speed and resource consumption | May require more memory and processing power compared to lightweight runtimes |
Wasmi | Pure Rust WebAssembly interpreter, designed for simplicity, portability, and ease of integration into Rust projects | Generally slower compared to JIT-based runtimes | Sacrifices some performance for simplicity and ease of use |
Wasm3 | High-performance WebAssembly interpreter, designed for efficiency and portability across various platforms | Emphasizes speed and efficiency | May not offer the same level of optimization as JIT-based runtimes |
Tools
-
WABT: The WebAssembly Binary Toolkit
WABT (we pronounce it "wabbit") is a suite of tools for WebAssembly, debugging and profiling utilities are supported.
e.g: converting WASM text format into WASM binary format.
wat2wasm hello.wat -o hello.wasm