【问题标题】:Rust cargo: how to use different features for a dep when a particular feature is enabled?Rust cargo:启用特定功能时如何为 dep 使用不同的功能?
【发布时间】:2017-01-03 17:49:34
【问题描述】:

例如,我定义了 2 个没有依赖关系的特性:

[features]
default = []
py2 = []
py3 = []

基于选定的功能 (--features py3) 我想为依赖项启用不同的功能 (cpython):

[dependencies.cpython]
default-features = false
# features = ["python27-sys"]      I want to select this if py2 is enabled
features = ["python3-sys"]
optional = true

我可以这样做吗?或者我也可以简单地从命令行为依赖项选择功能?

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    讨论了here。可以通过/ 做到这一点。

    [features]
    default = []
    py2 = ["cpython", "cpython/python27-sys"]
    py3 = ["cpython", "cpython/python3-sys"]
    unstable = []
    
    [dependencies.cpython]
    # git = "https://github.com/dgrunwald/rust-cpython.git"
    default-features = false
    optional = true
    

    我在文档或官方页面中没有看到任何关于它的内容。

    【讨论】:

    • 有没有办法根据启用的功能将默认功能设置为真或假?
    猜你喜欢
    • 2021-01-08
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多