2022-03-11 22:13:54 +01:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
2022-03-16 15:13:30 +01:00
|
|
|
println!(">>> Building version number...");
|
2022-03-11 22:13:54 +01:00
|
|
|
|
|
|
|
let rustc = std::env::var("RUSTC").unwrap();
|
2022-05-05 15:50:44 +02:00
|
|
|
let out = Command::new(rustc)
|
|
|
|
.arg("--version")
|
|
|
|
.output()
|
|
|
|
.expect("failed to run `rustc --version`");
|
|
|
|
let rustc_version =
|
|
|
|
String::from_utf8(out.stdout).expect("rustc --version returned invalid UTF-8");
|
2022-03-11 22:13:54 +01:00
|
|
|
let rustc_version = rustc_version.trim();
|
|
|
|
println!("cargo:rustc-env=CARGO_RUSTC_VERSION={}", rustc_version);
|
|
|
|
|
2022-03-16 15:17:09 +01:00
|
|
|
println!("cargo:rerun-if-env-changed=BFFHD_BUILD_TAGGED_RELEASE");
|
2022-03-11 22:13:54 +01:00
|
|
|
let tagged_release = option_env!("BFFHD_BUILD_TAGGED_RELEASE") == Some("1");
|
2022-04-27 17:21:45 +02:00
|
|
|
let version_string = if tagged_release {
|
2022-05-05 15:50:44 +02:00
|
|
|
format!(
|
|
|
|
"{version} [{rustc}]",
|
|
|
|
version = env!("CARGO_PKG_VERSION"),
|
|
|
|
rustc = rustc_version
|
|
|
|
)
|
2022-03-11 22:13:54 +01:00
|
|
|
} else {
|
2022-03-16 15:13:30 +01:00
|
|
|
// Build version number using the current git commit id
|
2022-05-05 15:50:44 +02:00
|
|
|
let out = Command::new("git")
|
|
|
|
.arg("rev-list")
|
|
|
|
.args(["HEAD", "-1"])
|
|
|
|
.output()
|
|
|
|
.expect("failed to run `git rev-list HEAD -1`");
|
|
|
|
let owned_gitrev =
|
|
|
|
String::from_utf8(out.stdout).expect("git rev-list output was not valid UTF8");
|
2022-03-16 15:13:30 +01:00
|
|
|
let gitrev = owned_gitrev.trim();
|
2022-05-05 15:50:44 +02:00
|
|
|
let abbrev = match gitrev.len() {
|
2022-03-16 15:13:30 +01:00
|
|
|
0 => "unknown",
|
|
|
|
_ => &gitrev[0..9],
|
|
|
|
};
|
|
|
|
|
2022-05-05 15:50:44 +02:00
|
|
|
let out = Command::new("git")
|
|
|
|
.arg("log")
|
|
|
|
.args(["-1", "--format=%as"])
|
|
|
|
.output()
|
|
|
|
.expect("failed to run `git log -1 --format=\"format:%as\"`");
|
|
|
|
let commit_date = String::from_utf8(out.stdout).expect("git log output was not valid UTF8");
|
2022-03-16 15:13:30 +01:00
|
|
|
let commit_date = commit_date.trim();
|
|
|
|
|
2022-05-05 15:50:44 +02:00
|
|
|
format!(
|
|
|
|
"{version} ({gitrev} {date}) [{rustc}]",
|
|
|
|
version = env!("CARGO_PKG_VERSION"),
|
|
|
|
gitrev = abbrev,
|
|
|
|
date = commit_date,
|
|
|
|
rustc = rustc_version
|
|
|
|
)
|
2022-03-11 22:13:54 +01:00
|
|
|
};
|
2022-04-27 17:21:45 +02:00
|
|
|
println!("cargo:rustc-env=BFFHD_VERSION_STRING={}", version_string);
|
2022-05-05 15:50:44 +02:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=BFFHD_RELEASE_STRING=\"BFFH {}\"",
|
|
|
|
version_string
|
|
|
|
);
|
2022-03-11 22:13:54 +01:00
|
|
|
}
|