summaryrefslogtreecommitdiffstats
path: root/build.rs
blob: afc62c9a578d72023809e478661f1a8c4031df34 (plain)
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
use std::process;

use chrono::Utc;

fn main() {
	// Make the current git hash available to the build
	if let Some(rev) = git_revision_hash() {
		println!("cargo:rustc-env=GIRT_BUILD_GIT_HASH={}", rev);
	}
	println!("cargo:rustc-env=GIRT_BUILD_DATE={}", Utc::now().format("%Y-%m-%d"));
}

fn git_revision_hash() -> Option<String> {
	let result = process::Command::new("git")
		.args(&["rev-parse", "--short=10", "HEAD"])
		.output();
	result.ok().and_then(|output| {
		let v = String::from_utf8_lossy(&output.stdout).trim().to_string();
		if v.is_empty() {
			None
		}
		else {
			Some(v)
		}
	})
}