When calling cargo package
in a monorepo with multiple packages, cargo will complain if a dependency doesn't exist on crates.io. This means that I can't update a dependency version and pack the consumer without first publishing the dependency.
For example, given 2 packages:
package_one/Cargo.toml
[package]
name = "package_one"
version = "0.1.0"
edition = "2021"
package_two/Cargo.toml
[package]
name = "package_two"
version = "0.1.0"
edition = "2021"
[dependencies]
package_one = { path = "../package_one", version = "0.1.0" }
calling cargo package
in /package_two returns:
> cargo package
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See .html#package-metadata for more info.
Packaging package_two v0.1.0 (C:\repo\package_two)
Updating crates.io index
error: failed to prepare local package for uploading
Caused by:
no matching package named `package_one` found
location searched: registry `crates-io`
required by package `package_two v0.1.0 (C:\repo\package_two)`
A similar issue occurs when the dependency version is changed in the same build that produces the dependency, e.g. I update package_one to 0.2.0 and try to package package_two without publishing package_one first.
> cargo package
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See .html#package-metadata for more info.
Packaging package_two v0.1.0 (C:\repo\package_two)
Updating crates.io index
error: failed to prepare local package for uploading
Caused by:
failed to select a version for the requirement `package_one = "^0.2.0"`
candidate versions found which didn't match: 0.1.0
location searched: crates.io index
required by package `package_two v0.1.0 (C:\repo\package_two)`
How can I build and package package_two using package_one from disk without having to publish package_one first?
When calling cargo package
in a monorepo with multiple packages, cargo will complain if a dependency doesn't exist on crates.io. This means that I can't update a dependency version and pack the consumer without first publishing the dependency.
For example, given 2 packages:
package_one/Cargo.toml
[package]
name = "package_one"
version = "0.1.0"
edition = "2021"
package_two/Cargo.toml
[package]
name = "package_two"
version = "0.1.0"
edition = "2021"
[dependencies]
package_one = { path = "../package_one", version = "0.1.0" }
calling cargo package
in /package_two returns:
> cargo package
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 package_two v0.1.0 (C:\repo\package_two)
Updating crates.io index
error: failed to prepare local package for uploading
Caused by:
no matching package named `package_one` found
location searched: registry `crates-io`
required by package `package_two v0.1.0 (C:\repo\package_two)`
A similar issue occurs when the dependency version is changed in the same build that produces the dependency, e.g. I update package_one to 0.2.0 and try to package package_two without publishing package_one first.
> cargo package
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 package_two v0.1.0 (C:\repo\package_two)
Updating crates.io index
error: failed to prepare local package for uploading
Caused by:
failed to select a version for the requirement `package_one = "^0.2.0"`
candidate versions found which didn't match: 0.1.0
location searched: crates.io index
required by package `package_two v0.1.0 (C:\repo\package_two)`
How can I build and package package_two using package_one from disk without having to publish package_one first?
If your packages are all in the same workspace, you can use the unstable package-workspace
Cargo option to enable packaging and/or publishing of workspace packages without having to publish their workspace dependencies:
# Package entire workspace
cargo +nightly -Zpackage-workspace package --workspace
# Package individual crates in workspace
cargo +nightly -Zpackage-workspace package -p foo -p dep
# Package crate in current working directory
cargo +nightly -Zpackage-workspace package
The option is only available in nightly Cargo builds, and requires that your packages must not have publishing disabled (i.e. package.publish
set to false
). In other words, you cannot use this feature to package crates that depend on unpublished crates in your workspace.
--no-verify
? – PitaJ Commented Jan 6 at 22:38--no-verify
may have prevented the validation build, but it didn't stop cargo from complaining about the missing dependency. – Patrick Hallisey Commented Jan 6 at 23:48