-
Notifications
You must be signed in to change notification settings - Fork 347
/
build.rs
286 lines (268 loc) Β· 9.21 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Clippy errors in this file should not stop build errors being
// reported elsewhere.
// https://github.com/rust-lang/rust-clippy/issues/9534
#![warn(clippy::all)]
// Has false positives on else if chains that sometimes have the same
// body for readability.
#![allow(clippy::if_same_then_else)]
use std::{path::PathBuf, process::Command};
use rayon::prelude::*;
use version_check as rustc;
struct TreeSitterParser {
name: &'static str,
src_dir: &'static str,
extra_files: Vec<&'static str>,
}
impl TreeSitterParser {
fn build(&self) {
let dir = PathBuf::from(&self.src_dir);
let mut c_files = vec!["parser.c"];
let mut cpp_files = vec![];
for file in &self.extra_files {
if file.ends_with(".c") {
c_files.push(file);
} else {
cpp_files.push(file);
}
}
if !cpp_files.is_empty() {
let mut cpp_build = cc::Build::new();
cpp_build
.include(&dir)
.cpp(true)
.std("c++14")
.flag_if_supported("-Wno-implicit-fallthrough")
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-ignored-qualifiers")
.link_lib_modifier("+whole-archive");
for file in cpp_files {
cpp_build.file(dir.join(file));
}
cpp_build.compile(&format!("{}-cpp", self.name));
}
let mut build = cc::Build::new();
if cfg!(target_env = "msvc") {
build.flag("/utf-8");
}
build.include(&dir).warnings(false); // ignore unused parameter warnings
for file in c_files {
build.file(dir.join(file));
}
build.link_lib_modifier("+whole-archive");
build.compile(self.name);
}
}
fn main() {
let parsers = vec![
TreeSitterParser {
name: "tree-sitter-ada",
src_dir: "vendored_parsers/tree-sitter-ada-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-clojure",
src_dir: "vendored_parsers/tree-sitter-clojure-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-cmake",
src_dir: "vendored_parsers/tree-sitter-cmake-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-commonlisp",
src_dir: "vendored_parsers/tree-sitter-commonlisp-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-dart",
src_dir: "vendored_parsers/tree-sitter-dart-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-devicetree",
src_dir: "vendored_parsers/tree-sitter-devicetree-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-elisp",
src_dir: "vendored_parsers/tree-sitter-elisp-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-elixir",
src_dir: "vendored_parsers/tree-sitter-elixir-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-elm",
src_dir: "vendored_parsers/tree-sitter-elm-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-elvish",
src_dir: "vendored_parsers/tree-sitter-elvish-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-erlang",
src_dir: "vendored_parsers/tree-sitter-erlang-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-f-sharp",
src_dir: "vendored_parsers/tree-sitter-f-sharp-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-gleam",
src_dir: "vendored_parsers/tree-sitter-gleam-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-hack",
src_dir: "vendored_parsers/tree-sitter-hack-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-hare",
src_dir: "vendored_parsers/tree-sitter-hare-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-hcl",
src_dir: "vendored_parsers/tree-sitter-hcl-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-janet-simple",
src_dir: "vendored_parsers/tree-sitter-janet-simple-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-kotlin",
src_dir: "vendored_parsers/tree-sitter-kotlin-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-latex",
src_dir: "vendored_parsers/tree-sitter-latex-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-newick",
src_dir: "vendored_parsers/tree-sitter-newick-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-nix",
src_dir: "vendored_parsers/tree-sitter-nix-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-pascal",
src_dir: "vendored_parsers/tree-sitter-pascal-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-perl",
src_dir: "vendored_parsers/tree-sitter-perl-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-qmljs",
src_dir: "vendored_parsers/tree-sitter-qmljs-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-r",
src_dir: "vendored_parsers/tree-sitter-r-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-racket",
src_dir: "vendored_parsers/tree-sitter-racket-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-rust",
src_dir: "vendored_parsers/tree-sitter-rust-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-scheme",
src_dir: "vendored_parsers/tree-sitter-scheme-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-scss",
src_dir: "vendored_parsers/tree-sitter-scss-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-sfapex",
src_dir: "vendored_parsers/tree-sitter-sfapex-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-smali",
src_dir: "vendored_parsers/tree-sitter-smali-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-solidity",
src_dir: "vendored_parsers/tree-sitter-solidity-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-sql",
src_dir: "vendored_parsers/tree-sitter-sql-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-swift",
src_dir: "vendored_parsers/tree-sitter-swift-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-vhdl",
src_dir: "vendored_parsers/tree-sitter-vhdl-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-zig",
src_dir: "vendored_parsers/tree-sitter-zig-src",
extra_files: vec![],
},
];
// Only rerun if relevant files in the vendored_parsers/ directory change.
for parser in &parsers {
println!("cargo:rerun-if-changed={}", parser.src_dir);
}
parsers.par_iter().for_each(|p| p.build());
commit_info();
if let Some((version, _, _)) = rustc::triple() {
println!("cargo:rustc-env=DFT_RUSTC_VERSION={}", version);
}
}
fn commit_info() {
if !PathBuf::from(".git").exists() {
return;
}
let output = match Command::new("git")
.arg("log")
.arg("-1")
.arg("--date=short")
.arg("--format=%H %h %cd")
.output()
{
Ok(output) if output.status.success() => output,
_ => return,
};
let stdout = String::from_utf8(output.stdout).unwrap();
let mut parts = stdout.split_whitespace();
let mut next = || parts.next().unwrap();
let _commit_hash = next();
println!("cargo:rustc-env=DFT_COMMIT_SHORT_HASH={}", next());
println!("cargo:rustc-env=DFT_COMMIT_DATE={}", next())
}