-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
30 lines (27 loc) · 1.1 KB
/
build.rs
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
#![deny(rust_2018_idioms, unused, unused_crate_dependencies, unused_import_braces, unused_lifetimes, unused_qualifications, warnings)]
#![forbid(unsafe_code)]
use {
std::{
env,
fs::File,
io::{
self,
prelude::*,
},
path::Path,
},
git2::Repository,
};
#[derive(Debug, thiserror::Error)]
enum Error {
#[error(transparent)] Env(#[from] env::VarError),
#[error(transparent)] Git(#[from] git2::Error),
#[error(transparent)] Io(#[from] io::Error),
}
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=nonexistent.foo"); // check a nonexistent file to make sure build script is always run (see https://github.com/rust-lang/cargo/issues/4213 and https://github.com/rust-lang/cargo/issues/3404)
let mut f = File::create(Path::new(&env::var("OUT_DIR")?).join("version.rs"))?;
writeln!(f, "/// The hash of the current commit of the sil repo at compile time.")?;
writeln!(f, "pub(crate) const GIT_COMMIT_HASH: [u8; 20] = {:?};", Repository::open_from_env()?.head()?.peel_to_commit()?.id().as_bytes())?;
Ok(())
}