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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#![doc = include_str!("../README.md")]

#[macro_export]
macro_rules! pyo3_built {
    ($py: ident, $info: ident, $dict: ident, "build") => {
        // Rustc
        let build = PyDict::new_bound($py);
        build.set_item("rustc", $info::RUSTC)?;
        build.set_item("rustc-version", $info::RUSTC_VERSION)?;
        build.set_item("opt-level", $info::OPT_LEVEL)?;
        build.set_item("debug", $info::DEBUG)?;
        build.set_item("jobs", $info::NUM_JOBS)?;
        $dict.set_item("build", build)?;
    };
    ($py: ident, $info: ident, $dict: ident, "time") => {
        let dt = $py
            .import_bound("email.utils")?
            .call_method1("parsedate_to_datetime", ($info::BUILT_TIME_UTC,))?;
        $dict.set_item("info-time", dt)?;
    };
    ($py: ident, $info: ident, $dict: ident, "deps") => {
        // info dependencies
        let deps = PyDict::new_bound($py);
        for (name, version) in $info::DEPENDENCIES.iter() {
            deps.set_item(name, version)?;
        }
        $dict.set_item("dependencies", deps)?;
    };
    ($py: ident, $info: ident, $dict: ident, "features") => {
        // Features
        let features = $info::FEATURES
            .iter()
            .map(|feat| PyString::new_bound($py, feat))
            .collect::<Vec<_>>();
        $dict.set_item("features", features)?;
    };
    ($py: ident, $info: ident, $dict: ident, "host") => {
        // Host
        let host = PyDict::new_bound($py);
        host.set_item("triple", $info::HOST)?;
        $dict.set_item("host", host)?;
    };
    ($py: ident, $info: ident, $dict: ident, "target") => {
        // Target
        let target = PyDict::new_bound($py);
        target.set_item("arch", $info::CFG_TARGET_ARCH)?;
        target.set_item("os", $info::CFG_OS)?;
        target.set_item("family", $info::CFG_FAMILY)?;
        target.set_item("env", $info::CFG_ENV)?;
        target.set_item("triple", $info::TARGET)?;
        target.set_item("endianness", $info::CFG_ENDIAN)?;
        target.set_item("pointer-width", $info::CFG_POINTER_WIDTH)?;
        target.set_item("profile", $info::PROFILE)?;
        $dict.set_item("target", target)?;
    };
    ($py: ident, $info: ident, $dict: ident, "git") => {
        let git = PyDict::new_bound($py);
        git.set_item("version", $info::GIT_VERSION)?;
        git.set_item("dirty", $info::GIT_DIRTY)?;
        git.set_item("hash", $info::GIT_COMMIT_HASH)?;
        git.set_item("head", $info::GIT_HEAD_REF)?;
        $dict.set_item("git", git)?;

    };
    // Default build
    ($py: ident, $info: ident) => {
        pyo3_built!{$py, $info, "build", "time", "deps", "features", "host", "target"}
    };
    // Custom build
    ($py: ident, $info: ident, $($i:tt ),+ ) => {{
        use pyo3::types::PyDict;
        use pyo3::types::PyString;
        let info = PyDict::new_bound($py);
        $(
            pyo3_built!{$py,$info, info, $i}
        )+
        info
    }};
}