我对货物构建的行为感到困惑
当锁定文件之间发生更改时:
- 运行
货物清洁
- 运行
货物构建
- 将锁定文件更改为 在我的情况下,使用GIT的先前版本
- 现在使用Git Rerun
货物构建
,尽管 cargo.lock
在两种构建之间进行了更改, cargo
not重建。它立即成功返回。这是为什么?我在做什么错或这是一个错误?
这些更改仅在依赖项中,而不在输出的主要二进制文件中。
我搜索了Rust论坛和问题,但找不到这种情况。
I'm confused about the behavior of cargo build
when the lock file changes between builds:
- Run
cargo clean
- Run
cargo build
- Change the lock file to a previous version using git
- 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.
发布评论
评论(2)
如果您使用单独的
cargo.lock
使用货物的 workspace功能。因此,如果您的项目看起来像这样:根目录中只有一个
cargo.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: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:The resolution is simple. Remove the
Cargo.lock
files from the crates and place one in the root directory of your project.您必须使用
- 锁定
flag,从 docs :You have to run with
--locked
flag, from the docs: