Ok folks. It’s late in the evening and I set myself the challenge of getting WAMR working on a Raspberry PI1. Rather than just share the tips and tricks, I thought I’d share a bit of my log book, and late night random thoughts as I get things going. Maybe this will be amusing to read? Anyway, it might help me remember in the morning.

Building WAMR on a Raspberry Pi 1 (ARM 32bit)

One of the benefits of WebAssembly is that it can run everywhere, of course for that to be true there needs to be (with a few exceptions) a WebAssembly runtime everywhere.

Building WAMR for x86 based Linux is pretty straight forward, in fact, I’ve a blog post all about that. Building for ARM32, on an ARM32 device appears to be a little more complicated.

The Old Raspberry PI 1

One of the easiest was to play around with a 32bit ARM device is to actually get your hands on one. Growing up in the UK, the Acorn Archimedes was the computer in the school classroom. While most of my friends had Amigas or Atari STs at home only one friend, James had the same computer as the school did, the Acorn Archimedes. These computers were 32bit super fast ARM machines that came with a GUI way before Windows was a thing. Before I get too far down my own personal memory lane, let me stop. The important point is that these things were cool, and expensive which of course means as a kid I wanted one.

AcornArchimedes-Wiki

Today the same computers are still super cool, and now according to e-bay collectors items, so still bloody expensive. I was therefore kinda thrilled when the PI came along. A cool little 32bit ARM machine I could play around with, and if I ever wanted to it, could actually run the old operating system from the Archimedes….

…. but, right now, let’s stick with WebAssembly.

Building WAMR

We need a working version of WAMR, so let’s attempt to build one. The easiest way is to build the iwasm command line interpreter. Don’t forget to install the tooling covered in the getting started blog post. But doing this provides the following error:

[  1%] Building C object CMakeFiles/vmlib.dir/home/mad/wasm-micro-runtime/core/shared/platform/linux/platform_init.c.o
cc: error: unrecognized command-line option ‘-mindirect-branch-register’
make[2]: *** [CMakeFiles/vmlib.dir/build.make:76: CMakeFiles/vmlib.dir/home/mad/wasm-micro-runtime/core/shared/platform/linux/platform_init.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/vmlib.dir/all] Error 2                                                make: *** [Makefile:136: all] Error 2

So, what does -mindirect-branch-register actually do? … time to check interest search… and that’s not much use:

weird-search-results

Time to keep looking.

##The Solution

The problem is that the cmake build script for Linux isn’t automatically detecting that it is building on an ARM32 platform, instead we have to tell it. This can be done via editing the cmake file file as shown below (note the line set (WAMR_BUILD_TARGET "ARM32") # hard code the build target ):

cmakechangesforarm32

Or… alternatively, and probably much more easily you can just pass the option to the CMake file when you are building like this:

buildingforarm32

Hazzah! - It works. Build building on a Raspberry PI 1 can take a while… in true British fashion, it is time for a cup of tea, and judging by the length of time this build is taking, probably also a biscuit too.

After a while we have a working iwasm command line interpreter, which is awesome.

Building WASM on ARM32?

Typically, the easiest way to build wasm without the Emscripten tool chain is simply to use the WASI SDK. But if you check, there is no pre-built tool chain for ARM32.

wasi-sdk-without-arm32

You could build your .wasm file on an ARM32 using clang, llvm directly, and the sysroot packages, in fact there is a great blog post called ‘Compiling C to WebAssembly without Emscripten’ I’ve personally referred to a number of times by Surma. It’s an excellent read, but is beyond the scope of what I’m attempted to do. Given the late hour, and the lack of tea… I’ll come back to this later.

Testing the runtime on ARM32

For now we can build a simple helloworld.wasm file on a host machine, then transfer it to the PI1 for execution. Here is my simple helloworld.c:

helloworld

One quick file transfer later and this is now running on the PI1 -

HelloWorldOnPI1

I think that will do for tonight. The next step would be to see if we can get wamrc compiled on the PI1, then we can have ahead of time compiled wasm on the PI.