简体   繁体   English

为什么货物构建缓存无效?

[英]Why is cargo build cache invalidating?

I have a barebones workspace project:我有一个准系统工作区项目:

.
├── build-debug.sh
├── Cargo.lock
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
├── rs-test.iml
├── server
│   ├── Cargo.toml
│   └── src
│       └── main.rs
└── wui
    ├── Cargo.toml
    └── src
        └── lib.rs

The rs files either empty or just an empty main function. rs 文件要么是空的,要么只是一个空的主函数。

The server and the wui depends on common: common = { path = "../common" } .服务器和 wui 依赖于 common: common = { path = "../common" }

The common project has one crates.io dependency with I suppose build script or proc macro dependency.通用项目有一个 crates.io 依赖项,我想是构建脚本或 proc 宏依赖项。

The build script:构建脚本:

cargo build -p wui --target wasm32-unknown-unknown
cargo build -p server

The problem:问题:

When I rebuild the unchanged project, some wui dependencies are getting invalidated/rebuilt, then the same for server.当我重建未更改的项目时,一些 wui 依赖项变得无效/重建,服务器也是如此。

Either:任何一个:

  • remove the wasm32 target flag删除 wasm32 目标标志
  • replace the dependency with a simple crate without build time compiled dependencies使用没有构建时编译依赖项的简单 crate 替换依赖项

It does not rebuild the subprojects anymore.它不再重建子项目。

Is this a cargo bug?这是货物错误吗? What can I do?我能做什么?

It's probably not a cargo bug.这可能不是货物错误。 What is likely happening here is that your crates.io dependency (you don't mention what it is, which might have been useful) has different dependencies or features depending on the target architecture.这里可能发生的情况是您的 crates.io 依赖项(您没有提及它是什么,这可能很有用)根据目标架构具有不同的依赖项或功能。 Thus, as you alternate between building the WASM target and your host target, stuff is being rebuilt.因此,当您在构建 WASM 目标和主机目标之间交替时,正在重建内容。

Perhaps it would be better in this case to stop using the Cargo workspace and build the server and wui separately;也许在这种情况下停止使用 Cargo 工作区并分别构建服务器和 wui 会更好; this way you'll have separate target directories for the server and wui, which takes some extra disk space and takes longer for non-incremental compilation, but will prevent you from having to rebuild that stuff all the time as you build both.通过这种方式,您将为服务器和 wui 拥有单独的target目录,这会占用一些额外的磁盘空间,并且非增量编译需要更长的时间,但会阻止您在构建两者时一直重建这些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Azure 构建管道中有效地缓存货物/Rust 项目 - How to effectively cache cargo/Rust projects in an Azure Build Pipeline 如何清除货物缓存? - How to clear the Cargo cache? 如果“货物建造”比直接运行rustc慢,为什么要使用Cargo? - Why should I use Cargo if “cargo build” is slower than running rustc directly? 为什么Rust会先用`cargo build --release`再加上`cargo run`再次编译我的项目? - Why does Rust compile my project again with `cargo build --release` followed by `cargo run`? 为什么 cargo build 不显示具有不兼容依赖项的编译错误? - Why is cargo build not showing compilation errors with incompatible dependencies? 为什么 cargo build 不能提供丰富多彩的错误信息? - Why cargo build can’t offer colorful error messages? 为什么此Rust 2018代码使用`cargo build`编译但不使用rustc编译? - Why does this Rust 2018 code compile with `cargo build` but not using rustc? 为什么`cargo build`没有在我的代码中显示所有错误? - Why does `cargo build` not show all errors in my code? 为什么运行 cargo bench 比运行 release build 快? - Why is running cargo bench faster than running release build? 为什么当构建失败时,货物构建的输出中包含不可读的字符? - Why does the output of cargo build contain unreadable characters when the build fails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM