| 1 | use std::process::Command; |
| 2 | |
| 3 | fn 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(&[ |
| 15 | "log", |
| 16 | "-1", |
| 17 | "--format=%cd", |
| 18 | "--date=format-local:%Y%m%dT%H%M%SZ", |
| 19 | ]) |
| 20 | .unwrap_or_else(|| chrono::Utc::now().format("%Y%m%dT%H%M%SZ").to_string()); |
| 21 | println!("cargo:rustc-env=TEAMS_BUILD_VERSION={commit}-{timestamp}"); |
| 22 | println!("cargo:rerun-if-env-changed=GITHUB_REF_NAME"); |
| 23 | println!("cargo:rerun-if-env-changed=GITHUB_REF_TYPE"); |
| 24 | let release_tag = std::env::var("GITHUB_REF_NAME") |
| 25 | .ok() |
| 26 | .filter(|_| std::env::var("GITHUB_REF_TYPE").as_deref() == Ok("tag")) |
| 27 | .filter(|tag| tag.starts_with('v')); |
| 28 | if let Some(tag) = release_tag { |
| 29 | println!("cargo:rustc-env=TEAMS_RELEASE_TAG={tag}"); |
| 30 | } |
| 31 | // Rerun only when HEAD moves, so an unchanged tree does not recompile the whole app crate. |
| 32 | if let Some(head) = git(&["rev-parse", "--path-format=absolute", "--git-path", "HEAD"]) { |
| 33 | println!("cargo:rerun-if-changed={head}"); |
| 34 | } |
| 35 | if let Some(reference) = git(&["symbolic-ref", "-q", "HEAD"]).and_then(|reference| { |
| 36 | git(&[ |
| 37 | "rev-parse", |
| 38 | "--path-format=absolute", |
| 39 | "--git-path", |
| 40 | &reference, |
| 41 | ]) |
| 42 | }) { |
| 43 | println!("cargo:rerun-if-changed={reference}"); |
| 44 | } |
| 45 | if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") { |
| 46 | let rc = if std::path::Path::new("assets/icon/kvt-app.rc").exists() { |
| 47 | println!("cargo:rerun-if-changed=assets/icon/kvt-teams.ico"); |
| 48 | println!("cargo:rerun-if-changed=assets/icon/kvt-app.rc"); |
| 49 | "assets/icon/kvt-app.rc" |
| 50 | } else { |
| 51 | println!("cargo:rerun-if-changed=assets/icon/teams-fast.ico"); |
| 52 | println!("cargo:rerun-if-changed=assets/icon/app.rc"); |
| 53 | "assets/icon/app.rc" |
| 54 | }; |
| 55 | embed_resource::compile(rc, embed_resource::NONE) |
| 56 | .manifest_optional() |
| 57 | .unwrap(); |
| 58 | } |
| 59 | println!("cargo:rerun-if-changed=build.rs"); |
| 60 | } |