cargo_emit

Macro rustc_env

Source
macro_rules! rustc_env {
    (to: $stream:expr, $key:expr, $value:expr $(, $($args:tt)*)?) => { ... };
    ($key:expr, $value:expr $(, $($args:tt)*)?) => { ... };
}
Expand description

Tells Cargo to assign $key for the environment variable for $key.

This is equivalent to:

println!("cargo:rustc-env=$key=$value");

ยงExamples

Useful for injecting environment variables during the build.

The $key and $value parameters get concatenated into a single formatting string. Formatting runtime values can be done by passing subsequent values.

let git_rev_hash = //
cargo_emit::rustc_env!("MY_HASH", "{}", git_rev_hash);

or, in case you want it to emit to a custom stream:

let mut stdout = std::io::stdout();
let git_rev_hash = // ...
cargo_emit::rustc_env!(
    to: stdout,
   "MY_HASH", "{}", git_rev_hash
);