依赖依赖关闭默认功能 [英] Turn off default-features in dependency of dependency
问题描述
我有一系列依赖项,这些依赖项以可选依赖于已弃用的库而告终.具体来说,我想使用间接依赖于 rustc-serialize 的 nalgebra 如下:
I have a chain of dependencies that end in depending optionally on a deprecated library. Concretely, I want to use nalgebra which depends indirectly on rustc-serialize as follows:
nalgebra -> alga -> num-complex -> (可选默认) rustc-serialize
nalgebra -> alga -> num-complex -> (optional default) rustc-serialize
我可以在 Cargo.toml 文件中列出 num-complex 依赖项并关闭可选的 rustc-serialize 依赖项(num-complex = { version = "0.1.42", default-features = false }
),但是有没有办法在 Cargo.toml 中一直关闭这个选项?
I can list the num-complex dependency in my Cargo.toml file and turn off the optional rustc-serialize dependency (num-complex = { version = "0.1.42", default-features = false }
), but is there a way to turn off this option all the way up the chain in Cargo.toml?
我尝试了另一种方法,即克隆其中的每一个并操纵本地副本的 Cargo.toml 文件来引用所有本地依赖项,这是可行的,但如果可能的话,我想要一种更易于维护的方法.
I have tried an alternative of cloning each of these and manipulating the local copies’ Cargo.toml file to refer to all the local dependencies, which works, but I would like a more maintainable way to do this if possible.
推荐答案
作为 H2O 状态,这是不可能的,但是检查他们的答案以获得一个很好的临时解决方法,以使事情再次正常工作.我想讨论为什么它不应该以及长期解决方案是什么.
As H2O states, this is not possible, but check their answer for a good temporary workaround to get things working again. I want to discuss why it should not be possible and what the long-term fix is.
一般来说,您无法判断 crate 使用依赖项的目的.alga 完全有可能在内部使用 num-complex 的 rustc-serialize 功能.
In general, you cannot tell what a crate uses a dependency for. It's completely possible that alga makes use of the rustc-serialize functionality of num-complex internally.
正确的做法是向上跟踪依赖链.转到每个项目并添加一个功能,该功能选择加入其直接依赖项的 rustc-serialize 功能.您还可以将 rustc-serialize
功能添加到默认功能中以保持向后兼容性.
The correct thing to do is to track the dependency chain upwards. Go to each project and add a feature that opts-in to the rustc-serialize functionality of its direct dependents. You would also add the rustc-serialize
feature to the default features to maintain backwards compatibility.
要么您最终能够向项目提交 PR 以改善每个人的情况,要么您将理解为什么您认为可选的内容实际上不是.
Either you will end up being able to submit a PR to the project to improve everyone's case, or you will understand why what you think is optional actually isn't.
这篇关于依赖依赖关闭默认功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!