Top Related Projects
The WebAssembly Binary Toolkit
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Emscripten: An LLVM-to-WebAssembly Compiler
A TypeScript-like language for WebAssembly.
Facilitating high-level interactions between Wasm modules and JavaScript
🐍🕸 WebAssembly runtime for Python
Quick Overview
WebAssembly Micro Runtime (WAMR) is a lightweight, standalone WebAssembly runtime designed for resource-constrained devices and embedded systems. It provides a small footprint, efficient execution environment for WebAssembly applications, supporting various architectures and platforms.
Pros
- Small footprint and low memory usage, suitable for IoT and embedded devices
- Cross-platform support, including various architectures and operating systems
- Modular design allowing for customization and feature selection
- Active development and community support
Cons
- Limited ecosystem compared to more established runtimes
- May require additional tooling for optimal development experience
- Performance may not match native code in all scenarios
- Learning curve for developers new to WebAssembly
Code Examples
- Initializing the runtime:
#include "wasm_c_api.h"
wasm_engine_t* engine = wasm_engine_new();
wasm_store_t* store = wasm_store_new(engine);
- Loading and instantiating a WebAssembly module:
wasm_byte_vec_t binary;
wasm_module_t* module;
wasm_instance_t* instance;
// Load WebAssembly binary
load_module_file("example.wasm", &binary);
module = wasm_module_new(store, &binary);
// Instantiate the module
wasm_instance_new(store, module, NULL, &instance);
- Calling a WebAssembly function:
wasm_func_t* func;
wasm_val_t args[] = { WASM_I32_VAL(5) };
wasm_val_t results[1];
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
wasm_val_vec_t results_vec = WASM_ARRAY_VEC(results);
// Get exported function
func = wasm_extern_as_func(wasm_instance_exports(instance)->data[0]);
// Call the function
wasm_func_call(func, &args_vec, &results_vec);
printf("Result: %d\n", results[0].of.i32);
Getting Started
-
Clone the repository:
git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
-
Build WAMR:
cd wasm-micro-runtime/product-mini/platforms/linux mkdir build && cd build cmake .. make
-
Run a WebAssembly application:
./iwasm /path/to/your/wasm/app.wasm
For more detailed instructions and API usage, refer to the project's documentation and samples in the repository.
Competitor Comparisons
The WebAssembly Binary Toolkit
Pros of wabt
- Focuses on WebAssembly tooling, providing a comprehensive suite of tools for working with WebAssembly binaries
- Offers both command-line tools and a C API for integration into other projects
- Widely used and well-maintained by the WebAssembly community
Cons of wabt
- Primarily designed for development and tooling, not for runtime execution of WebAssembly modules
- May have a steeper learning curve for users who only need basic WebAssembly functionality
- Larger codebase and potentially higher resource usage compared to more lightweight alternatives
Code Comparison
wabt (C++):
#include "src/binary-reader.h"
#include "src/error-formatter.h"
wabt::Result ReadBinaryInterp(const void* data,
size_t size,
const ReadBinaryOptions& options,
Errors* errors,
ModuleDesc* out_module) {
// Implementation details...
}
wasm-micro-runtime (C):
#include "wasm_runtime.h"
wasm_module_t module;
char error_buf[128];
module = wasm_runtime_load(buffer, size, error_buf, sizeof(error_buf));
if (!module) {
printf("Error loading WebAssembly module: %s\n", error_buf);
return 1;
}
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Pros of Wasmer
- More comprehensive language support, including Rust, C/C++, Python, and others
- Advanced features like ahead-of-time (AOT) compilation for improved performance
- Extensive ecosystem with tools like Wasmer-JS for browser integration
Cons of Wasmer
- Larger runtime size and resource footprint
- Potentially more complex setup and configuration for simple use cases
- May have a steeper learning curve for beginners
Code Comparison
WASM Micro Runtime:
wasm_module_t module = wasm_runtime_load(buffer, size, error_buf, error_buf_size);
wasm_module_inst_t module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, error_buf, error_buf_size);
Wasmer:
let module = Module::from_binary(store, wasm_bytes)?;
let import_object = imports! {};
let instance = Instance::new(&module, &import_object)?;
Both projects aim to provide WebAssembly runtime environments, but they cater to different use cases. WASM Micro Runtime focuses on embedded systems and IoT devices, prioritizing a small footprint and efficiency. Wasmer, on the other hand, offers a more feature-rich environment suitable for a wider range of applications, including server-side and desktop scenarios.
Emscripten: An LLVM-to-WebAssembly Compiler
Pros of Emscripten
- Mature ecosystem with extensive documentation and community support
- Broader compatibility with existing C/C++ codebases
- Powerful toolchain for optimizing and debugging WebAssembly output
Cons of Emscripten
- Larger runtime overhead compared to WAMR
- More complex setup and configuration process
- May produce larger WebAssembly binaries for simple projects
Code Comparison
Emscripten (compiling C to WebAssembly):
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
int add(int a, int b) {
return a + b;
}
WAMR (running WebAssembly):
#include <wasm_export.h>
wasm_module_t module;
wasm_module_inst_t module_inst;
// Load and instantiate WebAssembly module
wasm_runtime_load_module(buffer, size, &module, error, sizeof(error));
module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, error, sizeof(error));
Both projects aim to bridge native code and WebAssembly, but they approach it from different angles. Emscripten focuses on compiling C/C++ to WebAssembly, while WAMR provides a runtime for executing WebAssembly modules. Emscripten offers a more comprehensive solution for porting existing codebases, while WAMR is lighter and more suitable for embedded systems or scenarios where a minimal WebAssembly runtime is needed.
A TypeScript-like language for WebAssembly.
Pros of AssemblyScript
- Familiar TypeScript-like syntax, making it easier for JavaScript developers to adopt
- Compiles directly to WebAssembly, offering better performance than JavaScript
- Rich ecosystem with tools and libraries specifically designed for AssemblyScript
Cons of AssemblyScript
- Limited compatibility with existing TypeScript/JavaScript libraries
- Smaller community and fewer resources compared to more established languages
- May require additional effort to optimize for specific WebAssembly use cases
Code Comparison
AssemblyScript:
export function add(a: i32, b: i32): i32 {
return a + b;
}
WASM-Micro-Runtime (using C):
int add(int a, int b) {
return a + b;
}
AssemblyScript focuses on providing a TypeScript-like experience for WebAssembly development, while WASM-Micro-Runtime is a lightweight runtime for WebAssembly that supports multiple languages. AssemblyScript is ideal for web developers looking to leverage their existing JavaScript/TypeScript knowledge, whereas WASM-Micro-Runtime offers a more flexible, multi-language approach for running WebAssembly in various environments.
Facilitating high-level interactions between Wasm modules and JavaScript
Pros of wasm-bindgen
- Specifically designed for Rust-to-WebAssembly interoperability
- Provides high-level abstractions for working with JavaScript APIs
- Offers automatic generation of TypeScript definitions
Cons of wasm-bindgen
- Limited to Rust-WebAssembly interactions
- May introduce overhead for simple use cases
- Requires additional build steps and tooling
Code Comparison
wasm-bindgen:
#[wasm_bindgen]
pub fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}
wasm-micro-runtime:
int32_t greet(wasm_exec_env_t exec_env, const char *name) {
printf("Hello, %s!\n", name);
return 0;
}
wasm-bindgen focuses on seamless Rust-JavaScript interoperability, providing a more idiomatic Rust experience. wasm-micro-runtime, on the other hand, offers a lightweight runtime for WebAssembly modules with broader language support and is better suited for embedded systems or scenarios where a minimal footprint is crucial. The choice between the two depends on the specific requirements of your project, such as target environment, performance needs, and preferred programming language.
🐍🕸 WebAssembly runtime for Python
Pros of wasmer-python
- Specifically designed for Python integration, offering a more seamless experience for Python developers
- Provides a high-level API for easy WebAssembly module management and execution
- Supports multiple compilation backends (Cranelift, LLVM, Singlepass) for optimized performance
Cons of wasmer-python
- Limited to Python ecosystem, whereas WASM-micro-runtime supports multiple languages
- May have a larger footprint and higher resource usage compared to the lightweight WASM-micro-runtime
- Potentially slower startup time due to its more comprehensive feature set
Code Comparison
wasmer-python:
from wasmer import Store, Module, Instance
store = Store()
module = Module(store, wasm_bytes)
instance = Instance(module)
result = instance.exports.sum(5, 37)
WASM-micro-runtime:
wasm_module_t module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf, sizeof(error_buf));
wasm_module_inst_t module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, error_buf, sizeof(error_buf));
wasm_exec_env_t exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
wasm_runtime_call_wasm(exec_env, func_name, argc, argv);
The code examples highlight the difference in API design and language focus between the two projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
WebAssembly Micro Runtime
A Bytecode Alliance project
Build WAMR | Build AOT Compiler | Embed WAMR | Export Native API | Build Wasm Apps | Samples
WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm) runtime with small footprint, high performance and highly configurable features for applications cross from embedded, IoT, edge to Trusted Execution Environment (TEE), smart contract, cloud native and so on. It includes a few parts as below:
- VMcore: A set of runtime libraries for loading and running Wasm modules. It supports rich running modes including interpreter, Ahead-of-Time compilation(AoT) and Just-in-Time compilation (JIT). WAMR supports two JIT tiers - Fast JIT, LLVM JIT, and dynamic tier-up from Fast JIT to LLVM JIT.
- iwasm: The executable binary built with WAMR VMcore which supports WASI and command line interface.
- wamrc: The AOT compiler to compile Wasm file into AOT file
- Useful components and tools for building real solutions with WAMR vmcore:
- App-framework: A framework for supporting APIs for the Wasm applications
- App-manager: A framework for dynamical loading the Wasm module remotely
- WAMR-IDE: An experimental VSCode extension for developping WebAssembly applications with C/C++
Key features
- Full compliant to the W3C Wasm MVP
- Small runtime binary size (core vmlib on cortex-m4f with tail-call/bulk memroy/shared memroy support, text size from bloaty)
- ~58.9K for fast interpreter
- ~56.3K for classic interpreter
- ~29.4K for aot runtime
- ~21.4K for libc-wasi library
- ~3.7K for libc-builtin library
- Near to native speed by AOT and JIT
- Self-implemented AOT module loader to enable AOT working on Linux, Windows, MacOS, Android, SGX and MCU systems
- Choices of Wasm application libc support: the built-in libc subset for the embedded environment or WASI for the standard libc
- The simple C APIs to embed WAMR into host environment, see how to integrate WAMR and the API list
- The mechanism to export native APIs to Wasm applications, see how to register native APIs
- Multiple modules as dependencies, ref to document and sample
- Multi-thread, pthread APIs and thread management, ref to document and sample
- wasi-threads, ref to document and sample
- Linux SGX (Intel Software Guard Extension) support, ref to document
- Source debugging support, ref to document
- XIP (Execution In Place) support, ref to document
- Berkeley/Posix Socket support, ref to document and sample
- Multi-tier JIT and Running mode control
- Language bindings: Go, Python, Rust
Wasm post-MVP features
- wasm-c-api, ref to document and sample
- 128-bit SIMD, ref to samples/workload
- Reference Types, ref to document and sample
- Bulk memory operations, Shared memory, Memory64
- Tail-call, Garbage Collection, Exception Handling
Supported architectures and platforms
The WAMR VMcore supports the following architectures:
- X86-64, X86-32
- ARM, THUMB (ARMV7 Cortex-M7 and Cortex-A15 are tested)
- AArch64 (Cortex-A57 and Cortex-A53 are tested)
- RISCV64, RISCV32 (RISC-V LP64 and RISC-V LP64D are tested)
- XTENSA, MIPS, ARC
The following platforms are supported, click each link below for how to build iwasm on that platform. Refer to WAMR porting guide for how to port WAMR to a new platform.
- Linux, Linux SGX (Intel Software Guard Extension), MacOS, Android, Windows, Windows (MinGW)
- Zephyr, AliOS-Things, VxWorks, NuttX, RT-Thread, ESP-IDF
Getting started
- Build VM core and Build wamrc AOT compiler
- Build iwasm (mini product): Linux, SGX, MacOS and Windows
- Embed into C/C++, Embed into Python, Embed into Go, Embed in Rust
- Register native APIs for Wasm applications
- Build wamrc AOT compiler
- Build Wasm applications
- Port WAMR to a new platform
- VS Code development container
- Samples and Benchmarks
- End-user APIs documentation
Performance and memory
- Blog: The WAMR memory model
- Blog: Understand WAMR heaps and stacks
- Blog: Introduction to WAMR running modes
- Memory usage tuning: the memory model and how to tune the memory usage
- Memory usage profiling: how to profile the memory usage
- Performance tuning: how to tune the performance
- Benchmarks: checkout these links for how to run the benchmarks: PolyBench, CoreMark, Sightglass, JetStream2
- Performance and footprint data: the performance and footprint data
Project Technical Steering Committee
The WAMR PTSC Charter governs the operations of the project TSC. The current TSC members:
- dongsheng28849455 - Dongsheng Yan, dongsheng.yan@sony.com
- loganek - Marcin Kolny, mkolny@amazon.co.uk
- lum1n0us - Liang Heï¼ liang.he@intel.com
- no1wudi Qi Huang, huangqi3@xiaomi.com
- qinxk-inter - Xiaokang Qinï¼ xiaokang.qxk@antgroup.com
- ttrenner - Trenner, Thomasï¼ trenner.thomas@siemens.com
- wei-tang - Wei Tangï¼ tangwei.tang@antgroup.com
- wenyongh - Wenyong Huangï¼ wenyong.huang@intel.com
- woodsmc - Woods, Chrisï¼ chris.woods@siemens.com
- xujuntwt95329 - Jun Xuï¼ Jun1.Xu@intel.com
- xwang98 - Xin Wangï¼ xin.wang@intel.com (chair)
- yamt - Takashi Yamamoto, yamamoto@midokura.com
License
WAMR uses the same license as LLVM: the Apache 2.0 license
with the LLVM
exception. See the LICENSE file for details. This license allows you to freely
use, modify, distribute and sell your own products based on WAMR.
Any contributions you make will be under the same license.
More resources
Top Related Projects
The WebAssembly Binary Toolkit
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Emscripten: An LLVM-to-WebAssembly Compiler
A TypeScript-like language for WebAssembly.
Facilitating high-level interactions between Wasm modules and JavaScript
🐍🕸 WebAssembly runtime for Python
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot