aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/build.rs
blob: 45cfd4ef74f651fe736eb4a01f8426d01bc0f489 (plain) (blame)
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
use std::process::Command;

fn main() {
    let version = format!(
        "{} {}-{}",
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        commit_hash(),
    );

    println!("cargo:rustc-env=VERSION={}", version);
}

fn commit_hash() -> String {
    let output = Command::new("git")
                         .arg("show")
                         .arg("--pretty=format:%h")  // abbrev hash
                         .current_dir(env!("CARGO_MANIFEST_DIR"))
                         .output();
    if let Ok(output) = output {
        String::from_utf8_lossy(&output.stdout).to_string()
    } else {
        String::from("???")
    }
}