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

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

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

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

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

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

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

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