-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
55 lines (43 loc) · 1.53 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
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "web")]
compile_web_ui().unwrap();
Ok(())
}
#[cfg(feature = "web")]
pub fn compile_web_ui() -> std::io::Result<()> {
use std::env;
use std::fs::create_dir_all;
use std::path::PathBuf;
use cargo_toml::Manifest;
use static_files::resource_dir;
const CARGO_MANIFEST_DIR: &str = "CARGO_MANIFEST_DIR";
const OUT_DIR: &str = "OUT_DIR";
let cargo_manifest_dir = PathBuf::from(env::var(CARGO_MANIFEST_DIR).unwrap());
let cargo_toml = cargo_manifest_dir.join("Cargo.toml");
let out_dir = PathBuf::from(env::var(OUT_DIR).unwrap());
let ui_path = out_dir.join("ui");
let manifest = Manifest::from_path(cargo_toml).unwrap();
let manifest = manifest
.package
.expect("package not specified in Cargo.toml")
.metadata
.expect("no metadata specified in Cargo.toml");
let metadata = manifest
.get("ui")
.expect("UI Metadata not defined correctly");
let url = metadata["assets-url"].as_str().unwrap();
let build_zip = ureq::get(url)
.call()
.map(|data| {
let mut buf: Vec<u8> = Vec::new();
data.into_reader().read_to_end(&mut buf).unwrap();
buf
})
.expect("Failed to get resource from {url}");
create_dir_all(&ui_path)?;
let mut zip = zip::read::ZipArchive::new(std::io::Cursor::new(&build_zip))?;
zip.extract(&ui_path)?;
resource_dir(ui_path.join("dist")).build()?;
Ok(())
}