Wasm Builders

Cover image for WebAssembly outside of Browser or for Non-Browser Case
Ajay Kumar
Ajay Kumar

Posted on • Updated on

WebAssembly outside of Browser or for Non-Browser Case

Non-browser workflow

As of now we are all familiar with NodeJS, which is a JavaScript runtime: that means Node.js help us to run JavaScript outside of browser.

Likewise to run WebAssembly outside of browser there are few runtimes such as Wasmer and  Wasmtime which help us to run WebAssembly.

Prerequisites

  • An interface to access system resources such as WASI
  • A runtime to which we also have support for above interface and C/C++/Rust to wasm compiler

wasi logo

Non-browser workflow

System Interface for WebAssembly

To run WebAssembly outside of the browser we need a way to talk to the system because we want support for features such as sockets, threads, files.

For that we need a system interface and this is where WebAssembly System Interface   WASI   comes into play, which is a system interface for the WebAssembly platform.

Non-browser workflow

Wasmer is a WebAssembly runtime having support for system interface  WASI   and  C/C++/Rust's to wasm compiler such as Emscripten, Clang, Rust, Clang etc.

Non-browser workflow

Features of Wasmer

  • Secure by default. No file, network, or environment access, unless explicitly enabled.
  • Supports WASI and Emscripten out of the box.
  • Fast. Run WebAssembly at near-native speeds.
  • Embeddable in multiple programming languages
  • Compliant with latest WebAssembly Proposals (SIMD, Reference Types, Threads, ...)

Installation
To install Wasmer runtime run the following command

curl https://get.wasmer.io -sSfL | sh
Enter fullscreen mode Exit fullscreen mode

Serving WASM file

wasmer run test.wasm
Enter fullscreen mode Exit fullscreen mode

Next we will see some examples for non-browser case
Link for browser case can be found here

Discussion (1)

Collapse
fyodorio profile image
Fyodor

Thanks for the great write-up, and please don’t get the following noob question personal, I just don’t know where to search for answers.

I’m not very familiar with WASM aspects tbh, but I get really confused when I see and read about things like WASI.

What’s the point of passing the code written in system programming languages like Rust or Go through WASM and transforming it back with WASI to access system resources?

Why not write it to work with bare metal directly from the beginning? What am I missing here?