cargo-chef icon indicating copy to clipboard operation
cargo-chef copied to clipboard

Failure when cooking a workspace with local crates that are renamed

Open Veetaha opened this issue 2 years ago • 6 comments

Suppose we have a crate foo

name = "foo"
version = "0.1.2"

and we have a crate bar

name = "bar"
version = "0.1.2"

[dependencies]
foo2 = { path = "../foo", version = "^0.1.2", package = "foo" }

This project layout where a local crate depends on other local crate that is renamed doesn't work with the logic here: https://github.com/LukeMathWalker/cargo-chef/blob/30e5b862483790f13c337acacf2c60f6cde7ac43/src/skeleton/version_masking.rs#L3-L22

cargo chef replaces the versions of all local crates with 0.0.1, however it doesn't modify the version requirement in bar's [dependencies] for foo2, so cargo chef cook fails with

error: failed to select a version for the requirement `foo = "^0.1.2"`
candidate versions found which didn't match: 0.0.1

Veetaha avatar Oct 24 '21 22:10 Veetaha

Having read the implementation code of cargo chef more I also see that it doesn't handle replacing version requirements of crates in [target.'cfg(foo)'.*dependencies] sections, but that is just a separate issue and my not-yet-confirmed theory

cc @LukeMathWalker

Veetaha avatar Oct 25 '21 08:10 Veetaha

I agree - this is a bug.

LukeMathWalker avatar Oct 25 '21 08:10 LukeMathWalker

I am getting a similar error, but without having a path rewrite. It's a pretty simple dependency:

a2s = { version = "0.5.0", features = ["async"] }

which leads to

    Updating crates.io index
error: failed to select a version for the requirement `a2s = "^0.0.1"`
candidate versions found which didn't match: 0.5.0, 0.4.0, 0.3.1, ...
location searched: crates.io index

reitermarkus avatar Feb 05 '22 14:02 reitermarkus

What version of cargo-chef are you using @reitermarkus?

LukeMathWalker avatar Feb 06 '22 10:02 LukeMathWalker

I'm using 0.1.33, but it is working now it seems. I think my cargo install cargo-chef layer was cached locally with an older version since the same Dockerfile worked on CI.

reitermarkus avatar Feb 06 '22 20:02 reitermarkus

I got a similar error:

error: failed to select a version for the requirement `serde = "^0.0.1"`
candidate versions found which didn't match: 1.0.138, 1.0.137, 1.0.136, ...
location searched: crates.io index
required by package `habits-bot v0.0.1 (/)`
thread 'main' panicked at 'Exited with status code: 101', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cargo-chef-0.1.36/src/recipe.rs:148:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

However, after employing WORKDIR /app in Dockerfile, everything worked smoothly.

Hirrolot avatar Jul 03 '22 23:07 Hirrolot