-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
61 lines (50 loc) · 1.44 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use const_gen::*;
use std::{
env,
fs::write,
io::{self, Write},
path::Path,
process::Command,
};
fn main() {
// embed git info
let mut git_ref = git_exec(&["rev-parse", "HEAD"])[0..7].to_string();
let dirty = !git_exec(&["status", "--short"]).is_empty();
if dirty {
git_ref += "*";
}
let code = [
"#[allow(clippy::redundant_static_lifetimes)]",
&const_declaration!(GIT_REF = git_ref),
]
.join("\n");
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("const_gen.rs");
write(dest_path, code).unwrap();
//build fontend
// for some weird reason ci builds fail on this step on windows
#[cfg(windows)]
if std::env::var("CI").is_ok() {
return;
}
println!("cargo:rerun-if-changed=frontend");
pnpm_exec("install");
pnpm_exec("build");
println!("cargo:rerun-if-changed=.git/refs");
}
fn pnpm_exec(cmd: &str) {
println!("running: pnpm {cmd}");
let out = Command::new("pnpm")
.arg(cmd)
.current_dir("frontend")
.output()
.unwrap();
println!("status: {}", out.status);
io::stderr().write_all(&out.stdout).unwrap();
io::stderr().write_all(&out.stderr).unwrap();
}
fn git_exec(cmd: &[&str]) -> String {
println!("running: git {}", cmd.join(" "));
let res = Command::new("git").args(cmd).output().unwrap();
String::from_utf8(res.stdout).unwrap()
}