-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.py
54 lines (43 loc) · 1.41 KB
/
build.py
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
from subprocess import run
from node_generator import generate
SO = "so"
def build_main_lib():
print(" -- building main libraries")
native_lib_dir = "tree-sitter/lib/src"
dotnet_lib_dir = "TreeSitter"
run([
"gcc",
"-fPIC",
"-shared",
"-o", f"{dotnet_lib_dir}/tree-sitter.{SO}",
f"{native_lib_dir}/lib.c",
"free.c",
f"-I{native_lib_dir}",
f"-I{native_lib_dir}/../include",
], check=True)
def build_lang(native_name, cs_name, *files):
print(" -- building", native_name, "language support")
print(" -- building native library")
native_dir = f"langs-native/tree-sitter-{native_name}/src"
dotnet_dir = f"TreeSitter.{cs_name}"
run([
"gcc",
"-fPIC",
"-shared",
"-o", f"{dotnet_dir}/tree-sitter-{native_name}.{SO}",
*[f"{native_dir}/{file}" for file in files],
f"-I{native_name}"
], check=True)
print(" -- generating support code")
generate(f"{native_dir}/node-types.json", f"{dotnet_dir}/Generated.cs", cs_name)
def build_managed():
print(" -- building dotnet libraries")
run(["dotnet", "build"], check=True)
def main():
build_main_lib()
build_lang("c", "C", "parser.c")
build_lang("javascript", "JavaScript", "parser.c", "scanner.c")
build_lang("python", "Python", "parser.c", "scanner.cc")
build_managed()
if __name__ == '__main__':
main()