Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document how to run cross #42

Closed
glehmann opened this issue Feb 5, 2024 · 6 comments · Fixed by #47
Closed

document how to run cross #42

glehmann opened this issue Feb 5, 2024 · 6 comments · Fixed by #47

Comments

@glehmann
Copy link

glehmann commented Feb 5, 2024

I've seen cross mentioned in the documentation, so I thought it could be easy to run it. Not that much so far :-)

Here is what I tried to do:

VERSION --global-cache 0.7
IMPORT github.com/earthly/lib/rust AS rust

rust:
    FROM rust:alpine
    RUN apk add --no-cache musl-dev findutils
    DO rust+INIT --keep_fingerprints=true

cross:
    FROM +rust
    DO rust+CARGO --args="install cross"
    RUN apk add docker jq
    ARG --required target
    DO rust+SET_CACHE_MOUNTS_ENV
    COPY --keep-ts . ./
    WITH DOCKER
        RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE \
            --mount=$EARTHLY_RUST_TARGET_CACHE \
            cross build --target $target --release
    END
    DO rust+COPY_OUTPUT --output="[^\./]+/release/[^\./]+"

but cross fails with this error:

              +cross | build=cross target=i686-unknown-linux-musl
              +cross | --> WITH DOCKER RUN --privileged cross build --target $target --release
              +cross | Starting dockerd with data root /var/earthly/dind/f93b09b85d482e3c2c2a9ba24dac0885b16ada45cadeaaa5667074ec0e54ffda/tmp.HMgOjE
              +cross | error: DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain as the default.
              +cross | warning: toolchain '1.75.0-x86_64-unknown-linux-gnu' may not be able to run on this system.
              +cross | warning: If you meant to build software to target that platform, perhaps try `rustup target add x86_64-unknown-linux-gnu` instead?
              +cross | info: syncing channel updates for '1.75.0-x86_64-unknown-linux-gnu'
              +cross | info: latest update on 2023-12-28, rust version 1.75.0 (82e1608df 2023-12-21)
              +cross | info: downloading component 'cargo'
              +cross | info: downloading component 'rust-std'
              +cross | info: downloading component 'rustc'
              +cross | info: installing component 'cargo'
              +cross | info: installing component 'rust-std'
              +cross | info: installing component 'rustc'

              +cross |   1.75.0-x86_64-unknown-linux-gnu installed - (error reading rustc version)

              +cross | error: rustup is not installed at '/tmp/earthly/.cargo'
              +cross | Error: 
              +cross |    0: couldn't install toolchain `1.75.0-x86_64-unknown-linux-gnu`
              +cross |    1: `rustup toolchain add 1.75.0-x86_64-unknown-linux-gnu --profile minimal` failed with exit status: 1
              +cross | earthly debugger | Command /bin/sh -c 'cross build --target $target --release' failed with exit code 1
$ earthly --version
earthly version v0.8.3 70916968c9b1cbc764c4a4d4d137eb9921e97a1f linux/amd64; Ubuntu 23.10 (Mantic Minotaur)

Is there a example with cross available somewhere?

@glehmann
Copy link
Author

glehmann commented Feb 5, 2024

hey @joepio , I see in #34 that your using cross and earthly with much more success than I do. Would you have a configuration that you could share as an example, or a link to the Earthfile of your project if the sources are public?

@joepio
Copy link

joepio commented Feb 5, 2024

@glehmann
Copy link
Author

glehmann commented Feb 6, 2024

@joepio thanks a lot, I've been able to make it work with your example :-)

for the reference, the problem disappeared when I switched from the alpine to the slim (debian) variant of the rust image.

That was not all though, I had to clean the target/release directory before each run — somehow some stuff generated during the build was making the next builds fail: https://github.com/glehmann/yage/blob/8446fe3722fb782e6f0aa2b8dfcbd3d00617e3bc/Earthfile#L43

Also I found quite useful to:

that's my take on using cross and earthly together. I hope it will be useful for others :-)

@idelvall
Copy link
Member

Hi guys, thanks for pushing on this!
I will go through your examples and update the documentation accordingly

@idelvall
Copy link
Member

idelvall commented Feb 13, 2024

Hi guys, I was able to improve a little @glehmann solution. This is what I did:

  • Make the target mount cache ID depends on $TARGETPLATFORM. Add target cache suffix #45
  • Now, the cleaning of the target folder is not needed, the builds run in parallel and crate compilation is cached

It's taking more time than expected for me to ship this though the library in a clean way and without losing parallelization, but I didn't want to hold it any longer.

Please let me know your thoughts!

@idelvall idelvall mentioned this issue Feb 14, 2024
idelvall added a commit that referenced this issue Feb 14, 2024
@glehmann
Copy link
Author

rust+CROSS works great, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants