macro_rules! rustc_cfg {
(to: $stream:expr, $feature:expr $(, $($args:tt)*)?) => { ... };
($feature:expr $(, $($args:tt)*)?) => { ... };
}
Expand description
Tells Cargo to enable a $feature
.
This is equivalent to:
println!("cargo:rustc-cfg=$feature");
ยงExamples
Useful for conditionally enabling certain code to run.
if cargo.can_bench() {
cargo_emit::rustc_cfg!("bench");
}
or, in case you want it to emit to a custom stream:
let mut stdout = std::io::stdout();
if cargo.can_bench() {
cargo_emit::rustc_cfg!(
to: stdout,
"bench"
);
}
Then outside of build.rs
:
#[cfg(bench)]
mod benches {
// ...
}