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

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

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

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

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

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

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

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