- Run
cargo new hello
to create and example program. - Add
Dockerfile
andbuildx.sh
from this gist. - Run
./buildx.sh
. - Complied program will be put into
./release/hello
. Copy it to a x86-64 Linux machine and try to run.
Created
August 11, 2024 15:15
-
-
Save feymartynov/554e96a1baa9f43ffc0405d238451891 to your computer and use it in GitHub Desktop.
Rust program cross build from Mac M1 -> Linux amd64 using Docker for Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
docker buildx build --platform=linux/amd64 -t hello:amd64 --output . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:bookworm AS build | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
pkg-config \ | |
curl \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.80.0 | |
ENV PATH /root/.cargo/bin:$PATH | |
COPY . /app | |
WORKDIR /app | |
RUN cargo build --release | |
############################################################################### | |
FROM scratch | |
COPY --from=build /app/target/release/hello /release/hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment