Skip to content
Dariusz Olszewski edited this page Jun 13, 2024 · 15 revisions

A cross compilation environment is provided as a docker image. Build the image from the root of the project with the following command:

$ docker build -t librespot-cross -f contrib/Dockerfile .

The resulting image - when being run without any further command - i.e.:

docker run -v /tmp/librespot-build:/build librespot-cross

will build librespot for the following Linux architectures:

  • x86_64 - Intel/AMD (regular PC),
  • aarch64 - Arm 64-bit - e.g. Raspberry Pi OS 64-bit on Raspberry Pi 3 or later,
  • armhf - Arm v7 32-bit with hardware floating point - e.g. Raspberry Pi 2 or 3, but not Raspberry Pi 1 or Zero,
  • armel - would run on Pi 1 and Zero, but really slow due to software emulation of floating point operations - see below for how to build for Pi 1 and Zero with hardware floating point support.

Note: mipsel architecture was removed in PR #1299.

The compiled binaries will be located in /tmp/librespot-build/release/ for x86_64 and in /tmp/librespot-build/<architecture>/release/ for the other architectures.

If only one architecture is desired, cargo can be invoked directly with the appropriate options:

docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target arm-unknown-linux-gnueabi --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target aarch64-unknown-linux-gnu --no-default-features --features alsa-backend

Raspberry Pi 1 or Zero (armv6hf)

For Raspberry Pi 1 or Zero you can build librespot for armv6hf (ARMv6 with hardware floating point support) by building the specific docker image:

docker build -t librespot-cross-armv6hf -f contrib/cross-compile-armv6hf/Dockerfile .

Then run:

docker run -v /tmp/librespot-build-armv6hf:/build librespot-cross-armv6hf

The compiled binary will also be located here /tmp/librespot-build-armv6hf/arm-unknown-linux-gnueabihf/release/librespot.

Misc.

To resolve the error message librespot: Error getting 1120 bytes thread-local storage: No such file or directory on older Raspberry Pi devices (armv6 / target: arm-unknown-linux-musleabihf) will require the following additional compilation option:

RUSTFLAGS="-C target-feature=-crt-static"

SELinux

If you are running docker on a system with SELinux (RHEL, Centos, Fedora), add :Z to the end of the docker volume argument, to ensure the proper SELinux context is inherited by the directory used as a docker volume.

This yields the following commands:

docker run -v /tmp/librespot-build:/build:Z librespot-cross
docker run -v /tmp/librespot-build:/build:Z librespot-cross cargo build --release --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build:Z librespot-cross cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build:Z librespot-cross cargo build --release --target arm-unknown-linux-gnueabi --no-default-features --features alsa-backend