WebAssembly by Example is a hands-on introduction to WebAssembly using annotated example projects. Get started with the fibonacci example or click on any of the links below. You are encouraged to copy-paste bits from these examples into your own projects as needed.
WebAssembly is a type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++, C# and Rust with a compilation target so that they can run on the web. It is also designed to run alongside JavaScript, allowing both to work together.
🚩 Basics
- Return 42 in WebAssembly Text Format via JavaScript
- Fibonacci sequence in C via JavaScript
- Fibonacci sequence in Rust via JavaScript
- "Hello world!" in C via JavaScript
Fibonacci sequence in C via Python with $XFibonacci sequence in C via Rust with $XFibonacci sequence in C via Java with $XFibonacci sequence in Rust via C with $XFibonacci sequence in Rust via C++ with $X
👨💻 WASI
The WebAssembly System Interface (WASI) is a set of APIs for WASI being developed for eventual standardization by the WASI Subgroup, which is a subgroup of the WebAssembly Community Group.
🧰 Specialized tooling
- Use Rust in JavaScript through wasm-pack
- Use AssemblyScript in JavaScript
Use C++ in JavaScript through EmscriptenUse Go in JavaScript through GOOS=jsWrite Rust web apps using trunk
📦 WebAssembly component model
The WebAssembly Component Model is a broad-reaching architecture for building interoperable Wasm libraries, applications, and environments.
Create a WebAssembly component from Rust using cargo-componentCreate a WebAssembly component from JavaScript using jcoCompose WebAssembly components using wasm-toolsUse a WebAssembly component in JavaScript through jcoUse a WebAssembly component in Python with wasmtimeUse a WebAssembly component in Rust with wasmtime
⚙️ Advanced
Compile Rust to WASIXRun WASIX in JavaScript with WasmerCompile Rust to 64-bit WebAssemblyUse SDL2 in C++ in JavaScript through EmscriptenRun WASI preview1 on Arduino with Wasm3Write an HTTP endpoint in Rust with Wasmer