cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Confusing error when publishing a package with a path dependency without a version requirement

Open andrewdavidmackenzie opened this issue 6 months ago • 3 comments

Problem

I used to use a cargo plugin to publish an entire workspace to crates.io, but now just tried the (unstable) built-in functionality with:

cargo +nightly publish -Z package-workspace --workspace

But I get this error reported:

error: all dependencies must have a version specified when publishing.
dependency `pigdef` does not specify a version
Note: The published dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.

The crate mentioned (pigdef) inherits the version from the workspace:

[package]
name = "pigdef"
description = "Core struct and const definitions for multiple crates in the pigg project"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
documentation.workspace = true
repository.workspace = true
homepage.workspace = true
readme.workspace = true
exclude.workspace = true
rust-version.workspace = true

My repo is here: https://github.com/andrewdavidmackenzie/pigg

Workspace members inheriting the package version from the workspace Cargo.toml seems fairly common practice, and so it would be great to have it working with cargo publish --workspace

Steps

  • Have a workspace repo with one or more members
  • Have the members inherit the package version from the workspace (rust-version.workspace = true)
  • Try to publish the workspace by running
cargo +nightly publish -Z package-workspace --workspace

Possible Solution(s)

No response

Notes

No response

Version

cargo version is 1.87.0 cargo nightly is...

cargo +nightly --version
cargo 1.89.0-nightly (68db37499 2025-05-22)

(so a week old, and seems to be the latest?)

andrewdavidmackenzie avatar May 29 '25 08:05 andrewdavidmackenzie

I think I'm reading the error message wrong - it's the fact that the dependency on that package is a relative path ("../pigdef") and is not specifying a version..... not that the dependency doesn't have a version!

Maybe the error message could be worded to be more clear and maybe provide a source file (Cargo.toml) link with line and char where the dependency without a version was found?

andrewdavidmackenzie avatar May 29 '25 13:05 andrewdavidmackenzie

That is a good suggestion! The function checking it resides here. I think we can either expand the error message, or add an extra error context such as “failed to verify manifest at foo/Cargo.toml”, something like

https://github.com/rust-lang/cargo/blob/bffece899e9ba3cf948c9498713ba7fbc4ec10e4/tests/testsuite/rename_deps.rs?plain=1#L376-L381

@rustbot label +S-accepted +A-diagnostics +Command-package +Command-publish -S-triage

weihanglo avatar May 29 '25 14:05 weihanglo

A very subtle change that could help clarify this is to say "version requirement"

error: all dependencies must have a version requirement specified when publishing.
dependency `pigdef` does not specify a version requirement
Note: The published dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.

But yes, we should also name the manifest in question. As we roll out more annotate snippets usage in our errors, we could even highlight the section in the file.

epage avatar May 29 '25 14:05 epage

Thanks for this!

andrewdavidmackenzie avatar Jun 26 '25 12:06 andrewdavidmackenzie