use std::{env, error::Error, path::PathBuf, process::Command};
fn check_lib(lib: &str, package_hint: &str) {
let status = Command::new("pkg-config").args(["--exists", lib]).status();
match status {
Ok(s) if s.success() => {}
_ => {
println!(
"cargo:warning=System library '{lib}' not found. \
Install it (e.g. `apt install {package_hint}`) or run: ./setup.sh"
);
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
if Command::new("pkg-config").arg("--version").status().is_ok() {
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux") {
check_lib("alsa", "libasound2-dev");
check_lib("libudev", "libudev-dev");
}
check_lib("openssl", "libssl-dev");
}
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
tonic_prost_build::configure()
.file_descriptor_set_path(out_dir.join("player_descriptor.bin"))
.compile_protos(&["src/proto/player/v1/player.proto"], &["src/proto"])?;
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=MTRACK_GIT_HASH={git_hash}");
let build_time = jiff::Timestamp::now().strftime("%Y-%m-%dT%H:%M:%SZ");
println!("cargo:rustc-env=MTRACK_BUILD_TIME={build_time}");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs");
Ok(())
}