1
1
fn main() {
2
    // get the enabled cargo features
3
1
    let features = std::env::vars()
4
253
        .filter_map(|(env_name, val)| feature_name(env_name, val))
5
        // arti crates all use lowercase feature names with '-'
6
5
        .map(|feature| feature.replace('_', "-").to_lowercase())
7
        .collect::<Vec<_>>()
8
1
        .join(",");
9
1
    println!("cargo:rustc-env=BUILD_FEATURES={features}");
10

            
11
1
    let opt_level = std::env::var("OPT_LEVEL").unwrap();
12
1
    println!("cargo:rustc-env=BUILD_OPT_LEVEL={opt_level}");
13

            
14
1
    let profile = std::env::var("PROFILE").unwrap();
15
1
    println!("cargo:rustc-env=BUILD_PROFILE={profile}");
16

            
17
1
    let debug = std::env::var("DEBUG").unwrap();
18
1
    println!("cargo:rustc-env=BUILD_DEBUG={debug}");
19

            
20
1
    let target = std::env::var("TARGET").unwrap();
21
1
    println!("cargo:rustc-env=BUILD_TARGET={target}");
22

            
23
1
    let host = std::env::var("HOST").unwrap();
24
1
    println!("cargo:rustc-env=BUILD_HOST={host}");
25

            
26
1
    let rustc = std::env::var("RUSTC").unwrap();
27
1
    let rustc_version = std::process::Command::new(rustc)
28
1
        .arg("--version")
29
1
        .output()
30
1
        .unwrap()
31
1
        .stdout;
32
1
    let rustc_version = String::from_utf8(rustc_version).unwrap();
33
1
    println!("cargo:rustc-env=BUILD_RUSTC_VERSION={rustc_version}");
34
1
}
35

            
36
/// Returns `Some` if `name` begins with "CARGO_FEATURE_" and `val` is "1". Used when obtaining a
37
/// list of enabled features.
38
253
fn feature_name(name: String, val: String) -> Option<String> {
39
253
    let feature = name.strip_prefix("CARGO_FEATURE_")?;
40
5
    if val != "1" {
41
        return None;
42
5
    }
43
5
    Some(feature.to_string())
44
253
}