Open avsaase opened 1 year ago
The challenge is you're dealing with layers of calculations. We first look up a package and then the relevant command does what it wants with it. We also don't know what bins are in package unless we parse the manifest. So for this to fully work as requested, we'd need to cross layers and then load the manifests to resolve the ambiguity. We'd need the ambiguity resolution to be unambiguous to the user since (1) they might not be aware of details and (2) they can make mistakes.
Something I've considered is
If we could prioritize workspace members with a warning saying other options are available and still error when all else is equal, I think that might be good enough.
But why would cargo run
ever run a package from a dependency? I fail to see a use case for that.
I didn't say that part was ideal. I was more explaining why it is the way it is and the challenge with changing it to something else.
Hello, this is of interest also in the semver trick approach https://github.com/dtolnay/semver-trick to add compatibility code (e.g. for serialization) to an old version of a crate by depending on a more recent version of the crate and adding bridge/glue code in the old crate allowing users of the old crate to use a minor release to proceed with serialization format update for example.
a workaround seems to not specify the package at all, this is an issue if you have several crates with colliding binary/example names I guess
i.e. if you have unique names for binaries/examples you can
cargo run --release --bin my_bin
as long as my_bin has a unique name in the workspace it should be run ok, adding -p my_package when my_package is also a transitive dependency brings you back to the original issue where the name is ambiguous, but running with the spec is not accepted
This also occurs with cargo test -p foo
where your workspace has a crate called foo
and you also have a dependency called foo
(renamed to something else, of course).
Problem
Take a project directory structure like this:
Cargo.toml
:examples/grid/Cargo.toml
:Dependency tree:
When you try to run the
grid
example withcargo run --package grid
you get an error:Steps
cargo run --package grid
cargo run --package grid@0.1.0
Possible Solution(s)
The problem seems to be that cargo sees the transitive
grid
dependency oftaffy
and sees that as a conflict with the package of the same name in the local workspace. This must be a bug because there is no reason to run a binary target from a (transitive) dependency withcargo run
. And even if there was, thegrid
crate doesn't have a binary target so there's nothing to run.The solution suggested by cargo is also not correct because running
cargo run -p grid@0.1.0
gives the error that the package is not found in the workspace.A workaround is to use globally unique package names in workspaces but this is very restrictive because adding a dependency can easily create a new conflict.
Notes
No response
Version