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)
- Checkout to 54df3c7dd914a529b4efda61b1efcc10dbde52cc
- Bump cargo-test-support to an unpublished version such as
99.99.99 cargo +1.83.0 package -p cargo-test-support --no-verify— succeededcargo +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.
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
- fix: temporary deactivate dry run 'mithril-client' crate publish In CI and Pre-release workflows. This is due to a change of bahavior in cargo since version See https://github.com/rust-lang/cargo/is... — committed to input-output-hk/mithril by jpraynaud 2 years ago
- feat(package): add --exclude-lockfile flag (#15234) ### What does this PR try to resolve? Fixes #15059 Fixes #15159 This provides an escape hatch `--exclude-lockfile`for uncommon workflows that don... — committed to rust-lang/cargo by epage 2 years ago
ok, that seems to work now for me using the
+nightlychannel.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 doingcargo package --no-verifycares 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-workspacemight 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.