Cargo Workspace Behavior Change
There is a change in the way cargo workspaces handle dependencies between 1.50 and 1.51.
Before 1.51, attempting to build a dependency with --package fails if it is not a workspace member.
After 1.51 this becomes possible.
Workspace Description
notwsis a directory that contains one library package nameddep_1.wsis a directory that contains a workspace-onlyCargo.tomlfile and a package that is a member of the workspace,ws_member_1.ws_member_1hasdep_1as a dependency usingpath.
โโโ notws
โ โโโ dep_1
โ โโโ Cargo.toml
โ โโโ src
โ โโโ lib.rs
โโโ ws
โโโ Cargo.lock
โโโ Cargo.toml
โโโ ws_member_1
โโโ Cargo.toml
โโโ src
โโโ main.rs
Repro
If I try to build dep_1 from the workspace context with 1.50, it fails to find the package.
This seems reasonable given that dep_1 is a dependency, but not a workspace member.
rustup default 1.50.0
cargo build --manifest-path ./ws/Cargo.toml --package dep_1
# error: package ID specification `dep_1` matched no packages
This works with 1.51.0:
rustup default 1.51.0
cargo build --manifest-path ./ws/Cargo.toml --package dep_1
Question
Is this behavior change intended?
Can I rely on this behavior in my build?
Here is the repo: GitHub - webern/cargo-workspace-1.51: Demonstrates a change to workspace behavior in 1.51 that I have a question about.
Kind of a wild stab, but maybe it was this Add suggestion for bad package id. by ehuss ยท Pull Request #9095 ยท rust-lang/cargo ยท GitHub and thus @ehuss would know?
The Files
ws/Cargo.toml:
[workspace]
members = [
"ws_member_1",
]
ws/ws_member_1/Cargo.toml:
[package]
name = "ws_member_1"
version = "0.1.0"
edition = "2018"
[dependencies]
dep_1 = { path = "../../notws/dep_1" }
notws/dep_1/Cargo.toml:
[package]
name = "dep_1"
version = "0.1.0"
edition = "2018"