35 lines
No EOL
846 B
Rust
35 lines
No EOL
846 B
Rust
use std::process::Command;
|
|
|
|
fn main() {
|
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
|
|
println!("cargo:rustc-env=GIT_TAG={}", git_tag());
|
|
}
|
|
|
|
fn git_commit_hash() -> String {
|
|
let commit_command = Command::new("git")
|
|
.args(&[
|
|
"rev-parse",
|
|
"HEAD"
|
|
])
|
|
.output();
|
|
|
|
match commit_command {
|
|
Ok(out) => String::from_utf8(out.stdout).unwrap_or(String::from("unknown")),
|
|
Err(_) => String::from("unknown")
|
|
}
|
|
}
|
|
|
|
fn git_tag() -> String {
|
|
let tag_command = Command::new("git")
|
|
.args(&[
|
|
"describe",
|
|
"--tags",
|
|
"--abbrev=0"
|
|
])
|
|
.output();
|
|
|
|
match tag_command {
|
|
Ok(out) => String::from_utf8(out.stdout).unwrap_or(String::from("unknown")),
|
|
Err(_) => String::from("unknown")
|
|
}
|
|
} |