devela/build/
environment.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// devela build::utils
//
//! Build script environment variables.
//

pub(crate) fn main() -> Result<(), std::io::Error> {
    let cargo_primary_package = option_env!("CARGO_PRIMARY_PACKAGE");
    if cargo_primary_package.is_some() {
        println!("cargo:rustc-cfg=cargo_primary_package");
    }

    #[cfg(feature = "__dbg")]
    {
        use super::utils::{println, println_heading, println_var, println_var_encoded};

        // https://doc.rust-lang.org/cargo/reference/environment-variables.html
        println_heading("Environment variables:");

        if let Some(v) = cargo_primary_package {
            println(&format!["ยท CARGO_PRIMARY_PACKAGE={v}"]);
        } else {
            println("x CARGO_PRIMARY_PACKAGE");
        }

        println_var("CARGO_MANIFEST_DIR");
        println_var("CARGO_MANIFEST_PATH");
        println_var("OUT_DIR");

        println_var("HOST");
        println_var("TARGET");
        println_var("PROFILE");
        println_var("NUM_JOBS");

        println_var("RUSTC");
        // println_var("RUSTC_WRAPPER");
        // println_var("RUSTC_LINKER");
        // println_var("RUSTDOC");
        // println_var("CARGO");
        // println_var("CARGO_MAKEFLAGS");
        // println_var("CARGO_ENCODED_RUSTFLAGS");

        // for (key, value) in std::env::vars() {
        //     super::utils::println(&format![">> {key}: {value}"]);
        // }

        println_var_encoded("CARGO_ENCODED_RUSTFLAGS", "RUSTFLAGS");
        println_var("RUSTDOCFLAGS");
    }

    Ok(())
}