1
0
mirror of https://github.com/spikecodes/libreddit synced 2024-12-26 02:25:41 +01:00
libreddit/build.rs

27 lines
601 B
Rust
Raw Normal View History

use std::{
process::{Command, ExitStatus, Output},
};
2023-03-09 05:32:41 +01:00
#[cfg(not(target_os = "windows"))]
use std::os::unix::process::ExitStatusExt;
#[cfg(target_os = "windows")]
use std::os::windows::process::ExitStatusExt;
fn main() {
let output = String::from_utf8(
Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap_or(Output {
stdout: vec![],
stderr: vec![],
status: ExitStatus::from_raw(0),
})
.stdout,
)
.unwrap_or_default();
let git_hash = if output == String::default() { "dev".into() } else { output };
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}