-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
74 lines (61 loc) · 1.88 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
// https://github.com/tree-sitter/tree-sitter/blob/master/lib/binding_rust/README.md
struct LangDir {
lang_name: &'static str,
path: &'static str,
scanner_name: &'static str,
scanner_cplusplus: bool,
}
static OCAML_LANG: LangDir = LangDir {
lang_name: "ocaml",
path: "parsers/ocaml/ocaml/src",
scanner_name: "scanner.cc",
scanner_cplusplus: true,
};
static RUST_LANG: LangDir = LangDir {
lang_name: "rust",
path: "parsers/rust/src",
scanner_name: "scanner.c",
scanner_cplusplus: false,
};
static DART_LANG: LangDir = LangDir {
lang_name: "dart",
path: "parsers/dart/src",
scanner_name: "scanner.c",
scanner_cplusplus: false,
};
static JS_LANG: LangDir = LangDir {
lang_name: "js",
path: "parsers/js/src",
scanner_name: "scanner.c",
scanner_cplusplus: false,
};
impl LangDir {
fn scanner_path(&self) -> String {
format!("{}/{}", self.path, self.scanner_name)
}
fn parser_path(&self) -> String {
format!("{}/parser.c", self.path)
}
}
static LANGS: [&LangDir; 4] = [&OCAML_LANG, &RUST_LANG, &DART_LANG, &JS_LANG];
fn main() {
for lang in LANGS.iter() {
let scanner_path = lang.scanner_path();
let parser_path = lang.parser_path();
println!("cargo:rerun-if-changed={}", scanner_path);
println!("cargo:rerun-if-changed={}", parser_path);
cc::Build::new()
.include(lang.path)
.file(parser_path)
.warnings(false)
.compile(&format!("{}_parser", lang.lang_name));
cc::Build::new()
.include(lang.path)
.file(scanner_path)
.cpp(lang.scanner_cplusplus)
.warnings(false)
.compile(&format!("{}_scanner", lang.lang_name));
}
let hash = rustc_tools_util::get_commit_hash().unwrap_or_default();
println!("cargo:rustc-env=GIT_HASH={}", hash);
}