Running WASM Unikernels

Ready to make your head spin?!?

Today we're going to convert some C to WASM. Then we're going to take that wasm and run it in a WASM VM as a unikernel! But wait that's not all - we are going to do all of this on our mac inside of a virtual machine! Good god - how many layers of virtual machines batman!?

Hold on - let's back up - what exactly is WASM or web assembly anyways? Web assembly is a new binary instruction format for a stack based virtual machine. That's not what is making geeks geek out though. It's the fact that it is meant to be a universal transpiler - you know kinda like the univeral translator from Star Trek but for programming languages.

To give you an idea of the amount of language support check out this repo.

I've always had a casual side interest in languages and language construction playing with everything from antlr to lex/yacc so while not getting the daily drip on the ecosystem I've kept a third eye on it. Interest got the better of me and I was curious if we could run WASM unikernels yet. Turns out we can. :)

Ready to see how far down the turtles go?!? Ok!

First thing we're going to do is create a small little c program:

#include <stdio.h>

int main() {
  printf("yyoyoy!\n");
  return 0;
}
Simple enough. Next let's compile it to wasm. Keep in mind I'm not a daily participant of this ecosystem so there just might be a better way of doing this. If you don't have the EMSDK grab it from here. Then after setting up the environment you can go ahead and compile like so:
source ./emsdk_env.sh
emcc hi.c -s WASM=1 -o hi.html
Great - now we got the wasm let's run it through wasmer. Wasmer is an interesting tool I've been keeping tabs on and watching from a distance. You can find it here. Now let's turn this thing into a unikernel! We'll be using OPS for this. Download OPS at https://ops.city or you can goto the github and compile from source: https://github.com/nanovms/ops . We'll create a small little config.json for it:
{
  "Args": ["run", "hi.wasm"],
  "Files": ["hi.wasm"]
}
This simply tells OPS to load the wasm file and pass it as an argument.
ops load wasmer_0.1.4 -c config.json

Boom - you just executed a wasm unikernel originally written in C. As a word of warning - if you're reading this in 6 months from the posting date there is a decent chance none of this works as web assembly is a moving target, wasmer is a moving target and ops is a moving target but until then - have fun.

Stop Deploying 50 Year Old Systems

Introducing the future cloud.

Ready for the future cloud?

Ready for the revolution in operating systems we've all been waiting for?

Schedule a Demo