Inputs to build.rs

Is there a way to pass inputs to build scripts (build.rs)? I have a case where in a string to be passed to build script which intern will be passed to some other script called within build.rs.
Appreciate any inputs on this regard.

Input is usually passed to build scripts via environment variables.

Hi @jofas, I tried the following which didn't work:
CLI:
cargo -vv build --config MYVAR="abc"

build.rs:
let myvar = env::var("MYVAR").unwrap();
here myvar was NULL and hence compilation failed (due to unwrap on null).

But yes, having MYVAR in [env] of config.toml works, but I'm looking for passing it via cargo build CLI.

MYVAR="abc" cargo -vv build

1 Like

Mybad, I was doing a mistake while passing arg

Right CLI: cargo -vv build --config **env.**MYVAR="abc"