【问题标题】:Can a build script take arguments?构建脚本可以带参数吗?
【发布时间】:2018-08-03 18:03:36
【问题描述】:

我正在浏览the build script documentation,想知道是否可以从命令行将任何参数传递给build.rs 中的脚本。

fn main() {
    let args: Vec<String> = env::args().collect();
    let var = &args[1];
}

这样的东西在构建脚本中会起作用吗?我怎么能从命令行指定参数?

【问题讨论】:

    标签: rust


    【解决方案1】:

    没有。

    文档建议使用环境变量将数据传递给构建脚本。

    没有文档表明可以做到这一点,the test suite does not test for it。它只测试environment variables

    我尝试了@Stephan 从Passing program arguments through Cargo 建议的方法,但是cargo build 不遵循与cargo run 相同的行为:

    $ cargo build -- uoeuoe
    error: Found argument 'uoeuoe' which wasn't expected, or isn't valid in this context
    
    USAGE:
        cargo.exe build [OPTIONS]
    
    For more information try --help
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-30
      • 2016-01-02
      • 2016-01-04
      • 2021-12-24
      • 1970-01-01
      • 2011-08-16
      • 2011-03-14
      • 2020-02-14
      相关资源
      最近更新 更多