【发布时间】:2018-02-09 06:17:40
【问题描述】:
具有以下目录结构:
tree hello_dep
.
├── Cargo.lock
├── Cargo.toml
├── dep_a
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── dep_b
│ ├── Cargo.toml
│ └── src
│ └── main.rs
└── src
└── main.rs
还有如下依赖链:hello_dep -> dep_a -> dep_b -> (optional feature) rustc-serialize,
我想在 dep_a 中创建一个功能,重新导出 dep_b 中的可选 rustc-serialize 功能。
在底部,我有 dep_b,它具有 rustc-serialize 作为可选的默认功能:
# dep_b/Cargo.toml
[package]
name = "dep_b"
version = "0.1.0"
[dependencies]
rustc-serialize = { version = "0.3.19", optional = true }
[features]
default = ["rustc-serialize"]
我想在 dep_a 中创建一个功能,以选择性地重新导出“rustc-serialize”。这是尝试:
# dep_a/Cargo.toml
[package]
name = "dep_a"
version = "0.1.0"
[dependencies]
dep_b = { version = "0.1.0", path = "../dep_b" }
[features]
rustc-serialize = ["dep_b/rustc-serialize"]
default = ["rustc-serialize"]
但是,当我尝试使用以下 Cargo.toml 将其添加为默认关闭的依赖项时:
# hello_dep/Cargo.toml
[package]
name = "hello_dep"
version = "0.1.0"
[dependencies]
dep_a = { version = "0.1.0", path = "dep_a", default-features = false, optional = true }
cargo build 仍然在 Cargo.lock 中产生 rustc-serialize。但是直接依赖 dep_b 可以避免使用以下行引入 rustc-serialize
dep_b = { version = "0.1.0", path = "dep_b", default-features = false }
这是 Cargo 中的错误,还是我做错了什么?这是related question
【问题讨论】:
标签: rust rust-cargo