feat: add build sha to parser.c header comment

This commit is contained in:
dundargoc 2024-10-24 12:44:37 +02:00 committed by dundargoc
parent 74481399df
commit dc4e232e6e
3 changed files with 41 additions and 2 deletions

32
cli/generate/build.rs Normal file
View file

@ -0,0 +1,32 @@
use std::{env, path::PathBuf, process::Command};
fn main() {
if let Some(git_sha) = read_git_sha() {
println!("cargo:rustc-env=BUILD_SHA={git_sha}");
}
}
// This is copied from the build.rs in parent directory. This should be updated if the
// parent build.rs gets fixes.
fn read_git_sha() -> Option<String> {
let crate_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
if !crate_path
.parent()?
.parent()
.map_or(false, |p| p.join(".git").is_dir())
{
return None;
}
Command::new("git")
.args(["rev-parse", "HEAD"])
.current_dir(crate_path)
.output()
.map_or(None, |output| {
if !output.status.success() {
return None;
}
Some(String::from_utf8_lossy(&output.stdout).to_string())
})
}