Cross compiling - librespot-org/librespot GitHub Wiki

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 will build librespot for Linux x86_64, aarch64, armhf (compatible e. g. with Raspberry Pi 2 or 3, but not with 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) and mipsel when being run without any further command:

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

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
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target mipsel-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