gpt4 book ai didi

rust - 工作区在 Rust 中提供两种不同的行为

转载 作者:行者123 更新时间:2023-11-29 08:08:43 24 4
gpt4 key购买 nike

我正在学习 Cargo 工作区并设置了以下结构:

顶级:

[package]
name = "workspacer"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]

[workspace]
members = ["safe_core", "safe_authenticator", "safe_app"]

# If this is removed then each of the sub-projects will have thier own Cargo.lock file
# will build binaries/objects in their own target/ directories. With this present, it's
# always the parent-projects Cargo.lock and target/ directory used. Need to check if this
# is standard behaviour or some bug about to be fixed.
[lib]
crate_type = ["rlib", "cdylib", "staticlib"]

一个名为 safe_core 的库,它只需要生成一个 .rlib

[package]
authors = ["ustulation <zzzzzz@gmail.com>"]
name = "safe_core"
version = "0.1.0"

[dependencies]
maidsafe_utilities = "~0.10.0"

一个名为 safe_app 的库依赖于 safe_core 并且需要生成所有 3 个 .rlib.a.so:

[package]
name = "safe_app"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]

[dependencies]
maidsafe_utilities = "~0.10.0"
safe_core = { path = "../safe_core" }

[lib]
crate_type = ["rlib", "cdylib", "staticlib"]

一个名为 safe_authenticator 的库依赖于 safe_core 并且需要生成所有 3 个 .rlib.a.so:

[package]
name = "safe_authenticator"
version = "0.1.0"
authors = ["ustulation <zzzzzz@gmail.com>"]

[dependencies]
safe_core = { path = "../safe_core" }

[lib]
crate_type = ["rlib", "cdylib", "staticlib"]

这棵树看起来像:

workspacer
├── Cargo.toml
├── safe_app
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
├── safe_authenticator
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
└── safe_core
├── Cargo.toml
└── src
└── lib.rs

如果我转到 safe_core 并构建,它会在顶层 中创建一个 target/ 文件夹和 Cargo.lock 文件workspacer/,这很好。

如果我转到 safe_authenticator 文件夹并构建它,它也使用相同的 target/Cargo.lock 文件,因此不会重新编译safe_core 这也是我想要的。与 safe_app 相同。

但是,如果我从顶级 workspacer/Cargo.toml 中删除 [lib] 部分,每个子项目都会开始创建自己的 Cargo.lock 文件及其各自子目录中的 /target 目录。我已经在上面 workspacerCargo.toml 的内联注释中提到了这一点(上面的第一个片段)。

这是预期的行为还是错误,还是我做错了什么?

~$ rustc --version && cargo --version
rustc 1.15.0-nightly (ba872f270 2016-11-17)
cargo 0.15.0-nightly (1877f59 2016-11-16)

最佳答案

在最新稳定版上确认后:

~$ rustc --version && cargo --version
rustc 1.13.0 (2c6933acc 2016-11-07)
cargo 0.13.0-nightly (eca9e15 2016-11-01)

seems to be a bug :

All members of workspace should share the same target directory no matter what!

A bug report was submitted ,现在已经解决了。

关于rust - 工作区在 Rust 中提供两种不同的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41150495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com