Convert Figma logo to code with AI

bytecodealliance logowasm-micro-runtime

WebAssembly Micro Runtime (WAMR)

4,782
605
4,782
370

Top Related Projects

6,727

The WebAssembly Binary Toolkit

18,439

🚀 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

  1. Initializing the runtime:
#include "wasm_c_api.h"

wasm_engine_t* engine = wasm_engine_new();
wasm_store_t* store = wasm_store_new(engine);
  1. 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);
  1. 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

  1. Clone the repository:

    git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
    
  2. Build WAMR:

    cd wasm-micro-runtime/product-mini/platforms/linux
    mkdir build && cd build
    cmake ..
    make
    
  3. 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

6,727

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;
}
18,439

🚀 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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

WebAssembly Micro Runtime

A Bytecode Alliance project

Guide  Website  Chat

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

Wasm post-MVP features

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.

Getting started

Performance and memory

Project Technical Steering Committee

The WAMR PTSC Charter governs the operations of the project TSC. The current TSC members:

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