From 6532748d6cdc153a505dc3b2f9d12c58ab273e0b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 19 Mar 2023 22:04:36 +0100 Subject: [PATCH] Fix config.toml for the docker image --- .cargo/config-docker.toml | 11 ----------- Dockerfile | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 .cargo/config-docker.toml diff --git a/.cargo/config-docker.toml b/.cargo/config-docker.toml deleted file mode 100644 index 9eae839..0000000 --- a/.cargo/config-docker.toml +++ /dev/null @@ -1,11 +0,0 @@ -[net] -git-fetch-with-cli = true - -[target.x86_64-unknown-linux-gnu] -linker = "x86-64-linux-gnu-gcc" - -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" - -[target.armv7-unknown-linux-gnueabihf] -linker = "arm-linux-gnueabihf-gcc" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2dc1cae..ec700d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM --platform=${BUILDPLATFORM} rust:1.68-bullseye AS builder +ARG BUILDPLATFORM ARG TARGETPLATFORM ARG RUSTTARGET @@ -6,21 +7,37 @@ RUN apt-get update && \ apt-get upgrade --assume-yes RUN \ - if [ ${BUILDPLATFORM} = "linux/amd64" ] || [ ${TARGETPLATFORM} = "linux/amd64" ]; then \ + if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \ apt-get install --assume-yes gcc-x86-64-linux-gnu; \ fi && \ - if [ ${BUILDPLATFORM} = "linux/arm64" ] || [ ${TARGETPLATFORM} = "linux/arm64" ]; then \ + if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \ apt-get install --assume-yes gcc-aarch64-linux-gnu; \ fi && \ - if [ ${BUILDPLATFORM} = "linux/arm/v7" ] || [ ${TARGETPLATFORM} = "linux/arm/v7" ]; then \ + if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \ apt-get install --assume-yes gcc-arm-linux-gnueabihf; \ fi +RUN \ + mkdir .cargo && \ + echo '[net]' >> .cargo/config.toml && \ + echo 'git-fetch-with-cli = true' >> .cargo/config.toml && \ + if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \ + echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml; \ + echo 'linker = "x86-64-linux-gnu-gcc"' >> .cargo/config.toml; \ + fi && \ + if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \ + echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml; \ + echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml; \ + fi && \ + if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \ + echo '[target.armv7-unknown-linux-gnueabihf]' >> .cargo/config.toml; \ + echo 'linker = "arm-linux-gnueabihf-gcc"' >> .cargo/config.toml; \ + fi + RUN rustup target add ${RUSTTARGET} WORKDIR /usr/src/patched_porobot/ COPY ./ ./ -RUN mv ./.cargo/config-docker.toml ./.cargo/config.toml RUN cargo build --all-features --bins --release --target=${RUSTTARGET}