macro_rules! rustc_cfg { ($($tokens:tt)*) => { ... }; }
Expand description
The rustc_cfg instruction tells Cargo to pass the given value to the
--cfg flag to the compiler. This may be used for compile-time detection
of features to enable conditional compilation.
Note that this does not affect Cargo’s dependency resolution. This cannot be used to enable an optional dependency, or enable other Cargo features.
Be aware that Cargo features use the form feature=“foo”. cfg values passed
with this flag are not restricted to that form, and may provide just a
single identifier, or any arbitrary key/value pair. For example, emitting
cargo:rustc-cfg=abc will then allow code to use #[cfg(abc)]
(note the lack of feature=). Or an arbitrary key/value pair may be used
with an = symbol like cargo:rustc-cfg=my_component="foo". The key should
be a Rust identifier, the value should be a string.
For more information, see this cargo reference.
§Examples
basic use:
rustc_cfg!("abc"); // allows #[cfg(abc)]
rustc_cfg!(r#"my_component="{}""#, "foo") // allows #[cfg(my_component="foo")]