git clone https://garage44.eu/jeroen/midas.git.. /build.rs
//! Stamp the binary with the commit it was built from, so `midas --version` and
//! `midas check` can tell which build every machine runs — including one an
//! owner built by hand with plain `cargo build`. deploy.sh's MIDAS_BUILD wins.
//!
//! And carry the hub's web page when it was built (`web/`, `bun run build`):
//! `cfg(midas_web)` says `web/dist/` was there to embed. A node or an owner's
//! build without Bun gets a hub that says how to build the page instead.
use std::path::Path;
use std::process::Command;
fn main() {
println!("cargo::rustc-check-cfg=cfg(midas_web)");
println!("cargo:rerun-if-changed=web/dist");
if ["index.html", "app.js", "app.js.gz", "app.css", "app.css.gz", "sw.js", "manifest.json", "icon.svg", "icon-192.png", "icon-512.png"].iter().all(|f| Path::new("web/dist").join(f).exists()) {
println!("cargo:rustc-cfg=midas_web");
}
println!("cargo:rerun-if-env-changed=MIDAS_BUILD");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
if std::env::var_os("MIDAS_BUILD").is_some() {
return;
}
let describe = Command::new("git").args(["describe", "--always", "--dirty", "--abbrev=8"]).output();
if let Some(out) = describe.ok().filter(|o| o.status.success()) {
let v = String::from_utf8_lossy(&out.stdout).trim().to_string();
if !v.is_empty() {
println!("cargo:rustc-env=MIDAS_BUILD={v}");
}
}
}