-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
44 lines (42 loc) · 1.49 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
fn update_version() {
let git_desc = match Command::new("git")
.args(&["describe", "--tags", "--long", "--always", "--match=v*.*", "--dirty"])
.output()
{
Ok(output) =>
if output.status.success() {
String::from_utf8(output.stdout)
.unwrap_or("git-desc-badstr".to_string())
.trim_end()
.to_string()
} else {
"git-desc-error".to_string()
},
Err(_) => "git-desc-failed".to_string(),
};
let version_source = format!("pub const GIT_DESC: &'static str = \"{}\";\n", git_desc);
let out_dir = env::var_os("OUT_DIR").unwrap();
let version_path = Path::new(&out_dir).join("version.rs");
let old_version_source =
String::from_utf8(fs::read(&version_path).unwrap_or(vec![])).unwrap_or("".to_string());
if version_source != old_version_source {
fs::write(&version_path, version_source).unwrap();
}
// run if git HEAD changes
if Path::new("../.git/logs/HEAD").exists() {
println!("cargo:rerun-if-changed=../.git/logs/HEAD");
} else {
println!("cargo:rerun-if-changed=../../.git/modules/vls/logs/HEAD");
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
update_version();
tonic_build::configure()
.build_server(true)
.compile_protos(&["src/grpc/hsmd.proto"], &["src/grpc"])?;
Ok(())
}