【问题标题】:Workspace giving two different behaviors in Rust工作区在 Rust 中提供两种不同的行为
【发布时间】:2016-12-16 22:11:33
【问题描述】:

我正在学习 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 目录。我在上面workspacer 的Cargo.toml 的内联评论中提到了这一点(上面的第一个sn-p)。

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

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

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    在最新的稳定版上确认后:

    ~$ 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:

    工作空间的所有成员应该共享同一个目标目录 no 无所谓!

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

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 1970-01-01
      • 2011-05-28
      • 2019-11-01
      • 2023-01-29
      • 2020-09-08
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多