aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/build.rs
blob: f09b1c4a2ec350ed48c5fa143261ebe3c299c96c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::process::Command;

fn main() {
    let version = format!(
        "{} {}-{}",
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        commit_hash().unwrap_or_else(|| "???".to_string()),
    );

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

fn commit_hash() -> Option<String> {
    let output = Command::new("git")
                         .arg("show")
                         .arg("--pretty=format:%h")  // abbrev hash
                         .current_dir(env!("CARGO_MANIFEST_DIR"))
                         .output();
    output.ok().map(|o| String::from_utf8_lossy(&o.stdout).to_string())
}