Running Rust on ARM32v7 via QEMU.

Introduction

In this article we will explore how to use QEMU to run emulating the ARM32v7 architecture to build and run Rust code like if it was a native ARM32v7 architecture.

There are some drawbacks and performance considerations when using this approach, it can be simpler but way slower for big projects.

The source for this article is here RCV and the docker image is here.

This article can be considered a part 2 of Running rust on ARM32v7K3S Oracle cluster so we will not be creating the rust project and all that here, but focusing on building and running the project.

Prerequisites

Let’s jump to the example

The new Dockerfile

You will notice that this Dockerfile is way simpler than the ones from the previous article, since it runs natively as ARM32v7, the main difference is the base image being arm32v7/rust:1.63.0, this can be further extended for more architectures, see this article for more information.

Last steps for QEMU/Docker

After installing the required packages you will still need to perform some simple steps in order for it to work with docker and buildah, the first command is needed for docker to be able to use the required QEMU emulation and the second is just to validate that everything works fine

Short names error

If you get an error about short names when pulling images add the following line to your /etc/containers/registries.conf file

Lets build it

For the build we will use buildah because it is smarter than docker for this kind of scenarios.

Lets test it

After building it, we can push it to the docker daemon and then run it and test it from another terminal

Notice: you will see some warnings about the architecture, that’s fine as we are emulating things.

Performance considerations

This project build with the rust toolchain and then copied to an ARM32v7 image took 2 minutes, but using QEMU and the given emulation it took around 8 minutes and a half, so it is something to be aware since the difference is quite big.

Extra

You can see it running here, a very basic HTML Curriculum vitae.

For more details and to see how everything fits together I encourage you to clone the repo, test it, and modify it to make your own.

Closing notes

Be sure to check the links if you want to learn more about the examples, I hope you enjoyed it, see you on twitter or github!

The source for this article is here

Errata

If you spot any error or have any suggestion, please send me a message so it gets fixed.

Also, you can check the source code and changes in the generated code and the sources here