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;
}
source ./emsdk_env.sh
emcc hi.c -s WASM=1 -o hi.html
{
"Args": ["run", "hi.wasm"],
"Files": ["hi.wasm"]
}
ops pkg 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.