BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / build.rs

build.rs

build.rs 1.5 KiB Download Raw
1use std::process::Command;
2
3fn main() {
4 let git = |args: &[&str]| {
5 Command::new("git")
6 .args(args)
7 .env("TZ", "UTC")
8 .output()
9 .ok()
10 .filter(|output| output.status.success())
11 .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned())
12 };
13 let commit = git(&["rev-parse", "--short", "HEAD"]).unwrap_or_else(|| "unknown".to_owned());
14 let timestamp = git(&["log", "-1", "--format=%cd", "--date=format-local:%Y%m%dT%H%M%SZ"])
15 .unwrap_or_else(|| chrono::Utc::now().format("%Y%m%dT%H%M%SZ").to_string());
16 println!("cargo:rustc-env=TEAMS_BUILD_VERSION={commit}-{timestamp}");
17 // Rerun only when HEAD moves, so an unchanged tree does not recompile the whole app crate.
18 if let Some(head) = git(&["rev-parse", "--path-format=absolute", "--git-path", "HEAD"]) {
19 println!("cargo:rerun-if-changed={head}");
20 }
21 if let Some(reference) = git(&["symbolic-ref", "-q", "HEAD"])
22 .and_then(|reference| git(&["rev-parse", "--path-format=absolute", "--git-path", &reference]))
23 {
24 println!("cargo:rerun-if-changed={reference}");
25 }
26 if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
27 println!("cargo:rerun-if-changed=assets/icon/teams-fast.ico");
28 println!("cargo:rerun-if-changed=assets/icon/app.rc");
29 embed_resource::compile("assets/icon/app.rc", embed_resource::NONE)
30 .manifest_optional()
31 .unwrap();
32 }
33 println!("cargo:rerun-if-changed=build.rs");
34}