Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

rust - Can a build script take arguments?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No.

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...