-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
60 lines (50 loc) · 2.13 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
use std::path::PathBuf;
fn main() {
let dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
// Get tree-sitter include path from the tree-sitter crate
let tree_sitter_dir = PathBuf::from(std::env::var("DEP_TREE_SITTER_RUNTIME_INCLUDE").unwrap_or_else(|_| {
// Fallback to a common location if the env var is not set
format!("{}/target/debug/build/tree-sitter-*/out", dir.display())
}));
// Compile tree-sitter parsers
println!("cargo:rerun-if-changed=build.rs");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.file(dir.join("tree-sitter-go/src/parser.c"))
.compile("tree-sitter-go");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.file(dir.join("tree-sitter-java/src/parser.c"))
.compile("tree-sitter-java");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.file(dir.join("tree-sitter-javascript/src/parser.c"))
.file(dir.join("tree-sitter-javascript/src/scanner.c"))
.compile("tree-sitter-javascript");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.file(dir.join("tree-sitter-python/src/parser.c"))
.file(dir.join("tree-sitter-python/src/scanner.c"))
.compile("tree-sitter-python");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.file(dir.join("tree-sitter-rust/src/parser.c"))
.file(dir.join("tree-sitter-rust/src/scanner.c"))
.compile("tree-sitter-rust");
cc::Build::new()
.include(&dir)
.include(&tree_sitter_dir)
.include(dir.join("tree-sitter-typescript/typescript/src"))
.include(dir.join("tree-sitter-typescript/common"))
.file(dir.join("tree-sitter-typescript/typescript/src/parser.c"))
.file(dir.join("tree-sitter-typescript/typescript/src/scanner.c"))
.compile("tree-sitter-typescript");
// Add library search path
println!("cargo:rustc-link-search=native={}", out_dir.display());
}