-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
36 lines (33 loc) · 1.24 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
use std::path::Path;
use build_deps::rerun_if_changed_paths;
use jsonnet::JsonnetVm;
fn get_level_config_json() -> String {
match std::process::Command::new("jsonnet")
.args(&[
"-J",
"src/levels/config",
"src/levels/config/level_config.jsonnet",
])
.output()
{
Ok(o) if !o.stdout.is_empty() => String::from_utf8(o.stdout).unwrap(),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
let mut vm = JsonnetVm::new();
let out = vm
.evaluate_file("src/levels/config/level_config.jsonnet")
.expect("Failed to parse jsonnet")
.to_string();
out
},
Ok(o) => panic!("{}", String::from_utf8_lossy(&o.stderr)),
Err(e) => panic!("Failed to run {:?}", e),
}
}
fn main() {
rerun_if_changed_paths("src/levels/config/**/*.jsonnet").unwrap();
rerun_if_changed_paths("src/levels/config/**/*.libsonnet").unwrap();
rerun_if_changed_paths("src/levels/config/**/*.json").unwrap();
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("level_config.json");
std::fs::write(&dest_path, &get_level_config_json()).unwrap();
}