【发布时间】:2020-12-28 01:11:08
【问题描述】:
我正在开发一个使用 reqwest 和 self_update 的 CLI 应用程序。 self_update 也使用 reqwest。我希望我的应用程序使用 rustls 而不是引入 openssl 依赖项。 Cargo.toml 允许 choosing features 的依赖项:
[dependencies.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]
如果子依赖有效,那就太酷了:
[dependencies.self_update.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]
我还查看了replace section,但只有这样的东西在我分支代码的地方才有效:
"reqwest:0.10.1" = { branch = "rustls", git = "https://github.com/ctaggart/reqwest" }
但我想要的是默认功能和支持的功能:
"reqwest:0.10.1" = { tag="v0.10.1", git = "https://github.com/seanmonstar/reqwest", default-features = false, features = ["rustls-tls", "json", "blocking"] }
如何使用 Cargo 配置 Reqwest 或 Tokio 或任何其他高度可配置的非直接依赖项的功能?
【问题讨论】:
-
特征是附加的。如果您在自己的依赖项中启用了一项功能,那么它也可以在您的子依赖项中使用。无论有没有该功能,您都不会在您的应用程序中获得两个
reqwest副本。 -
好的,但是如何删除默认功能?如何防止
self_update引入 openssl 依赖项,这是reqwest的默认功能? -
self_update本身必须具有这样做的功能。 Cargo 无法知道从子依赖项中删除功能是否安全,因为您的依赖项实际上可能使用该功能。 -
我想过给
self_update添加一个rustls特性,但是cargo不支持基于特性的不同依赖。 github.com/rust-lang/cargo/issues/5954 我认为必须将每个可选功能都冒泡到消费库中是一种奇怪的设计。
标签: rust rust-cargo