Cross compiling RethinkDB for ARM

Posted on March 6, 2015

Building RethinkDB on a Raspberry Pi takes a very long time. However we can speed it up using cross-compilation.


Cross-compilation allows us to build ARM software on a PC. There is a common terminology used when cross-compiling that can be confusing:

In this post, We will walk through the steps required to build on a Linux PC a version of RethinkDB that will run, or be hosted, on ARM.

The cross-compiler

The raspberrypi/tools repository on github contains a pre-compiled cross-compiler for the raspberry pi, with no installation necessary other than downloading the repository.

git clone --depth 1 pi-tools

If that compiler doesn’t work, tools such as crossdev or crossdev-ng can be used to build a cross-compiler from scratch.

The environment

RethinkDB makes two assumptions when cross-compiling:

This script will setup such an environment for us:

export CC=$CROSS-gcc
export CXX=$CROSS-g++
export LD=$CROSS-ld
export AR=$CROSS-ar
export RANLIB=$CROSS-ranlib

We can pass the -dumpmachine argument to GCC to check the target architecture:

$ uname -om
x86_64 GNU/Linux
$ gcc -dumpmachine
$ $CXX -dumpmachine

The build

We can now fetch and build RethinkDB for the Raspberry Pi.

git clone -b v2.0.x
cd rethinkdb
rm -rf external/v8*
./configure --allow-fetch --with-system-malloc
make -j `nproc`

When the build completes, we will have version of RethinkDB that runs on the Raspberry Pi:

$ scp build/release_system/rethinkdb pi:
$ ssh pi ./rethinkdb
Running rethinkdb 1.16.0-1-447-g4400d8 (GCC 4.8.3)...
Running on Linux 3.18.7+ armv6l