`cargo publish` cannot find workspace dependency


I've a project named foo in the path foo.
And foo/Cargo.toml is a virtual manifest with the following

members = [ "foo", "foo-lib" ]

foo is a binary package with the manifest foo/foo/Cargo.toml

name = "foo"
version = "0.1.0"
authors = ["XXXX <YYY>"]
edition = "2018"

foo-lib = { path = "../foo-lib", version = "0.1.0" }

while foo-lib is a library package with foo/foo-lib/Cargo.toml

name = "foo"
version = "0.1.0"
authors = ["XXXX <YYY>"]
edition = "2018"


Of course above is the simplification. In the real world project I'm working on, I'm able to compile each member crate, and also run cargo test on them.

How ever, I've issue with cargo publish

When at workspace root foo

cargo publish --dry-run --allow-dirty --manifest-path foo/Cargo.toml

would report

𝛌> cargo publish --manifest-path foo/Cargo.toml --dry-run --allow-dirty
    Updating crates.io index
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
   Packaging foo v0.1.0 (/tmp/foo/foo)
error: failed to prepare local package for uploading

Caused by:
  no matching package named `foo-lib` found
  location searched: registry `https://github.com/rust-lang/crates.io-index`
  required by package `foo v0.1.0 (/tmp/foo/foo)`

but I'm able to run

cargo publish --dry-run --allow-dirty --manifest-path foo-lib/Cargo.toml

So, could anyone please explain, why I'm able to compile and build all member crates, but I failed on cargo publish?

crates.io requires that all dependencies are also available on crates.io
Because you didn’t publish foo-lib yet, you can’t publish foo itself.



This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.