-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
38 lines (30 loc) · 933 Bytes
/
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
use cmd_lib::run_fun;
use std::fs::File;
use std::io::Write;
fn main() {
#[cfg(target_os = "windows")]
set_windows_info();
let _ = write_app_version();
}
#[allow(unused)]
fn build_log(msg: &str) {
let mut file = File::create("build.log").unwrap();
_ = file.write(msg.as_bytes());
}
fn write_app_version() -> Result<(), Box<dyn std::error::Error>> {
let tags = run_fun!(git describe --tags --abbrev=0)?
.split(char::is_whitespace)
.map(|s| s.to_owned())
.collect::<Vec<String>>();
let output = if let Some(version) = tags.last() {
format!(r#"pub static VERSION: &str = "{}";"#, version)
} else {
format!(r#"pub static VERSION: &str = "{}";"#, "0.0.1")
};
let _ = std::fs::write("src/version.rs", output);
Ok(())
}
#[cfg(target_os = "windows")]
fn set_windows_info() {
embed_resource::compile("./windows/icon.rc", embed_resource::NONE);
}