From 6a07a2f47cffe27c2a2b5d50d8097d65e701ae59 Mon Sep 17 00:00:00 2001 From: perennial Date: Tue, 13 Aug 2024 23:33:32 +1000 Subject: [PATCH] Dockerfile: let Rustup handle architecture detection More flexible as the build process will now automatically adapt to whatever architecture the container is being built on, without needing to explicitly list out each supported architecture --- Dockerfile | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index d83de4e..3622fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,18 +19,8 @@ ENV OPENSSL_DIR=/usr # Copy the current directory contents into the container COPY . . -# Set up build arguments for architecture detection -ARG TARGETARCH - -# Set the Rust target based on the detected architecture -RUN case "$TARGETARCH" in \ - "amd64") echo "x86_64-unknown-linux-musl" > /tmp/target ;; \ - "arm64") echo "aarch64-unknown-linux-musl" > /tmp/target ;; \ - *) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \ - esac - -# Add the target to rustup and build the application -RUN RUST_TARGET=$(cat /tmp/target) && \ +# Determine the target architecture and build the application +RUN RUST_TARGET=$(rustc -vV | sed -n 's/host: //p') && \ rustup target add $RUST_TARGET && \ RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target $RUST_TARGET