WasmEdge or how to run webassembly code as a native object in a containerized environment
With many security challenges solved by design in its core conception, lots of projects benefit from using WebAssembly.
WasmEdge runtime is an efficient Virtual Machine optimized for edge computing. Its main use cases are:
- Jamstack apps, through a static front end with a serverless backend (FaaS)
- Automobiles
- IoT and Stream processing
It is an embeddable virtual machine that can be used as a process, in a process, or orchestrated as a native OCI container (providing an OCI compliant interface).
What is WebAssembly?
WebAssembly (Wasm) is a byte-code meant to be run alongside JavaScript, it is a successor to a few projects designed to speed-up code running in a browser.
Its most notable predecessors are asm.js and Google Native Client (GNI).
Asm.js and GNI had two different philosophies. The former uses a subset of JavaScript, therefore you only need a JavaScript engine to execute it. While the latter is a fully-fledged sandbox meant to be integrated into web browsers.
EmScripten is a tool allowing you to convert LLVM based byte-code (C, C++, Rust) to asm.js.
WebAssembly features are:
- Portable
- Secured
- Performant
- Reduced binary size
The WebAssembly specification defines two languages, the binary (compiled one), and the text one, made to be human-readable.
Here are examples of a code written in Rust and how it translates in WAT (WebAssembly Text).
Rust:
pub fn add_two(a: i32, b: i32) -> i32 {
a + b
}
WAT (WebAssembly Text):
(module
(type $t0 (func (param i32 i32) (result i32)))
(func $addTwo (export "add_two") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
(i32.add
(local.get $p0)
(local.get $p1))))