cargo: `cargo package --no-verify` fails if a package's version req is too high for the registry (but works locally)

Problem

#13447 dd698ff0483bda065d1f78968e70ee86fb116a72 has some unintentional consequences:

cargo package after that generates a lockfile also when packaging libraries. However, if the crate being packaged depends on some unpublished dependencies. When generating the lockfile Cargo then can’t find unpublished deps on registry index, so it bailed out.

Steps

This could be simplly reproduced in rust-lang/cargo as of today (2025-01-13)

  1. Checkout to 54df3c7dd914a529b4efda61b1efcc10dbde52cc
  2. Bump cargo-test-support to an unpublished version such as 99.99.99
  3. cargo +1.83.0 package -p cargo-test-support --no-verify — succeeded
  4. cargo +1.84.0 package -p cargo-test-support --no-verify — failed

Possible Solution(s)

Assume if we have passed the local registry unconditionally, we shouldn’t have the issue today.

https://github.com/rust-lang/cargo/blob/f15df8fd4990f1b87734343c4e44f3adec3c8b00/src/cargo/ops/cargo_package/mod.rs?plain=1#L219-L225

Version

  • cargo 1.84.0 (66221abde 2024-11-19)
  • cargo 1.86.0-nightly (088d49608 2025-01-10)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 35 (24 by maintainers)

Commits related to this issue

Most upvoted comments

ok, that seems to work now for me using the +nightly channel.

One question continues popping up: why it wasn’t a problem for [[bin]] until cargo started generating lockfile for [lib].

Here is my answer:

A lot of packages on crates.io and in the wild are lib only crates. People learn to use Cargo workspaces to separate bins from lib packages for a better dependency management (you can’t have bin-only dependency in one package). So [[bin]] is less a problem, but it still a problem. People could work around it, like removing [[bin]] from Cargo.toml if there is no interest. And most packagers doing cargo package --no-verify cares more about libraries. If it were for binaries usually they just build them won’t “package” the source.


I think upon this moment, as -Zpackage-workspace might not fit every need here, especially for packaging circular dev-dependencies, I would personally favor the proposal in https://github.com/rust-lang/cargo/issues/15159.

That seems like a very limited workflow as it only worked if the crates had no [[bin]]s and no [[example]]s in them. Once you add one, it failed.