-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
38 lines (31 loc) · 1.18 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
//! Build script for lib-core
use std::{env, fs::File, io::Write, path::Path, process::Command};
use anyhow::Result;
fn main() -> Result<(), Box<dyn std::error::Error>> {
gen_server_version()?;
Ok(())
}
/// Gen server version
fn gen_server_version() -> Result<()> {
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(())
}