From 077949be20fb693f78d7c94d8d38df78262b1cdb Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:27:19 -0800 Subject: [PATCH] fix: cross-compiled bin not working without emulation on host; static link libc --- crates/bws/Dockerfile | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/bws/Dockerfile b/crates/bws/Dockerfile index 07f9f3a79..061f7e6a3 100644 --- a/crates/bws/Dockerfile +++ b/crates/bws/Dockerfile @@ -1,7 +1,7 @@ ############################################### # Build stage # ############################################### -FROM --platform=$BUILDPLATFORM rust:1.81 AS build +FROM rust:1.81 AS build # Docker buildx supplies the value for this arg ARG TARGETPLATFORM @@ -13,16 +13,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Copy required project files COPY . /app +# Set required args for build +ENV CARGO_TARGET_DIR='./target' +ENV RUSTFLAGS='-C target-feature=+crt-static' + # Build project WORKDIR /app/crates/bws -RUN cargo build --release --bin bws - -# Bundle bws dependencies -RUN mkdir /lib-bws -RUN mkdir /lib64-bws - -RUN ldd /app/target/release/bws | tr -s '[:blank:]' '\n' | grep '^/lib' | xargs -I % cp % /lib-bws -RUN ldd /app/target/release/bws | tr -s '[:blank:]' '\n' | grep '^/lib64' | xargs -I % cp % /lib64-bws +RUN <