Today I read very interesting article about running WebAssembly without the browser.

I won't get into details about WebAssembly itself because it's rather material for the full blog post instead of TIL article.

In very few words (and very inaccurate), WebAssembly is binary language which can be executed by Virtual Machine embedded in the browsers. Because it's binary — it's smaller, and it can be faster delivered to the browsers. And the Virtual Machine (and language itself) is designed to allow faster execution than JavaScript. Of course, it's not always the case, but, again, that's not the topic for this article.

I knew that WebAssembly runs on Virtual Machine. I wasn't aware that those Virtual Machines are already accessible as libraries! How exciting is that! You can basically point this VM to your rust code and instruct it to run your code.

There are at least three VMs:

  • wasmtime
  • WAMR — WebAssembly Micro Runtime
  • WASM3

It looks like only wasmtime allows debugging stuff.

For the exact details of how to compile your code to WebAssembly and how to use wasmtime to load your code as a module and then execute exported functions - go to the original article I linked above.