在不发布的情况下打包依赖包

问题描述 投票:0回答:1

在包含多个包的 monorepo 中调用

cargo package
时,如果 crates.io 上不存在依赖项,cargo 会抱怨。 这意味着如果不先发布依赖项,我就无法更新依赖项版本并打包使用者。

例如,给定 2 个包:

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" }

在 /package_two 中调用

cargo package
返回:

> 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)`

当在生成依赖项的同一构建中更改依赖项版本时,会出现类似的问题,例如我将 package_one 更新为 0.2.0 并尝试打包 package_two 而无需先发布 package_one。

> 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)`

如何使用磁盘上的 package_one 构建和打包 package_two,而无需先发布 package_one?

rust
1个回答
0
投票

如果您的包都在同一个工作区中,您可以使用不稳定的

package-workspace
Cargo 选项来启用同时打包和/或发布多个工作区包:

# Package entire workspace
cargo +nightly -Zpackage-workspace package --workspace
# Package individual crates
cargo +nightly -Zpackage-workspace package -p foo -p dep

该选项仅在夜间 Cargo 构建中可用,并且要求您的包不得禁用发布(即

package.publish
设置为
false
)。换句话说,您无法使用此功能来打包依赖于工作区中未发布的 crate 的 crate。

© www.soinside.com 2019 - 2024. All rights reserved.