cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.21k stars 354 forks source link

Provide images with rustup / cargo installed #1516

Open Emilgardis opened 2 weeks ago

Emilgardis commented 2 weeks ago

We can, before https://github.com/cross-rs/cross/blob/19be83481fd3e50ea103d800d72e0f8eddb1c90c/.github/workflows/ci.yml#L242 also tag and publish an image which has rustup installed, this would help the use case of just wanting an image with cross-compilation tools + rust installed.

related to #1187

randomairborne commented 2 weeks ago

A significant problem with this might be the creation of an excessive number of new dockerfiles. Then again, maybe it could be done programatically somehow.

randomairborne commented 2 weeks ago

How does:

FROM ghcr.io/cross-rs/{{TARGET}}:latest

ENV PATH="/root/.cargo/bin:$PATH"

RUN curl -fsSL https://sh.rustup.rs | bash -s -- -y --profile minimal
RUN rustup target add {{TARGET}}

look? This could probably be used to generate the required dockerfiles.

Emilgardis commented 2 weeks ago

No, I don't see why we'd need to generate a bunch of dockerfiles. Instead we could just use a build-arg approach.

# Dockerfile.cross-with-cargo
ARG CROSS_IMAGE
ARG TARGET
FROM CROSS_IMAGE
ENV PATH="/root/.cargo/bin:$PATH"
RUN curl -fsSL https://sh.rustup.rs/ | bash -s -- -y --profile minimal
RUN rustup target add $TARGET

and then invoke it like docker buildx build -f Dockerfile.cross-with-cargo --build-arg CROSS_IMAGE="<image>" --build-arg TARGET="<target>"

hcl would probably be the best solution coupled with https://github.com/cross-rs/cross/pull/849 however

randomairborne commented 2 weeks ago

That was what my comment originally was, and is what I'm currently using for cross-cargo. I just laser-focused on that for some reason LOL! Is there already a list of supported targets that could be read from to generate the ARGs?

Emilgardis commented 2 weeks ago

All targets built with ci lives in https://github.com/cross-rs/cross/blob/main/targets.toml, and if integrated in this repos CI the target name would already exist in ${{ matrix.target }}

Emilgardis commented 2 weeks ago

or here also: https://github.com/cross-rs/cross/blob/main/src/docker/provided_images.rs

Oh, there's also a unmerged pr to make cross-util give the list: https://github.com/cross-rs/cross/pull/1240