BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / build.rs

build.rs

build.rs 1.9 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 println!("cargo:rerun-if-env-changed=GITHUB_REF_NAME");
18 println!("cargo:rerun-if-env-changed=GITHUB_REF_TYPE");
19 let release_tag = std::env::var("GITHUB_REF_NAME")
20 .ok()
21 .filter(|_| std::env::var("GITHUB_REF_TYPE").as_deref() == Ok("tag"))
22 .filter(|tag| tag.starts_with('v'));
23 if let Some(tag) = release_tag {
24 println!("cargo:rustc-env=TEAMS_RELEASE_TAG={tag}");
25 }
26 // Rerun only when HEAD moves, so an unchanged tree does not recompile the whole app crate.
27 if let Some(head) = git(&["rev-parse", "--path-format=absolute", "--git-path", "HEAD"]) {
28 println!("cargo:rerun-if-changed={head}");
29 }
30 if let Some(reference) = git(&["symbolic-ref", "-q", "HEAD"])
31 .and_then(|reference| git(&["rev-parse", "--path-format=absolute", "--git-path", &reference]))
32 {
33 println!("cargo:rerun-if-changed={reference}");
34 }
35 if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
36 println!("cargo:rerun-if-changed=assets/icon/teams-fast.ico");
37 println!("cargo:rerun-if-changed=assets/icon/app.rc");
38 embed_resource::compile("assets/icon/app.rc", embed_resource::NONE)
39 .manifest_optional()
40 .unwrap();
41 }
42 println!("cargo:rerun-if-changed=build.rs");
43}