-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
33 lines (28 loc) · 1.04 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
//! Get git infos
use std::{env, fs::File, io::Write, path::Path, process::Command};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let main_version = env!("CARGO_PKG_VERSION");
let branch = Command::new("git")
.args(["branch", "--show-current"])
.output()
.map(|o| String::from_utf8(o.stdout).unwrap())
.unwrap();
let commit = Command::new("git")
.args(["describe", "--always"])
.output()
.map(|o| String::from_utf8(o.stdout).unwrap())
.unwrap();
let release_mode = if cfg!(debug_assertions) || cfg!(test) {
"DEBUG"
} else {
"RELEASE"
};
let version =
format!("{}-{}-{}-{}", main_version, branch, commit, release_mode).replace('\n', "");
File::create(Path::new(&env::var("OUT_DIR")?).join("VERSION"))?
.write_all(version.trim().as_bytes())?;
// let now = chrono::Local::now().to_rfc3339();
// File::create(Path::new(&env::var("OUT_DIR")?).join("BUILD_TIME"))?
// .write_all(now.trim().as_bytes())?;
Ok(())
}