-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
51 lines (49 loc) · 1.53 KB
/
build.rs
File metadata and controls
51 lines (49 loc) · 1.53 KB
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
use std::env;
fn git_commit_hash() -> String {
if let Ok(output) = std::process::Command::new("git")
.arg("rev-list")
.arg("-1")
.arg("HEAD")
.output()
{
if output.status.success() {
std::str::from_utf8(&output.stdout[..40])
.unwrap()
.to_string()
} else {
// When not in git repository
// (e.g. when the user install by `cargo install xx`)
"UNKNOWN".to_string()
}
} else {
// When there is no git command for some reason
"UNKNOWN".to_string()
}
}
fn main() {
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH");
println!(
"cargo:rustc-env=GIT_COMMIT_HASH_SHORT={}",
&git_commit_hash()[..7]
);
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
// https://doc.rust-lang.org/reference/conditional-compilation.html#set-configuration-options
println!(
"cargo:rustc-env=TARGET_OS={}",
env::var("CARGO_CFG_TARGET_OS").unwrap()
);
println!(
"cargo:rustc-env=TARGET_ARCH={}",
env::var("CARGO_CFG_TARGET_ARCH").unwrap()
);
println!(
"cargo:rustc-env=TARGET_FAMILY={}",
env::var("CARGO_CFG_TARGET_FAMILY").unwrap()
);
println!(
"cargo:rustc-env=TARGET_ENV={}",
env::var("CARGO_CFG_TARGET_ENV").unwrap()
);
}