From 262fc2e8201dedfbfe1278af566cc78b6fcad94b Mon Sep 17 00:00:00 2001 From: Gabriel Pajot Date: Mon, 11 Mar 2024 10:34:20 +0100 Subject: [PATCH] fix: working armv6hf docker image for cross-compiling --- contrib/Dockerfile | 8 +-- contrib/cross-compile-armv6hf/Dockerfile | 49 +++++++++++++++++++ contrib/cross-compile-armv6hf/docker-build.sh | 14 ++++++ contrib/docker-build-pi-armv6hf.sh | 17 ------- 4 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 contrib/cross-compile-armv6hf/Dockerfile create mode 100755 contrib/cross-compile-armv6hf/docker-build.sh delete mode 100755 contrib/docker-build-pi-armv6hf.sh diff --git a/contrib/Dockerfile b/contrib/Dockerfile index 8baa36ae..1b420020 100644 --- a/contrib/Dockerfile +++ b/contrib/Dockerfile @@ -2,7 +2,7 @@ # Build the docker image from the root of the project with the following command : # $ docker build -t librespot-cross -f contrib/Dockerfile . # -# The resulting image can be used to build librespot for linux x86_64, armhf(with support for armv6hf), armel, mipsel, aarch64 +# The resulting image can be used to build librespot for linux x86_64, armhf, armel, mipsel, aarch64 # $ docker run -v /tmp/librespot-build:/build librespot-cross # # The compiled binaries will be located in /tmp/librespot-build @@ -13,8 +13,6 @@ # $ 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 contrib/docker-build-pi-armv6hf.sh - FROM debian:stretch RUN dpkg --add-architecture arm64 @@ -40,10 +38,6 @@ RUN mkdir /.cargo && \ echo '[target.arm-unknown-linux-gnueabi]\nlinker = "arm-linux-gnueabi-gcc"' >> /.cargo/config && \ echo '[target.mipsel-unknown-linux-gnu]\nlinker = "mipsel-linux-gnu-gcc"' >> /.cargo/config -RUN mkdir /build && \ - mkdir /pi-tools && \ - curl -L https://github.com/raspberrypi/tools/archive/648a6eeb1e3c2b40af4eb34d88941ee0edeb3e9a.tar.gz | tar xz --strip-components 1 -C /pi-tools - ENV CARGO_TARGET_DIR /build ENV CARGO_HOME /build/cache ENV PKG_CONFIG_ALLOW_CROSS=1 diff --git a/contrib/cross-compile-armv6hf/Dockerfile b/contrib/cross-compile-armv6hf/Dockerfile new file mode 100644 index 00000000..c7f73f4c --- /dev/null +++ b/contrib/cross-compile-armv6hf/Dockerfile @@ -0,0 +1,49 @@ +# Cross compilation environment for librespot in armv6hf. +# Build the docker image from the root of the project with the following command: +# $ docker build -t librespot-cross-armv6hf -f contrib/cross-compile-armv6hf/Dockerfile . +# +# The resulting image can be used to build librespot for armv6hf: +# $ docker run -v /tmp/librespot-build-armv6hf:/build librespot-cross-armv6hf +# +# The compiled binary will be located in /tmp/librespot-build-armv6hf/arm-unknown-linux-gnueabihf/release/librespot + +FROM --platform=linux/amd64 ubuntu:18.04 + +# Install common packages. +RUN apt-get update +RUN apt-get install -y -qq git curl build-essential libasound2-dev libssl-dev libpulse-dev libdbus-1-dev + +# Install armhf packages. +RUN echo "deb [arch=armhf] http://ports.ubuntu.com/ubuntu-ports/ bionic main" | tee -a /etc/apt/sources.list +RUN apt-get update +RUN apt-get download libasound2:armhf libasound2-dev:armhf libssl-dev:armhf libssl1.1:armhf +RUN mkdir /sysroot && \ + dpkg -x libasound2_*.deb /sysroot/ && \ + dpkg -x libssl-dev*.deb /sysroot/ && \ + dpkg -x libssl1.1*.deb /sysroot/ && \ + dpkg -x libasound2-dev*.deb /sysroot/ + +# Install rust. +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y +ENV PATH="/root/.cargo/bin/:${PATH}" +RUN rustup target add arm-unknown-linux-gnueabihf +RUN mkdir /.cargo && \ + echo '[target.arm-unknown-linux-gnueabihf]\nlinker = "arm-linux-gnueabihf-gcc"' >> /.cargo/config + +# Install Pi tools for armv6. +RUN mkdir /pi && \ + git -C /pi clone --depth=1 https://github.com/raspberrypi/tools.git + +# Build env variables. +ENV CARGO_TARGET_DIR /build +ENV CARGO_HOME /build/cache +ENV PATH="/pi/tools/arm-bcm2708/arm-linux-gnueabihf/bin:${PATH}" +ENV PKG_CONFIG_ALLOW_CROSS=1 +ENV PKG_CONFIG_PATH_arm-unknown-linux-gnueabihf=/usr/lib/arm-linux-gnueabihf/pkgconfig/ +ENV C_INCLUDE_PATH=/sysroot/usr/include +ENV OPENSSL_LIB_DIR=/sysroot/usr/lib/arm-linux-gnueabihf +ENV OPENSSL_INCLUDE_DIR=/sysroot/usr/include/arm-linux-gnueabihf + +ADD . /src +WORKDIR /src +CMD ["/src/contrib/cross-compile-armv6hf/docker-build.sh"] diff --git a/contrib/cross-compile-armv6hf/docker-build.sh b/contrib/cross-compile-armv6hf/docker-build.sh new file mode 100755 index 00000000..ab84175c --- /dev/null +++ b/contrib/cross-compile-armv6hf/docker-build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eux + +PI1_TOOLS_DIR="/pi/tools/arm-bcm2708/arm-linux-gnueabihf" + +PI1_LIB_DIRS=( + "$PI1_TOOLS_DIR/arm-linux-gnueabihf/sysroot/lib" + "$PI1_TOOLS_DIR/arm-linux-gnueabihf/sysroot/usr/lib" + "/sysroot/usr/lib/arm-linux-gnueabihf" + "/sysroot/lib/arm-linux-gnueabihf" +) +export RUSTFLAGS="-C linker=$PI1_TOOLS_DIR/bin/arm-linux-gnueabihf-gcc ${PI1_LIB_DIRS[*]/#/-L}" + +cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features "alsa-backend" diff --git a/contrib/docker-build-pi-armv6hf.sh b/contrib/docker-build-pi-armv6hf.sh deleted file mode 100755 index 676b84c5..00000000 --- a/contrib/docker-build-pi-armv6hf.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# largerly inspired by https://github.com/Spotifyd/spotifyd/blob/993336f7/.github/workflows/cd.yml#L109 - -set -eux - -# See https://github.com/raspberrypi/tools/commit/5caa7046 -# Since this commit is not (yet) contained in what is downloaded in Dockerfile, we use the target of the symlink directly -PI1_TOOLS_DIR="/pi-tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf" - -PI1_LIB_DIRS=( - "$PI1_TOOLS_DIR/arm-linux-gnueabihf/sysroot/lib" - "$PI1_TOOLS_DIR/arm-linux-gnueabihf/sysroot/usr/lib" -) -export RUSTFLAGS="-C linker=$PI1_TOOLS_DIR/bin/arm-linux-gnueabihf-gcc ${PI1_LIB_DIRS[@]/#/-L}" - -cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features "alsa-backend"