-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
41 lines (36 loc) · 1.16 KB
/
build.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
use std::ffi;
use std::process;
fn main() {
let rustc = std::env::var("RUSTC").unwrap_or("<unknown>".to_owned());
let compiler_version = version(rustc).unwrap_or("<unknown>".to_owned());
println!("cargo:rustc-env=RUSTC_VERSION={}", compiler_version);
let cargo = std::env::var("CARGO").unwrap_or("<unknown>".to_owned());
let cargo_version = version(cargo).unwrap_or("<unknown>".to_owned());
println!("cargo:rustc-env=CARGO_VERSION={}", cargo_version);
let gitsha = gitsha().unwrap_or("<unknown>".to_owned());
println!("cargo:rustc-env=GITSHA={}", gitsha);
}
fn version<P: AsRef<ffi::OsStr>>(command: P) -> Option<String> {
match process::Command::new(command).arg("-V").output() {
Ok(o) => {
let mut v = String::from_utf8(o.stdout).unwrap();
v.pop();
Some(v)
}
Err(_) => None,
}
}
fn gitsha() -> Option<String> {
match process::Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
{
Ok(o) => {
let mut v = String::from_utf8(o.stdout).unwrap();
v.pop();
Some(v)
}
Err(_) => None,
}
}