构建脚本可以接受参数吗? [英] Can a build script take arguments?

查看:43
本文介绍了构建脚本可以接受参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读构建脚本文档和想知道我是否可以从命令行将任何参数传递给 build.rs 中的脚本.

I was going through the build script documentation and was wondering if I can pass any argument to the script in build.rs from the command line.

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

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

Would something like this work in the build script? And how could I specify the arguments from command line?

推荐答案

没有

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

Documentation suggests passing data to the build script using environment variables.

没有文件表明它可以完成并且 测试套件不对其进行测试.它只测试环境变量.

There is no documentation indicating that it can be done and the test suite does not test for it. It only tests for environment variables.

我尝试了@Stephan 从通过 Cargo 传递程序参数中建议的方法,但是 cargo build 不遵循与 cargo run 相同的行为:

I attempted the method that @Stephan suggests from Passing program arguments through Cargo, however cargo build does not follow the same behavior as 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

这篇关于构建脚本可以接受参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆