-
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathbuild.rs
More file actions
23 lines (20 loc) · 790 Bytes
/
build.rs
File metadata and controls
23 lines (20 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::{fs::File, io::Write};
// Build.rs does not use all provided functions
#[allow(dead_code)]
#[path = "src/git.rs"]
mod git;
fn main() {
let repo_path = git::git_dir(".").unwrap();
let head_path = repo_path.join("HEAD");
println!("cargo:rerun-if-changed={}", head_path.display());
let head = std::fs::read_to_string(&head_path).unwrap();
if let Some(ref_) = head.trim_end().strip_prefix("ref: ") {
let ref_path = repo_path.join(ref_);
assert!(ref_path.is_file());
println!("cargo:rerun-if-changed={}", ref_path.display());
}
let ver = git::repo_hash(".").unwrap_or_else(|| "???".into());
File::create("src/gir_version.rs")
.and_then(|mut f| writeln!(f, "pub const VERSION: &str = \"{ver}\";",))
.unwrap();
}