当锁定锁定时,为什么货物构建忽略锁定文件?

发布于 2025-01-31 20:06:45 字数 362 浏览 4 评论 0 原文

我对货物构建的行为感到困惑当锁定文件之间发生更改时:

  1. 运行货物清洁
  2. 运行货物构建
  3. 将锁定文件更改为 在我的情况下,使用GIT的先前版本
  4. 现在使用Git Rerun 货物构建

,尽管 cargo.lock 在两种构建之间进行了更改, cargo not重建。它立即成功返回。这是为什么?我在做什么错或这是一个错误?

这些更改仅在依赖项中,而不在输出的主要二进制文件中。

我搜索了Rust论坛和问题,但找不到这种情况。

I'm confused about the behavior of cargo build when the lock file changes between builds:

  1. Run cargo clean
  2. Run cargo build
  3. Change the lock file to a previous version using git
  4. Now rerun cargo build

In my case, despite the Cargo.lock having changed between the two builds, cargo doesn't rebuild. It immediately returns successfully. Why is that? What am I doing wrong or is this a bug?

The changes are only in the dependencies, not in the main binaries that are output.

I searched the Rust forum and issues and couldn't find this case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2025-02-07 20:06:45

如果您使用单独的 cargo.lock 使用货物的 workspace功能。因此,如果您的项目看起来像这样:

.
├── Cargo.toml
├── cli
│   ├── Cargo.toml
│   └── src
│       └── main.rs
├── core
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
├── gui
│   ├── Cargo.toml
│   └── src
│       └── main.rs

根目录中只有一个 cargo.lock 文件。和子目录中的锁定文件将被忽略。从文档中:

一个工作空间是一组包裹,共享相同的货物,lock和lock
输出目录。

分辨率很简单。从板条箱中删除 cargo.lock 文件,然后将一个文件放在项目的根目录中。

This might happen if you use separate Cargo.lock files with Cargo's workspace feature. So if your project looks like this:

.
├── Cargo.toml
├── cli
│   ├── Cargo.toml
│   └── src
│       └── main.rs
├── core
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
├── gui
│   ├── Cargo.toml
│   └── src
│       └── main.rs

There will be only one Cargo.lock file within the root directory. And lock files in the sub directories will be ignored. From the docs:

A workspace is a set of packages that share the same Cargo.lock and
output directory.

The resolution is simple. Remove the Cargo.lock files from the crates and place one in the root directory of your project.

戴着白色围巾的女孩 2025-02-07 20:06:45

您必须使用 - 锁定 flag,从 docs

- 冷冻
- 锁定

这些标志中的任何一个都要求cargo.lock文件是最新的。如果丢失了锁定文件,或者需要更新,
货物将出错。 - 弗罗兹国旗也可以防止货物
从尝试访问网络以确定它是否是
过时。这些可能用于您想要的环境
断言cargo.lock文件是最新的(例如CI构建)或
想要避免访问网络。

You have to run with --locked flag, from the docs:

--frozen
--locked

Either of these flags requires that the Cargo.lock file is up-to-date. If the lock file is missing, or it needs to be updated,
Cargo will exit with an error. The --frozen flag also prevents Cargo
from attempting to access the network to determine if it is
out-of-date. These may be used in environments where you want to
assert that the Cargo.lock file is up-to-date (such as a CI build) or
want to avoid network access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文