WASM to WASI
Tags: webassembly, wasi, rust
Published: 2019-04-29 07:48:24

---
title: WASM to WASI
published: true
tags: wasm,wasi,rust
canonical_url: 
---

You would have to try hard to avoid hearing about WebAssembly/WASM. Hardly a day goes by without another article popping up.

Some years ago we used [emscripten](https://emscripten.org/) to turn a C/C++ game engine into JavaScript/WebGL for running in a web browser. Amusing, but the resulting mess was big, slow, and pretty painful to debug. [Unity dialed this to 11](https://blogs.unity3d.com/2015/05/06/an-introduction-to-ilcpp-internals): `C# -> (via Mono) IL -> (via IL2CPP) C++ -> (via emscripten) JavaScript`. They deserve a tip o’ the hat for that impressive bit of software engineering gymnastics, but I’m glad I never had to use it.

I’ve been curious about the tech behind WASM, but not being a web-frontend guy was only casually/passively interested. WASI changes that by embracing WASM outside the browser; another contender for the [“write once, run anywhere”](https://en.wikipedia.org/wiki/Write_once,_run_anywhere) panacea.

_The Rust Connection_. Namely, why Rust? The Rust team made [WASM a focus for 2018](https://blog.rust-lang.org/2018/03/12/roadmap.html#four-target-domains) because [reasons](https://mgattozzi.com/rust-wasm/). The crux of the argument being:

1. Languages without runtimes are the best candidates for WASM (i.e. C/C++/Rust)
2. Rust is better/safer/easier (especially for people coming from JavaScript) than C/C++

Perhaps subjective, but palatable with the right colored glasses (unless you’re a diehard C/C++ enthusiast). Are Rust and WASM the solution to all your problems? Probably not, but we can be interested in the tech regardless.

Rather than write a verbose treatise on WASM basics (of which there are many), thought I’d round up various resources and notes/browser tabs I’ve got hanging around.

Introduction to WASM:

- [WASM: Universal Application Runtime](https://cybernetist.com/2019/04/25/wasm-universal-application-runtime/)
- https://webassembly.org/

WASI- WASM outside the browser:

- [Standardizing WASI: A system interface to run WebAssembly outside the web](https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/)
- https://wasi.dev/

Use cases:

- Serverless:    
  - [Serverless Rust with AWS Lambda and WebAssembly](https://blog.scottlogic.com/2018/10/18/serverless-rust.html)
  - [Serverless Rust with Cloudflare Workers](https://blog.cloudflare.com/cloudflare-workers-as-a-serverless-rust-platform/) and now [The Wrangler CLI: Deploying Rust with WASM on Cloudflare Workers](https://blog.cloudflare.com/introducing-wrangler-cli/)
  - [The Promise of WebAssembly](https://dev.to/ryan_levick/the-promise-of-webassembly-2obi)
- Embedding:    
  - [Embedding WebAssembly in your Rust application](https://medium.com/wasmer/executing-webassembly-in-your-rust-application-d5cd32e8ce46)
- [Others](https://webassembly.org/docs/use-cases/)

Digging in:

- [Rust WASM working group](https://rustwasm.github.io/) and [docs](https://rustwasm.github.io/docs.html).
- Runtimes: [wasmtime](https://github.com/CraneStation/wasmtime/), [Lucet](https://github.com/fastly/lucet), and [wasmer](https://github.com/wasmerio/wasmer) (all built with [cranelift](https://github.com/CraneStation/cranelift)). [cervus](https://github.com/cervus-v/cervus) Linux user-mode.    
  - [Announcing Lucet: Fastly’s native WebAssembly compiler and runtime](https://www.fastly.com/blog/announcing-lucet-fastly-native-webassembly-compiler-runtime)
- [js-sys](https://docs.rs/crate/js-sys): Rust bindings to JavaScript ECMAScript standard.
- [web-sys](https://docs.rs/crate/web-sys/): Rust bindings to browser APIs. Auto-generated from [WebIDL](https://heycam.github.io/webidl/).
- Performance:    
  - [WebAssembly Is Fast: A Real-World Benchmark of WebAssembly vs. ES6](https://medium.com/@torch2424/webassembly-is-fast-a-real-world-benchmark-of-webassembly-vs-es6-d85a23f8e193)
- Internals:    
  - [Multithreading Rust and Wasm](https://rustwasm.github.io/2018/10/24/multithreading-rust-and-wasm.html)
  - [Memory in WebAssembly (and why it’s safer than you think)](https://hacks.mozilla.org/2017/07/memory-in-webassembly-and-why-its-safer-than-you-think/). Just check out the [Mozilla blog](https://hacks.mozilla.org/) there’s other interesting stuff there, no need to individually link it all.

Misc:

- [Rust -> WASM in web browser](https://rust.godbolt.org/z/PZqG56)