summaryrefslogtreecommitdiff
path: root/build.rs
blob: de1f754794416555a664ab6668652359fe5623b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// (c) 2023 Cory Forsstrom
// (c) 2024-2025 Polesznyák Márk László

use std::path::Path;
use std::process::Command;

fn main() {
    println!("cargo::rerun-if-changed=fonts/icons.toml");
    iced_fontello::build("fonts/icons.toml").expect("Build icons font");
    #[cfg(windows)]
    {
        embed_resource::compile(
            "assets/windows/iced_builder.rc",
            embed_resource::NONE,
        );
        windows_exe_info::versioninfo::link_cargo_env();
    }

    let git_hash = Command::new("git")
        .args(["describe", "--always", "--dirty", "--exclude='*'"])
        .output()
        .ok()
        .filter(|output| output.status.success())
        .and_then(|x| String::from_utf8(x.stdout).ok());

    if let Some(hash) = git_hash.as_ref() {
        println!("cargo:rustc-env=GIT_HASH={}", hash);
    }

    if git_hash.is_none() {
        return;
    }

    let Some(git_dir): Option<String> = Command::new("git")
        .args(["rev-parse", "--git-dir"])
        .output()
        .ok()
        .filter(|output| output.status.success())
        .and_then(|x| String::from_utf8(x.stdout).ok())
    else {
        return;
    };

    let head = Path::new(&git_dir).join("HEAD");
    if head.exists() {
        println!("cargo:rerun-if-changed={}", head.display());
    }

    let Some(head_ref): Option<String> = Command::new("git")
        .args(["symbolic-ref", "HEAD"])
        .output()
        .ok()
        .filter(|output| output.status.success())
        .and_then(|x| String::from_utf8(x.stdout).ok())
    else {
        return;
    };
    let head_ref = Path::new(&git_dir).join(head_ref);
    if head_ref.exists() {
        println!("cargo:rerun-if-changed={}", head_ref.display());
    }
}