[英]How do I specify features for a sub-dependency in Cargo?
I'm working on a CLI app that uses reqwest and self_update.我正在开发一个使用 reqwest 和 self_update 的 CLI 应用程序。 self_update also uses reqwest.
self_update 也使用 reqwest。 I want my app to use rustls and not pull in openssl dependencies.
我希望我的应用程序使用 rustls 而不是引入 openssl 依赖项。 Cargo.toml allows choosing features of dependencies:
Cargo.toml 允许选择依赖项的特性:
[dependencies.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]
It would be cool if sub-dependencies worked:如果子依赖项有效,那就太酷了:
[dependencies.self_update.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]
I also looked at replace section , but only something like this works where I branch the code:我还查看了replace section ,但只有这样的东西才能在我分支代码的地方工作:
"reqwest:0.10.1" = { branch = "rustls", git = "https://github.com/ctaggart/reqwest" }
But what I want is default-features and features supported too:但我想要的是默认功能和支持的功能:
"reqwest:0.10.1" = { tag="v0.10.1", git = "https://github.com/seanmonstar/reqwest", default-features = false, features = ["rustls-tls", "json", "blocking"] }
How do I configure the features of Reqwest or Tokio or any other highly configurable non-direct dependency using Cargo?如何使用 Cargo 配置 Reqwest 或 Tokio 或任何其他高度可配置的非直接依赖项的功能?
I agree with you, having support for sub-dependencies features would be great.我同意你的观点,支持子依赖特性会很棒。
It's not ideal but if you add your sub-dependency as a dependency the feature is going to work.这并不理想,但如果您将子依赖项添加为依赖项,则该功能将起作用。
[dependencies]
...
surf = "2.1.0" # which depends on http-client, which depends on isahc
...
[dependencies.isahc]
features = ["static-ssl"]
If you don't specify a version you'll get a deprecation warning, but at least you won't have to keep track of the sub-dependency version manually:如果您不指定版本,您将收到弃用警告,但至少您不必手动跟踪子依赖版本:
warning: dependency (isahc) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.