LukeMathWalker / cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Apache License 2.0
1.72k stars 113 forks source link

Unable to use cargo-chef with old nightly and 2018 edition #239

Closed oren0e closed 1 year ago

oren0e commented 1 year ago

Hi, I am using rustc 1.56.0-nightly (0035d9dce 2021-08-16) with 2018 edition. I couldn't use the latest cargo-chef anymore so I fixed the version of it to the last one that used 2018 edition. This caused the same edition problem for cargo-manifest, so I've downgraded the cargo-chef version yet again to account for that (version 0.1.40), But of course the chain does not end there - I now receive an error about other dependencies it seems:

#9 [chef 4/5] RUN cargo install --version 0.1.40 cargo-chef
#9 0.522     Updating crates.io index
#9 197.2  Downloading crates ...
#9 198.9   Downloaded cargo-chef v0.1.40
#9 199.0   Installing cargo-chef v0.1.40
#9 199.6  Downloading crates ...
#9 200.2   Downloaded log v0.4.20
#9 200.2   Downloaded autocfg v1.1.0
#9 200.2   Downloaded quote v1.0.33
#9 200.2   Downloaded once_cell v1.17.2
#9 200.3 error: failed to compile `cargo-chef v0.1.40`, intermediate artifacts can be found at `/tmp/cargo-install9Bd0cM`
#9 200.3 
#9 200.3 Caused by:
#9 200.3   failed to parse manifest at `/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.17.2/Cargo.toml`
#9 200.3 
#9 200.3 Caused by:
#9 200.3   feature `edition2021` is required
#9 200.3 
#9 200.3   The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.56.0-nightly (b51[439](XXXXXXXXXX)fd8 2021-08-09)).
#9 200.3   Consider trying a more recent nightly release.
#9 200.3   See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.
#9 ERROR: process "/bin/sh -c cargo install --version 0.1.40 cargo-chef" did not complete successfully: exit code: 101
------
 > [chef 4/5] RUN cargo install --version 0.1.40 cargo-chef:
200.3 
200.3 Caused by:
200.3   failed to parse manifest at `/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.17.2/Cargo.toml`
200.3 
200.3 Caused by:
200.3   feature `edition2021` is required
200.3 
200.3   The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.56.0-nightly (b51439fd8 2021-08-09)).
200.3   Consider trying a more recent nightly release.
200.3   See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.
LukeMathWalker commented 1 year ago

I'm sorry, but this is not a supported usecase. We expect you to be using a ~recent version of Rust.

If you want to stick to an older version of cargo-chef, you probably want to use the --locked flag when installing.

oren0e commented 1 year ago

@LukeMathWalker Doesn't the project have an MSRV? In our company there are constraints that does not allow me to always use the latest Rust version, nor do I want to update everything every month.

LukeMathWalker commented 1 year ago

This project does not guarantee an MSRV—it isn't documented anywhere, as you can see from the README. Even if it did guarantee an MSRV, it still wouldn't work unless you pass --locked when issuing the cargo install command.

It's also worth noticing that the version of Rust you use to compile cargo-chef has nothing to do with the version of Rust you use to compile your own project. To list a few options:

oren0e commented 1 year ago

Thank you very much! I wasn't aware of some of these options. Using a pre-built docker actually sounds promising. Will try that out.

oren0e commented 1 month ago

@LukeMathWalker sorry for reviving this but could you please provide a small Dockerfile example for how can I use your pre-built docker image (with latest Rust version for example) from docker-hub to "cook" the recipe while using another image of older Rust to actually cargo build --release my project?

LukeMathWalker commented 4 weeks ago

how can I use your pre-built docker image (with latest Rust version for example) from docker-hub to "cook" the recipe while using another image of older Rust to actually cargo build --release my project?

You need to use the same version of Rust in both steps, otherwise there won't be any artifact sharing.

oren0e commented 4 weeks ago

This project does not guarantee an MSRV—it isn't documented anywhere, as you can see from the README. Even if it did guarantee an MSRV, it still wouldn't work unless you pass --locked when issuing the cargo install command.

It's also worth noticing that the version of Rust you use to compile cargo-chef has nothing to do with the version of Rust you use to compile your own project. To list a few options:

* you can compile `cargo-chef` in another Docker build stage and then copy the binary over into the stages used to build your application and its dependencies

* you can download a pre-built binary from our GitHub releases (and verify the checksum to ensure integrity)

* you can use our pre-built Docker images

@LukeMathWalker I thought this is what you meant here, or did I misunderstood?

LukeMathWalker commented 4 weeks ago

I think you misunderstood. What you use to compile cargo-chef doesn't matter, but the toolchains must match between building deps and building the project.