Skip to content
build.rs 826 B
Newer Older
theMackabu's avatar
theMackabu committed
use chrono::Datelike;
theMackabu's avatar
theMackabu committed
use std::env;
theMackabu's avatar
theMackabu committed
use std::process::Command;

theMackabu's avatar
theMackabu committed
struct Env {}
impl Env {
    fn git() {
        let output = Command::new("git").args(&["rev-parse", "--short=10", "HEAD"]).output().unwrap();
        println!("cargo:rustc-env=GIT_HASH={}", String::from_utf8(output.stdout).unwrap());
theMackabu's avatar
theMackabu committed
        let output_full = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
        println!("cargo:rustc-env=GIT_HASH_FULL={}", String::from_utf8(output_full.stdout).unwrap());
    }
theMackabu's avatar
theMackabu committed

theMackabu's avatar
theMackabu committed
    fn date() {
        let date = chrono::Utc::now();
        println!("cargo:rustc-env=BUILD_DATE={}-{}-{}", date.year(), date.month(), date.day());
    }
theMackabu's avatar
theMackabu committed

theMackabu's avatar
theMackabu committed
    fn misc() {
        println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
    }
}
theMackabu's avatar
theMackabu committed
fn main() {
    Env::git();
    Env::date();
    Env::misc();
theMackabu's avatar
theMackabu committed
}