【问题标题】:How to pass compiler flags to a sub crate in Rust? [duplicate]如何将编译器标志传递给 Rust 中的子板条箱? [复制]
【发布时间】:2018-06-23 02:52:30
【问题描述】:

我有箱子 ABA 依赖于 BB 有一个名为 some_feature 的功能。

我可以通过运行 cargo build --features=some_feature 使用 cargo 构建 B,但是我如何为 A 设置相同的功能,我可以选择在编译 @987654332 时为底层 crate B 启用或禁用 some_feature @?

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    您可以简单地转发A中指定的功能:

    # A/Cargo.toml
    
    [features]
    some-feature = ["B/some-feature"]
    
    [dependencies]
    B = "*"
    

    如果您将--features=some_feature 传递给A,这将编译B--features=some_feature

    【讨论】:

      【解决方案2】:

      你只需要配置清单,就像doc说的一样简单:

      [dependencies.awesome]
      version = "1.3.5"
      default-features = false # do not include the default features, and optionally
                               # cherry-pick individual features
      features = ["secure-password", "civet"]
      

      【讨论】:

        猜你喜欢
        • 2019-04-14
        • 1970-01-01
        • 1970-01-01
        • 2012-10-12
        • 1970-01-01
        • 1970-01-01
        • 2011-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多