From 8d3f2ed7adae10e25e4d5bafe7e868a73ebee715 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 10 Dec 2021 10:52:58 +0100 Subject: [PATCH] More cross-compilation platforms --- Dockerfile | 25 +++++++++++++++++++------ docker-bake.hcl | 7 ++++++- misc/docker-arch-to-rust-target.sh | 8 +++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4286cd325..529573929 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,32 +29,45 @@ RUN find public -type f -exec touch -t 197001010000.00 {} + # The image Debian base name (bullseye) must be in sync with the runtime variant (debian11) FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-slim-${DEBIAN_VERSION_NAME} AS chef -# Install x86_64 and aarch64 cross-compiling stack +# Install x86_64, aarch64 and arm (v6 and v7) cross-compiling stack RUN apt update && apt install -y --no-install-recommends \ g++-x86-64-linux-gnu \ g++-aarch64-linux-gnu \ + g++-arm-linux-gnueabihf \ libc6-dev-arm64-cross \ libc6-dev-amd64-cross \ + libc6-dev-armhf-cross \ && rm -rf /var/lib/apt/lists/* WORKDIR /app RUN cargo install --locked cargo-chef ENV \ + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \ + CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \ + CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \ CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \ CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \ - CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \ - CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \ - CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ + CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CC_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ + CXX_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ + CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ ARG RUSTC_VERSION ARG TARGETPLATFORM +# Install all cross-compilation targets +RUN rustup target add --toolchain "${RUSTC_VERSION}" \ + x86_64-unknown-linux-gnu \ + aarch64-unknown-linux-gnu \ + arm-unknown-linux-gnueabihf \ + armv7-unknown-linux-gnueabihf + # Helper script that transforms docker platforms to LLVM triples COPY ./misc/docker-arch-to-rust-target.sh / -# Install the right toolchain for cross-compilation -RUN rustup target add `/docker-arch-to-rust-target.sh "${TARGETPLATFORM}"` --toolchain "${RUSTC_VERSION}" ## Run the planner from cargo-chef ## FROM --platform=${BUILDPLATFORM} chef AS planner diff --git a/docker-bake.hcl b/docker-bake.hcl index a466aebf2..dc5b442b5 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -14,7 +14,12 @@ target "debug" { target "release" { inherits = ["default"] - platforms = ["linux/amd64", "linux/arm64"] + platforms = [ + "linux/amd64", + "linux/arm64", + "linux/arm/v6", + "linux/arm/v7", + ] } // This is what is baked by GitHub Actions diff --git a/misc/docker-arch-to-rust-target.sh b/misc/docker-arch-to-rust-target.sh index 76bafaa11..673c4db3a 100755 --- a/misc/docker-arch-to-rust-target.sh +++ b/misc/docker-arch-to-rust-target.sh @@ -5,10 +5,16 @@ if [ "$#" -ne 1 ]; then exit 1 fi -if [ "$1" = "linux/arm64" ]; then +if [ "$1" = "linux/arm64" -o "$1" = "linux/arm64/v8" ]; then echo "aarch64-unknown-linux-gnu" +elif [ "$1" = "linux/arm" -o "$1" = "linux/arm/v7" ]; then + echo "armv7-unknown-linux-gnueabihf" +elif [ "$1" = "linux/arm/v6" ]; then + echo "arm-unknown-linux-gnueabihf" elif [ "$1" = "linux/amd64" ]; then echo "x86_64-unknown-linux-gnu" +elif [ "$1" = "linux/i386" ]; then + echo "i686-unknown-linux-gnu" else echo "unsupported platform $1" >&2 exit 2