如何将编译器标志传递给 Rust 中的子包?

All*_*Lee 5 rust rust-cargo

我有板条箱ABA依赖于B并且B有一个名为 的功能some_feature

我可以B通过运行来使用 Cargo进行构建cargo build --features=some_feature,但是如何设置相同的功能,以便在编译时A可以选择启用或禁用some_feature底层板条箱?BA

Tim*_*ann 7

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

# A/Cargo.toml

[features]
some-feature = ["B/some-feature"]

[dependencies]
B = "*"
Run Code Online (Sandbox Code Playgroud)

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