rust - Packing dependent crates without publishng - Stack Overflow

admin2025-04-29  2

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?

Share Improve this question asked Jan 6 at 22:24 Patrick HalliseyPatrick Hallisey 9436 silver badges12 bronze badges 4
  • I doubt it will work, but have you tried --no-verify? – PitaJ Commented Jan 6 at 22:38
  • 1 What is the goal behind packaging the second without publishing the first? – kmdreko Commented Jan 6 at 22:59
  • 1 @kmdreko, for separation of processes within the CI build. I would like to build, test and package (produce tarballs) of everything that will be shipped before shipping anything. I don't want to ship anything if there's a problem producing any of the packages. – Patrick Hallisey Commented Jan 6 at 23:45
  • @PitaJ, --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
Add a comment  | 

1 Answer 1

Reset to default 1

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.

转载请注明原文地址:http://anycun.com/QandA/1745941254a91425.html