-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
48 lines (43 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
use cbindgen::{self, Language};
use std::{env, path::PathBuf};
fn main() {
compile_tree_sitter_languages();
generate_c_bindings();
}
fn compile_tree_sitter_languages() {
for (language, files) in &[
// ("go", &["parser.c", "scanner.c"]),
("javascript", &["parser.c", "scanner.c"]),
// ("python", &["parser.c", "scanner.c"]),
("rust", &["parser.c", "scanner.c"]),
] {
let package = format!("tree-sitter-{}", language);
let srcdir = format!("{}/src", package);
let mut build = cc::Build::new();
build.flag("-Wno-unused-parameter");
build.flag("-Wno-unused-but-set-variable");
for file in *files {
let srcfile = format!("{}/{}", srcdir, file);
println!("cargo:rerun-if-changed={}", srcfile);
build.file(srcfile);
}
build.include(srcdir);
build.compile(&package);
}
}
fn generate_c_bindings() {
let mut config = cbindgen::Config::default();
config.include_guard = Some("__hial_h".into());
config.autogen_warning =
Some("/* !!! DO NOT MANUALLY MODIFY !!! Autogenerated by cbindgen. */".into());
config.language = Language::C;
config.includes = vec![];
config.sys_includes = vec!["stdint.h".into()];
config.no_includes = true;
let crate_dir = PathBuf::from(
env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env var is not defined"),
);
cbindgen::generate_with_config(&crate_dir, config)
.expect("Unable to generate bindings")
.write_to_file(crate_dir.join("hial.h"));
}