# ========================================================================= # Stage 1: Native Host Builder # We use --platform=$BUILDPLATFORM so the container runs natively on your # Mac's ultra-fast CPU instead of running slow ARM-to-Intel emulation. # ========================================================================= FROM --platform=$BUILDPLATFORM rust:slim AS builder # Install linkers and cross-compilers for Linux ARM64, Linux x86, and Windows RUN apt-get update && apt-get install -y \ build-essential \ gcc-aarch64-linux-gnu \ gcc-x86-64-linux-gnu \ mingw-w64 \ && rm -rf /var/lib/apt/lists/* WORKDIR /workspace COPY . . # Capture target arguments from the docker buildx flag ARG TARGETOS ARG TARGETARCH # Dynamically cross-compile based on the platform requested by Buildx RUN set -ex; \ if [ "$TARGETOS" = "linux" ] && [ "$TARGETARCH" = "amd64" ]; then \ rustup target add x86_64-unknown-linux-gnu; \ export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc; \ cargo build --release --target x86_64-unknown-linux-gnu; \ mkdir -p /out; cp target/x86_64-unknown-linux-gnu/release/libtbr.so /out/; \ \ elif [ "$TARGETOS" = "linux" ] && [ "$TARGETARCH" = "arm64" ]; then \ rustup target add aarch64-unknown-linux-gnu; \ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc; \ cargo build --release --target aarch64-unknown-linux-gnu; \ mkdir -p /out; cp target/aarch64-unknown-linux-gnu/release/libtbr.so /out/; \ \ elif [ "$TARGETOS" = "windows" ] && [ "$TARGETARCH" = "amd64" ]; then \ rustup target add x86_64-pc-windows-gnu; \ cargo build --release --target x86_64-pc-windows-gnu; \ mkdir -p /out; \ # Copy the compiled Windows DLL (supports both prefixed and non-prefixed outputs) \ cp target/x86_64-pc-windows-gnu/release/*.dll /out/tbr.dll; \ fi # ========================================================================= # Stage 2: Exporter Stage # ========================================================================= FROM scratch AS exporter ARG TARGETOS ARG TARGETARCH # Copies the binaries into cleanly structured, platform-named folders COPY --from=builder /out/ /