Working with workspace-inheritance
Hello, and thanks for your work on cargo-chef
I tried experimenting with the new (unstable, 1.64) feature of workspace-inheritance and faced the following issue.
With 2 members in the workspace, inheriting some common dependencies, and defining their own. (very close to the doc above)
And got the following error (docker build):
> [planner 2/2] RUN cargo +nightly chef prepare --recipe-path recipe.json:
#14 0.270 Error: Failed to compute recipe
#14 0.270
#14 0.270 Caused by:
#14 0.270 0: invalid type: map, expected a string for key `package.version` at line 3 column 21
#14 0.270 1: invalid type: map, expected a string for key `package.version` at line 3 column 21
package.version being defined as in the docs as: version.workspace = true.
The Dockerfile I'm using to build is here and the overall WIP I'm working on is there.
Let me know if I can do something to help you
Hey!
This won't work because cargo-manifest (used by cargo-chef) doesn't know how to parse the manifests using the new unstable feature.
I'm afraid I am not open to PRs on this until the feature stabilises and lands in beta - I don't want to keep up with nightly breakage.
@LukeMathWalker The feature is stabilized and it's already on current beta (1.64) documentation.
Note there are two ways to use it: cc.workspace = true and regex = { workspace = true, features = ["unicode"] }
The first one crashes and the second one doesn't crash but neither take into account the version and the cache doesn't work as expected.
Oh, that's great! I'll prepare a patch then!
If you run cargo-upgrade to pull in the latest version of cargo-manifest it should work 👍🏻
Nice! Thank you.
Any idea where I should include the cargo-upgrade here:
FROM rustlang/rust:nightly-bullseye-slim as chef
RUN cargo +nightly install cargo-chef --locked
WORKDIR app
FROM chef AS planner
COPY . .
RUN cargo +nightly chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN apt update
RUN apt install -y cmake
RUN apt install -y libssl-dev
RUN cargo +nightly chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo +nightly build --all --release
FROM debian:bullseye-slim AS runtime
WORKDIR app
RUN apt update
RUN apt install -y libssl1.1 openssl ca-certificates
COPY --from=builder /app/target/release/buska-cli /usr/local/bin
ENTRYPOINT ["/usr/local/bin/buska-cli"]
Or maybe I should just get rid of some cached docker layer?
'Cause I gave it a try and got the same error, but that must be because I didn't catch the latest cargo-manifest version.
Sorry, I actually need to run it on this repository to upgrade the contents of our Cargo.lock.
I'll do it once I get to my machine.
No problem at all. There's no urgency, I just wanted to give this new feature a try and figured out it could be interesting for you to know cargo-chef wasn't compatible, yet.
Tell me if you want me to give it a try, or if I can help you with anything.
Thanks again for your work on cargo-chef!!
Done - the change should have been released with 0.1.40 😁
I can confirm it is working now as expected! Thanks 😀
I've only tried this style: regex = { workspace = true, features = ["unicode"] }, so I can't confirm about cc.workspace = true.
I'm sorry I must still be missing something:
❯ cargo +nightly chef --version
cargo-chef 0.1.40
=>
❯ cargo +nightly chef prepare --recipe-path /tmp/recipe.json
Error: Failed to compute recipe
Caused by:
0: invalid type: map, expected a string for key `package.version` at line 3 column 21
1: invalid type: map, expected a string for key `package.version` at line 3 column 21
Notes:
- I'm not using the Dockerfile shown above, just using a fresh install of
cargo-cheflocally on my machine - using the
cc.workspace = truesyntax
Can you share your Cargo.toml? @aesteve
Everything is on this branch: https://github.com/aesteve/buska/blob/feat/upgrades/Cargo.toml
Ok, the issue is related to this line: https://github.com/aesteve/buska/blob/33414b1c1c0ea15d2f42ac29476129352af0edf4/cli/Cargo.toml#L3
It will take a bit more work to sort this one out I think, based on how cargo-chef works.
Basically, we only support inheritance for dependencies at the moment; not yet for other fields under package.
Also filed an issue here: https://gitlab.com/crates.rs/cargo_toml/-/issues/18, as it seems cargo-chef uses a fork of this crate.
I have implemented the missing pieces in 0.1.43/0.1.44. I can confirm that your branch builds correctly @aesteve 👌🏻
We should have everything needed to support the inheritance features stabilised in Rust 1.64.0 🎉