-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.rs
More file actions
87 lines (71 loc) · 1.76 KB
/
build.rs
File metadata and controls
87 lines (71 loc) · 1.76 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
use {
cc::Build,
std::path::{Path, PathBuf},
};
struct Parser<'a> {
extra: Vec<&'a str>,
name: &'a str,
src: &'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| {
Path::new(file)
.extension()
.is_some_and(|extension| extension.eq_ignore_ascii_case("c"))
})
.copied()
.collect::<Vec<&str>>();
let mut build = Build::new();
build.include(&path).warnings(false);
for file in &c {
build.file(path.join(file));
}
build.compile(self.name);
let cpp = files
.iter()
.filter(|file| {
!Path::new(file)
.extension()
.is_some_and(|extension| extension.eq_ignore_ascii_case("c"))
})
.copied()
.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"
});
for file in &cpp {
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::build);
}