-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
32 lines (27 loc) · 924 Bytes
/
build.rs
File metadata and controls
32 lines (27 loc) · 924 Bytes
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
use std::{path::PathBuf, process::Command};
fn main() {
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
// println!("cargo:rustc-env=GIT_HASH={}", git_hash);
let build_id = format!(
"#{} {}",
git_hash.trim(),
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S")
);
println!("cargo:rustc-env=BUILD_ID={}", build_id);
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let mut out_dir2 = out_dir.as_path();
loop {
out_dir2 = out_dir2.parent().unwrap();
if out_dir2.ends_with("build") {
out_dir2 = out_dir2.parent().unwrap();
break;
}
}
let out_path = out_dir2.join("build_id");
std::fs::write(out_path, build_id).unwrap();
embuild::espidf::sysenv::output();
}