【问题标题】:How to custom condition compile and passing argument by cargo?如何自定义条件编译并通过货物传递参数?
【发布时间】:2021-10-28 08:52:28
【问题描述】:

我想用语言选项编译 rust 代码:

#[cfg(lang = "en")]
use xxx;

#[cfg(lang = "fr")]
use yyy;

以及如何运行货物和传递参数?

cargo release --feature "lang=en" // error!

【问题讨论】:

  • 你可能想要#[cfg(feature = "en")]cargo release --features "en"
  • 表示我认为编译时语言选择不是建议。

标签: rust rust-cargo


【解决方案1】:

您可以使用#[cfg(en)] 并将--cfg en 传递给rustc。

但是,如果你使用 cargo,那么你可以附加到你的 .cargo/cargo.toml(如果你没有,必须创建这个文件)这个:

[build]
rustflags = ["--cfg", "en"]

您还可以编写脚本来构建和运行生成此文件并调用货物的项目。

【讨论】:

    猜你喜欢
    • 2018-10-23
    • 1970-01-01
    • 2011-09-17
    • 2016-07-28
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多