-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
90 lines (75 loc) · 2.4 KB
/
build.rs
File metadata and controls
90 lines (75 loc) · 2.4 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// use std::fs;
// use std::path::Path;
// use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=assets_bundled/");
// Uncomment to build tailwindcss before including assets
/*execute_command(
"chmod".to_string(),
vec!["+x".to_string(), "tailwindcss-linux-x64".to_string()],
);
execute_command(
"./tailwindcss-linux-x64".to_string(),
vec![
"-i".to_string(),
"assets/input.css".to_string(),
"-o".to_string(),
"assets/style.css".to_string(),
"--minify".to_string(),
"-c".to_string(),
"tailwind.config.js".to_string(),
],
);*/
assets::include_asset();
}
// fn execute_command(command: String, args: Vec<String>) {
// let mut cmd = Command::new(command);
// for arg in args {
// cmd.arg(arg);
// }
// cmd.spawn().unwrap().wait().unwrap();
// }
mod assets {
use std::collections::BTreeMap;
use std::fs::{write};
use walkdir::WalkDir;
pub fn include_asset() {
let mut temp = BTreeMap::new();
let entries = WalkDir::new("./assets_bundled")
.into_iter()
.filter_entry(|p| {
p.file_name() != "android"
&& p.file_name() != "windows"
&& p.file_name() != "linux"
&& p.file_name() != "universal"
})
.filter_map(Result::ok);
for entry in entries
{
if entry.file_type().is_file() {
let path = entry.path();
let rel = path.strip_prefix("./").unwrap_or(path);
temp.insert(format!("/{}", rel.to_string_lossy()), rel.to_string_lossy().to_string());
}
}
if temp.is_empty() {
println!("cargo:warning=Empty assets_bundled path");
return;
}
let mut temp_ent = Vec::new();
for s in &temp {
temp_ent.push(format!(
" \"{}\" => include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/{}\")),",
s.0, s.1));
println!("cargo:warning=including file {} in the binary", &s.0);
}
let code = format!(
r#"use phf::phf_map;
pub static ASSETS: phf::Map<&'static str, &'static [u8]> = phf_map! {{
{}
}};"#,
temp_ent.join("\n")
);
write("target/bundled.rs", code).unwrap();
}
}