1#![doc = include_str!("../README.md")]
2
3#[macro_export]
4macro_rules! pyo3_built {
5 ($py: ident, $info: ident, $dict: ident, "build") => {
6 let build = PyDict::new($py);
8 build.set_item("rustc", $info::RUSTC)?;
9 build.set_item("rustc-version", $info::RUSTC_VERSION)?;
10 build.set_item("opt-level", $info::OPT_LEVEL)?;
11 build.set_item("debug", $info::DEBUG)?;
12 build.set_item("jobs", $info::NUM_JOBS)?;
13 $dict.set_item("build", build)?;
14 };
15 ($py: ident, $info: ident, $dict: ident, "time") => {
16 let dt = $py
17 .import("email.utils")?
18 .call_method1("parsedate_to_datetime", ($info::BUILT_TIME_UTC,))?;
19 $dict.set_item("info-time", dt)?;
20 };
21 ($py: ident, $info: ident, $dict: ident, "deps") => {
22 let deps = PyDict::new($py);
24 for (name, version) in $info::DEPENDENCIES.iter() {
25 deps.set_item(name, version)?;
26 }
27 $dict.set_item("dependencies", deps)?;
28 };
29 ($py: ident, $info: ident, $dict: ident, "features") => {
30 let features = $info::FEATURES
32 .iter()
33 .map(|feat| PyString::new($py, feat))
34 .collect::<Vec<_>>();
35 $dict.set_item("features", features)?;
36 };
37 ($py: ident, $info: ident, $dict: ident, "host") => {
38 let host = PyDict::new($py);
40 host.set_item("triple", $info::HOST)?;
41 $dict.set_item("host", host)?;
42 };
43 ($py: ident, $info: ident, $dict: ident, "target") => {
44 let target = PyDict::new($py);
46 target.set_item("arch", $info::CFG_TARGET_ARCH)?;
47 target.set_item("os", $info::CFG_OS)?;
48 target.set_item("family", $info::CFG_FAMILY)?;
49 target.set_item("env", $info::CFG_ENV)?;
50 target.set_item("triple", $info::TARGET)?;
51 target.set_item("endianness", $info::CFG_ENDIAN)?;
52 target.set_item("pointer-width", $info::CFG_POINTER_WIDTH)?;
53 target.set_item("profile", $info::PROFILE)?;
54 $dict.set_item("target", target)?;
55 };
56 ($py: ident, $info: ident, $dict: ident, "git") => {
57 let git = PyDict::new($py);
58 git.set_item("version", $info::GIT_VERSION)?;
59 git.set_item("dirty", $info::GIT_DIRTY)?;
60 git.set_item("hash", $info::GIT_COMMIT_HASH)?;
61 git.set_item("head", $info::GIT_HEAD_REF)?;
62 $dict.set_item("git", git)?;
63
64 };
65 ($py: ident, $info: ident) => {
67 pyo3_built!{$py, $info, "build", "time", "deps", "features", "host", "target"}
68 };
69 ($py: ident, $info: ident, $($i:tt ),+ ) => {{
71 use pyo3::types::PyDict;
72 use pyo3::types::PyString;
73 let info = PyDict::new($py);
74 $(
75 pyo3_built!{$py,$info, info, $i}
76 )+
77 info
78 }};
79}