Skip to main content

cu29_build/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// Environment variable used to pass the consuming crate's Cargo features to
4/// Copper's procedural macros and generated runtime.
5pub const COPPER_CFG_FEATURES_ENV: &str = "COPPER_CFG_FEATURES";
6
7/// Emit the standard Cargo build-script configuration required by Copper.
8pub fn setup() {
9    println!(
10        "cargo::rustc-env=LOG_INDEX_DIR={}",
11        std::env::var("OUT_DIR").expect("Cargo must provide OUT_DIR")
12    );
13
14    let mut features: Vec<_> = std::env::var("CARGO_CFG_FEATURE")
15        .unwrap_or_default()
16        .split(',')
17        .filter(|feature| !feature.is_empty())
18        .map(str::to_owned)
19        .collect();
20    features.sort_unstable();
21    features.dedup();
22
23    println!(
24        "cargo::rustc-env={COPPER_CFG_FEATURES_ENV}={}",
25        features.join(",")
26    );
27}
28
29#[cfg(test)]
30mod tests {
31    use super::COPPER_CFG_FEATURES_ENV;
32
33    #[test]
34    fn feature_environment_name_is_stable() {
35        assert_eq!(COPPER_CFG_FEATURES_ENV, "COPPER_CFG_FEATURES");
36    }
37}