build_script_cfg/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#![doc = include_str!("../README.md")]
#![deny(warnings, missing_docs)]

/// The type that represents a configuration option.
#[derive(Clone, PartialEq, Eq, Debug)]
#[repr(transparent)]
pub struct Cfg<S>(S);

impl<S: std::fmt::Display> Cfg<S> {
    /// Creates a new configuration option with the given name.
    #[inline]
    pub fn new(name: S) -> Self {
        println!("cargo::rustc-check-cfg=cfg({name})");
        Self(name)
    }

    /// Sets the corresponding `rustc-cfg` flag.
    #[inline]
    pub fn define(self) {
        println!("cargo:rustc-cfg={}", self.0);
    }
}