-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (49 loc) · 1.68 KB
/
build.rs
File metadata and controls
54 lines (49 loc) · 1.68 KB
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
use std::{fs::File, io::Write, path::PathBuf, process::Command};
fn main() {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR is required"));
let vite_out_dir = out_dir.join("vite-dist");
// Vite always seems to update the mtime of the project folder on each build, so track the files that we know matter individually
for tracked_file in [
"package.json",
"../yarn.lock",
"index.html",
"public",
"src",
"tsconfig.json",
"vite.config.ts",
] {
println!("cargo:rerun-if-changed={tracked_file}");
}
let mut vite_command = Command::new("yarn");
vite_command
.arg("run")
.arg("build")
.arg("--outDir")
.arg(&vite_out_dir)
.arg("--base")
.arg("/ui/");
let vite_status = vite_command.status();
match vite_status {
Ok(vite_status) if vite_status.success() => {}
_ => panic!("web-ui build failed: command {vite_command:?} resulted in {vite_status:?}"),
};
let mut asset_map = phf_codegen::Map::new();
for asset_file in vite_out_dir.join("assets").read_dir().unwrap() {
let asset_file = asset_file.unwrap();
let asset_file_name = asset_file.file_name();
let asset_file_path = asset_file.path();
asset_map.entry(
asset_file_name
.to_str()
.expect("asset filename must be valid UTF-8")
.to_string(),
format!("include_bytes!({asset_file_path:?})"),
);
}
write!(
File::create(out_dir.join("vite-asset-map.rs")).unwrap(),
"{asset_map}",
asset_map = asset_map.build()
)
.unwrap();
}