librespot: switch from cross-compile to native ARM64 build
Cross-compile on x86_64 with qemu emulation takes >30min and hits 60-90min ceiling due to slow crate-by-crate aarch64 build under qemu. Native ARM64 build on RPi 3B+ with --jobs 2 (1GB RAM) is much faster. Rust 1.85.1 installed via rustup on RPi (precompiled aarch64 toolchain).
This commit is contained in:
+15
-23
@@ -1,51 +1,43 @@
|
|||||||
# Librespot (Spotify Connect) for ARM64
|
# Librespot (Spotify Connect) for ARM64
|
||||||
# Multi-stage: cross-compile Rust app on x86_64 builder, ship slim runtime.
|
# Multi-stage Docker build. Run on ARM64 host (RPi 3B+ etc).
|
||||||
# Audio output: PulseAudio (connect to audio-bridge via TCP localhost:4713).
|
# Audio output: PulseAudio (connects to audio-bridge via TCP localhost:4713).
|
||||||
|
|
||||||
FROM rust:1.85.1-bookworm AS builder
|
FROM rust:1.85.1-bookworm AS builder
|
||||||
|
|
||||||
# Cross-compile toolchain for aarch64
|
RUN apt-get update \
|
||||||
RUN rustup target add aarch64-unknown-linux-gnu
|
|
||||||
RUN dpkg --add-architecture arm64 \
|
|
||||||
&& apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends \
|
&& apt-get install -y --no-install-recommends \
|
||||||
gcc-aarch64-linux-gnu \
|
libpulse-dev \
|
||||||
libpulse-dev:arm64 \
|
libasound2-dev \
|
||||||
libasound2-dev:arm64 \
|
|
||||||
libssl-dev:arm64 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Build librespot. Pin to a known tag.
|
|
||||||
ARG LIBRESPOT_VERSION=v0.8.0
|
ARG LIBRESPOT_VERSION=v0.8.0
|
||||||
RUN git clone --depth 1 --branch ${LIBRESPOT_VERSION} \
|
RUN git clone --depth 1 --branch ${LIBRESPOT_VERSION} \
|
||||||
https://github.com/librespot-org/librespot.git /src
|
https://github.com/librespot-org/librespot.git /src
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
|
||||||
RUN cargo build --release --target aarch64-unknown-linux-gnu --no-default-features --features="pulseaudio-backend"
|
# Limit parallelism to 2 (RPi 3B+ has 4 cores but only 1GB RAM).
|
||||||
|
# Lower = less memory pressure, slower build. Higher = OOM risk.
|
||||||
|
RUN cargo build --release --jobs 2 \
|
||||||
|
--no-default-features \
|
||||||
|
--features="pulseaudio-backend"
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
RUN dpkg --add-architecture arm64 \
|
RUN apt-get update \
|
||||||
&& apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends \
|
&& apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libpulse0:arm64 \
|
libpulse0 \
|
||||||
libasound2:arm64 \
|
libasound2 \
|
||||||
libssl3:arm64 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=builder /src/target/aarch64-unknown-linux-gnu/release/librespot /usr/local/bin/librespot
|
COPY --from=builder /src/target/release/librespot /usr/local/bin/librespot
|
||||||
|
|
||||||
# Cache dir for Spotify credentials
|
|
||||||
VOLUME ["/var/cache/librespot"]
|
VOLUME ["/var/cache/librespot"]
|
||||||
|
|
||||||
# PulseAudio bridge is at localhost:4713 (audio-bridge)
|
|
||||||
ENV PULSE_SERVER=tcp:127.0.0.1:4713
|
ENV PULSE_SERVER=tcp:127.0.0.1:4713
|
||||||
|
|
||||||
CMD ["librespot", \
|
CMD ["librespot", \
|
||||||
"--name", "Klubhaus", \
|
"--name", "Klubhaus", \
|
||||||
"--backend", "pulseaudio", \
|
"--backend", "pulseaudio", \
|
||||||
"--device", "alsa_output.default", \
|
|
||||||
"--bitrate", "320", \
|
"--bitrate", "320", \
|
||||||
"--enable-audio-cache", \
|
"--enable-audio-cache", \
|
||||||
"--cache", "/var/cache/librespot"]
|
"--cache", "/var/cache/librespot"]
|
||||||
|
|||||||
Reference in New Issue
Block a user