Closed LuckyTurtleDev closed 8 months ago
I'm not sure I understand this feature request, I understand the spirit, but not how it would be used.
Could you explain a bit further how this would be done and used?
I'll also explain abit, today it's possible to do
[target.armv7-unknown-linux-musl.image]
name = "ghcr.io/rust-cross/rust-musl-cross"
toolchain = ["linux/arm/v7=armv7-unknown-linux-musl"]
side note, I don't think musl-linux
is a valid docker/oci os platform
I should clearyfi this more.
I do want use the docker image, used by cross inside the From
step of a Dockerfile for building a rust program.
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:aarch64-unknown-linux-musl AS builder
SHELL ["/bin/bash", "-uo", "pipefail", "-c"]
ARG version
RUN apt-get -y update && apt-get -y install protobuf-compiler musl musl-dev musl-tools
ENV PROTOC=/usr/bin/protoc
RUN echo "build version ${version}"
RUN cargo install --locked --git https://github.com/ankitects/anki.git --tag ${version} anki-sync-server
RUN ldd /usr/local/cargo/bin/anki-sync-server
FROM --platform=$BUILDPLATFORM scratch
ENV SYNC_BASE=/data
COPY --from=builder --chmod=0755 /usr/local/cargo/bin/anki-sync-server /
CMD ["./anki-sync-server"]
So I do not use the cross binary, which mean I can not use the meta data section of the cargo.toml.
The problem is that I must change the target in the from step, which make it difficult, to build multi platform image.
Docker does provide the option to use docker Args here. Which are created by buildx.
So you can modifiy the From
step like this:
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:$TARGETPLATFORM AS builder
The problem is that TARGETPLATFORM
platform does not match the name of the rust toolchain. Instead it has values like linux/amd64
, linux/arm64
, linux/arm/v7
. Sadly docker does not allow to use a function here, also variables for previous build steps can not be used, so they is currently no way to map this values to the required toolchain.
My suggestion is to add additional linux/amd64
, linux/arm64
, linux/arm/v7
, etc tags, so TARGETPLATFORM
platform can be used directly.
aha! I think then that you're on the wrong issue tracker, this is cross-rs
, for the cross
binary that uses it's own docker images and produces binaries on the host system via cross build --target <target>
you probably want to raise this on https://github.com/rust-cross/rust-musl-cross instead! :D
Ups sorry for this.
Issue moved to https://github.com/rust-cross/rust-musl-cross/issues/133
Checklist
Describe your request
Since buildx exist out of docker image it would ideal to be used in the Docker
From
step inside a builder, to build mutliplatform images. For this you must choose an different image tag for each platform. Docker/Buildx allows you to use environments variables likeTARGETPLATFORM
inside the from step. The problem is that docker does not allow to use function here. So there is no way to mapTARGETPLATFORM
to the needed rust tool chain.Adding additional tags like
musl-linux/arm64
,musl-linux/arm/v7
", etc would allow to use it as builder:Describe why this would be a good inclusion for
cross
It allows to use cross to build multiplatforms docker images without using DiD. Hit this issue at https://github.com/ankitects/anki/pull/2798, so currently only linux/amd64 is supported.
Maybe an solution for https://github.com/cross-rs/cross/issues/1104