-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
61 lines (58 loc) · 1.77 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use chrono::prelude::*;
use rustc_version::version_meta;
use std::{env, process::Command};
fn main() {
// Git Information
let output = Command::new("git")
.args([
"show",
"--pretty=format:'%H,%cn,%cI'",
"--no-patch",
"--no-notes",
])
.output()
.unwrap();
let command_args: Vec<String> = String::from_utf8(output.stdout)
.unwrap()
.replace('\'', "")
.split(',')
.map(String::from)
.collect();
println!("cargo:rustc-env=COMMIT_HASH={}", command_args[0]);
println!("cargo:rustc-env=COMMIT_AUTHOR={}", command_args[1]);
let commit_date = DateTime::parse_from_rfc3339(command_args[2].as_str())
.unwrap()
.with_timezone(&Utc)
.to_rfc3339_opts(SecondsFormat::Millis, true);
println!("cargo:rustc-env=COMMIT_DATE={}", commit_date);
// Build Date
let build_date = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true);
println!("cargo:rustc-env=BUILD_DATE={}", build_date);
// Build Profile
println!(
"cargo:rustc-env=BUILD_PROFILE={}",
match env::var("PROFILE").unwrap().as_str() {
"release" => "Release",
"debug" => "Debug",
_ => "Unknown",
}
);
// Build Platform
println!(
"cargo:rustc-env=BUILD_PLATFORM={}",
env::var("TARGET").unwrap()
);
// Rustc Version & LLVM Version
let rustc_version = version_meta().unwrap();
println!(
"cargo:rustc-env=RUSTC_VERSION={}",
rustc_version.short_version_string
);
println!(
"cargo:rustc-env=LLVM_VERSION={}",
match rustc_version.llvm_version {
Some(v) => v.to_string(),
None => "Unknown".to_string(),
}
)
}