forked from michaelb/sniprun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
100 lines (88 loc) · 2.41 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
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
91
92
93
94
95
96
97
98
99
100
use std::fs;
use std::path::Path;
// fn build_tree_sitter(language_name: &str) {
// let dir: PathBuf = ["ressources", language_name, "src"].iter().collect();
//
// cc::Build::new()
// .include(&dir)
// .file(dir.join("parser.c"))
// .file(dir.join("scanner.c"))
// .compile(language_name);
// }
fn main() -> Result<(), std::io::Error> {
// build_tree_sitter("tree-sitter-rust");
//clarify this
let out_dir = "src/interpreters";
let dest_path = Path::new(&out_dir).join("mod.rs");
let mut string_to_write = "".to_string();
for path in fs::read_dir(out_dir).unwrap() {
let plugin = path.unwrap().file_name().into_string().unwrap();
if plugin == "mod.rs" || plugin == "example.rs" {
continue;
}
if !plugin.ends_with(".rs") {
// not a rust file
continue;
}
string_to_write.push_str(&format!(
"include!(\"{}\");
",
plugin
));
}
string_to_write.push_str(
"#[macro_export]
macro_rules! iter_types {
($($code:tt)*) => {
",
);
for path in fs::read_dir(out_dir).unwrap() {
let mut plugin = path.unwrap().file_name().into_string().unwrap();
if plugin == "mod.rs" || plugin == "import.rs" || plugin == "example.rs" {
continue;
}
if !plugin.ends_with(".rs") {
// not a rust file
continue;
}
plugin = plugin[..plugin.len() - 3].to_string();
string_to_write.push('{');
string_to_write.push_str(&format!(
"
type Current = interpreters::{};
$(
$code
)*
",
plugin,
));
string_to_write.push_str("};");
}
string_to_write.push_str(
"
};
}
",
);
// cargo stuff for rebuild
for path in fs::read_dir(out_dir).unwrap() {
let _plugin_path = path.unwrap().path().display();
}
println!(
"cargo:rerun-if-changed=build.rs
"
);
println!(
"cargo:rerun-if-changed={}
",
out_dir
);
for path in fs::read_dir(out_dir).unwrap() {
println!(
"cargo:rerun-if-changed={}
",
path.unwrap().path().display()
);
}
fs::write(&dest_path, string_to_write)
}