forked from ducaale/xh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
63 lines (55 loc) · 1.71 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
62
63
use std::env;
use std::fs::read_dir;
use std::path::Path;
use syntect::dumps::dump_to_file;
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSetBuilder;
fn build_syntax(dir: &str, out: &str) {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut builder = SyntaxSetBuilder::new();
builder.add_from_folder(dir, true).unwrap();
let ss = builder.build();
dump_to_file(&ss, Path::new(&out_dir).join(out)).unwrap();
}
fn feature_status(feature: &str) -> String {
if env::var_os(format!(
"CARGO_FEATURE_{}",
feature.to_uppercase().replace('-', "_")
))
.is_some()
{
format!("+{}", feature)
} else {
format!("-{}", feature)
}
}
fn features() -> String {
format!(
"{} {}",
&feature_status("native-tls"),
&feature_status("rustls")
)
}
fn main() {
for dir in [
"assets/syntax",
"assets/syntax/basic",
"assets/syntax/large",
"assets/themes",
] {
println!("cargo:rerun-if-changed={}", dir);
for entry in read_dir(dir).unwrap() {
let path = entry.unwrap().path();
let path = path.to_str().unwrap();
if path.ends_with(".sublime-syntax") || path.ends_with(".tmTheme") {
println!("cargo:rerun-if-changed={}", path);
}
}
}
build_syntax("assets/syntax/basic", "basic.packdump");
build_syntax("assets/syntax/large", "large.packdump");
let out_dir = env::var_os("OUT_DIR").unwrap();
let ts = ThemeSet::load_from_folder("assets/themes").unwrap();
dump_to_file(&ts, Path::new(&out_dir).join("themepack.themedump")).unwrap();
println!("cargo:rustc-env=XH_FEATURES={}", features());
}