-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
76 lines (60 loc) · 1.57 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
use {cc::Build, std::path::PathBuf};
struct Parser<'a> {
name: &'a str,
src: &'a str,
extra: Vec<&'a str>,
}
impl Parser<'_> {
fn build(&self) {
let path = PathBuf::from(self.src);
let mut files = vec!["parser.c"];
files.extend(self.extra.clone());
let c = files
.iter()
.filter(|file| file.ends_with(".c"))
.cloned()
.collect::<Vec<&str>>();
let mut build = Build::new();
build.include(&path).warnings(false);
c.iter().for_each(|file| {
build.file(path.join(file));
});
build.compile(self.name);
let cpp = files
.iter()
.filter(|file| !file.ends_with(".c"))
.cloned()
.collect::<Vec<&str>>();
if !cpp.is_empty() {
let mut build = cc::Build::new();
build
.include(&path)
.warnings(false)
.cpp(true)
.flag_if_supported("-Wno-implicit-fallthrough")
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-ignored-qualifiers")
.flag_if_supported("-Wno-return-type");
build.flag(if cfg!(windows) {
"/std:c++14"
} else {
"--std=c++14"
});
cpp.iter().for_each(|file| {
build.file(path.join(file));
});
build.compile(&format!("{}-cpp", self.name));
}
}
}
fn main() {
let parsers = vec![Parser {
name: "tree-sitter-just",
src: "vendor/tree-sitter-just-src",
extra: vec!["scanner.c"],
}];
for parser in &parsers {
println!("cargo:rerun-if-changed={}", parser.src);
}
parsers.iter().for_each(|parser| parser.build());
}