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

Workspace giving two different behaviors in Rust

我正在学习 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 并构建,它会在顶层 workspacer/ 中创建一个 target/ 文件夹和 Cargo.lock 个文件,这很好。

如果我转到 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!

一个bug report was submitted,现在解决了