summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen-shared/build.rs
blob: 8e6ea1b031cdd2e25672a0bf9eaad617e598e04e (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
use std::collections::hash_map::DefaultHasher;
use std::env;
use std::hash::Hasher;
use std::path::PathBuf;
use std::process::Command;

fn main() {
    set_schema_version_env_var();

    let rev = Command::new("git")
        .arg("rev-parse")
        .arg("HEAD")
        .output()
        .ok()
        .map(|s| s.stdout)
        .and_then(|s| String::from_utf8(s).ok());
    if let Some(rev) = rev {
        if rev.len() >= 9 {
            println!("cargo:rustc-env=WBG_VERSION={}", &rev[..9]);
        }
    }
}

fn set_schema_version_env_var() {
    let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").expect(
        "The `CARGO_MANIFEST_DIR` environment variable is needed to locate the schema file",
    );
    let schema_file = PathBuf::from(cargo_manifest_dir).join("src/lib.rs");
    let schema_file = std::fs::read(schema_file).unwrap();

    let mut hasher = DefaultHasher::new();
    hasher.write(&schema_file);

    println!("cargo:rustc-env=SCHEMA_FILE_HASH={}", hasher.finish());
}