Cross Compilation - Faster Builds
Multi-stage build
Dockerfile setup
# 1. -- Sysroot stage. Runs in arm64 emulation (QEMU) --
# Install library dependencies
FROM auterion/app-base:v2 as sysroot-stage
RUN apt update && apt install -y \
<DEPENDENCIES>
# 2. -- Cross-compile build stage. Runs native on x86 --
FROM --platform=$BUILDPLATFORM auterion/app-cross-buildenv:v2 as build-stage
# Variable to contain the target arch. Set automatically by docker to either "arm64" or "amd64"
ARG TARGETARCH
# This is the magic part - copy the entire sysroot from the first stage into
# /opt/sysroot. This path is indicated in the Toolchain file as the place
# to look for libraries to link against. This makes sure, we link against the
# right libraries (the arm64 versions)
COPY --from=sysroot-stage / /opt/sysroot
# Copy and compile the app
COPY app /app
WORKDIR /app
# Build your app using the right toolchain file. Selected by $TARGETARCH variable
RUN cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/Toolchain_$TARGETARCH.cmake && \
cmake --build build
# 3. -- Runtime stage. Runs in arm64 emulation and on target --
FROM sysroot-stage as run-stage
COPY --from=build-stage /app/build /app/build
CMD /app/my_app
app-cross-buildenv contents
Last updated