1pub struct Env {
7 pub rust_version: String,
8 pub platform: String,
9 pub ellip_version: String,
10 pub cpu: String,
11}
12
13pub fn get_env() -> Env {
14 use std::process::Command;
15
16 let mut sys = sysinfo::System::new_all();
17 sys.refresh_all();
18 let cpu = match sys.cpus().first() {
19 Some(cpu) => cpu.brand(),
20 None => "Unknown CPU",
21 }
22 .to_string();
23
24 let rust_version = {
25 let output = Command::new("rustc")
26 .arg("--version")
27 .output()
28 .unwrap()
29 .stdout;
30 String::from_utf8_lossy(&output)
31 .split_whitespace()
32 .collect::<Vec<&str>>()[1]
33 .to_owned()
34 };
35
36 let platform = {
37 let output = Command::new("rustc").arg("-vV").output().unwrap().stdout;
38 String::from_utf8_lossy(&output)
39 .lines()
40 .find(|line| line.starts_with("host:"))
41 .unwrap()
42 .strip_prefix("host: ")
43 .unwrap()
44 .to_owned()
45 };
46
47 let ellip_version: String = {
48 let output = Command::new("cargo")
49 .args(["tree", "--invert", "--package", "ellip"])
50 .output()
51 .unwrap()
52 .stdout;
53 String::from_utf8_lossy(&output)
54 .lines()
55 .next()
56 .and_then(|line| line.strip_prefix("ellip v"))
57 .unwrap()
58 .split_whitespace()
59 .next()
60 .unwrap()
61 .to_owned()
62 };
63
64 Env {
65 rust_version,
66 platform,
67 ellip_version,
68 cpu,
69 }
70}