device-driver-core 2.1.0

Internal compiler crate for the device-driver toolkit
Documentation
use std::process;

fn main() {
    println!(
        "cargo:rustc-env=BUILDRS_GIT_SHA={}",
        get_git_sha().as_deref().unwrap_or("unknown")
    );
}

fn get_git_sha() -> Option<String> {
    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();

    let output = process::Command::new("git")
        .current_dir(&manifest_dir)
        .arg("rev-parse")
        .arg("HEAD")
        .output()
        .ok()?;
    let sha = String::from_utf8(output.stdout).unwrap();

    let output = process::Command::new("git")
        .current_dir(&manifest_dir)
        .arg("status")
        .arg("--porcelain")
        .output()
        .ok()?;
    let dirty = !output.stdout.is_empty();

    Some(format!(
        "{}{}",
        sha.trim(),
        if dirty { "-dirty" } else { "" }
    ))
}