Sign inSign up

jonoh/rust-crossbuild

By jonoh

Updated about 2 months ago

Rust build image for cross platform builds with buildx

Image
0

10K+

jonoh/rust-crossbuild repository overview

rust-crossbuild

A Rust image that includes cross-compilation toolchains, designed to work in conjunction with docker buildx.

It's faster than buildx with the vanilla Rust image because it configures cargo for cross-compilation, so builds run natively without qemu.

Usage

Prepare a Dockerfile, such as:

FROM --platform=$BUILDPLATFORM jonoh/rust-crossbuild AS builder
WORKDIR /usr/src/myapp
COPY . .
RUN cargo install --path .

FROM debian:buster-slim
RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/myapp /usr/local/bin/myapp
CMD ["myapp"]

It's important to include --platform=$BUILDPLATFORM in the FROM. These will ensure that the builder image is native to the system, while the output is native to the target system. The rest of the Dockerfile is up to you, the above is just an example.

Then use docker buildx for a cross-platform build. For example:

docker buildx build --platform linux/amd64,linux/arm64 -t myapp --push .

Platforms

Build platforms

  • linux/amd64
  • linux/arm64

Target platforms

  • linux/amd64
  • linux/arm64
  • linux/arm/v7

Tag summary

Content type

Image

Digest

sha256:12d6b8191

Size

886.7 MB

Last updated

about 2 months ago

docker pull jonoh/rust-crossbuild