Files
latchd/build.rs
Zane Walker faf5b27328 feat: ship Rust login manager and GitLab release pipeline
Replace the legacy Go implementation as the production path, quarantine the reference tree, add deterministic release packaging and version metadata, and run verification through GitLab CI.
2026-09-25 21:33:46 +05:30

42 lines
1.3 KiB
Rust

use std::{env, process::Command};
fn main() {
for variable in [
"LATCHD_VERSION",
"LATCHD_COMMIT",
"LATCHD_BUILD_TIME",
"SOURCE_DATE_EPOCH",
] {
println!("cargo:rerun-if-env-changed={variable}");
}
let version = env::var("LATCHD_VERSION")
.ok()
.filter(|value| !value.is_empty())
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_owned());
let commit = env::var("LATCHD_COMMIT")
.ok()
.filter(|value| !value.is_empty())
.or_else(|| git_value(["rev-parse", "--short=12", "HEAD"]))
.unwrap_or_else(|| "unknown".to_owned());
let build_time = env::var("LATCHD_BUILD_TIME")
.ok()
.filter(|value| !value.is_empty())
.or_else(|| env::var("SOURCE_DATE_EPOCH").ok())
.unwrap_or_else(|| "unknown".to_owned());
println!("cargo:rustc-env=LATCHD_VERSION={version}");
println!("cargo:rustc-env=LATCHD_COMMIT={commit}");
println!("cargo:rustc-env=LATCHD_BUILD_TIME={build_time}");
}
fn git_value<const N: usize>(arguments: [&str; N]) -> Option<String> {
let output = Command::new("git").args(arguments).output().ok()?;
if !output.status.success() {
return None;
}
let value = String::from_utf8(output.stdout).ok()?;
let value = value.trim();
(!value.is_empty()).then(|| value.to_owned())
}