Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ repositories {
mavenCentral()
}

String sharedObject = "libjava-tree-sitter"

task buildSharedObject {
inputs.file "lib/ai_serenade_treesitter_Languages.cc"
inputs.file "lib/ai_serenade_treesitter_Languages.h"
inputs.file "lib/ai_serenade_treesitter_TreeSitter.cc"
inputs.file "lib/ai_serenade_treesitter_TreeSitter.h"
outputs.file "libjava-tree-sitter.so"
outputs.file "${sharedObject}.dylib"
outputs.file "${sharedObject}.so"

doLast {
exec {
commandLine "./build.py", "libjava-tree-sitter", "src/test/tree-sitter-python"
commandLine "./build.py", "-a", "${System.getProperty("os.arch")}", "src/test/tree-sitter-python", "-o", "${sharedObject}"
}
}
}

clean {
delete "libjava-tree-sitter.dylib"
delete "libjava-tree-sitter.so"
}

Expand Down Expand Up @@ -72,5 +76,5 @@ test {
events "passed", "skipped", "failed"
}

environment "JAVA_TREE_SITTER", "${project.projectDir.toString()}/libjava-tree-sitter.so"
environment "JAVA_TREE_SITTER", "${project.projectDir.toString()}/libjava-tree-sitter.${System.getProperty("os.name").equalsIgnoreCase("mac os x") ? "dylib" : "so"}"
}
13 changes: 6 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
def build(repositories, output_path="libjava-tree-sitter", arch=None, verbose=False):
if arch and platform.system() != "Darwin":
arch = "64" if "64" in arch else "32"
if arch and platform.system() == "Darwin":
arch = "arm64" if "aarch64" in arch else arch

output_path = f"{output_path}.{'dylib' if platform.system() == 'Darwin' else 'so'}"
here = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -31,7 +33,6 @@ def build(repositories, output_path="libjava-tree-sitter", arch=None, verbose=Fa
f"{env} make -C {os.path.join(here, 'tree-sitter')} {'> /dev/null' if not verbose else ''}"
)

cpp = False
source_paths = [
os.path.join(here, "lib", "ai_serenade_treesitter_TreeSitter.cc"),
os.path.join(here, "lib", "ai_serenade_treesitter_Languages.cc"),
Expand All @@ -44,7 +45,6 @@ def build(repositories, output_path="libjava-tree-sitter", arch=None, verbose=Fa
scanner_c = os.path.join(src_path, "scanner.c")
scanner_cc = os.path.join(src_path, "scanner.cc")
if os.path.exists(scanner_cc):
cpp = True
source_paths.append(scanner_cc)
elif os.path.exists(scanner_c):
source_paths.append(scanner_c)
Expand All @@ -55,11 +55,10 @@ def build(repositories, output_path="libjava-tree-sitter", arch=None, verbose=Fa
)

source_mtimes = [os.path.getmtime(__file__)] + [os.path.getmtime(path) for path in source_paths]
if cpp:
if ctypes.util.find_library("stdc++"):
compiler.add_library("stdc++")
elif ctypes.util.find_library("c++"):
compiler.add_library("c++")
if ctypes.util.find_library("stdc++"):
compiler.add_library("stdc++")
elif ctypes.util.find_library("c++"):
compiler.add_library("c++")

output_mtime = os.path.getmtime(output_path) if os.path.exists(output_path) else 0
if max(source_mtimes) <= output_mtime:
Expand Down
1 change: 1 addition & 0 deletions lib/ai_serenade_treesitter_TreeSitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Java_ai_serenade_treesitter_TreeSitter_treeCursorCurrentTreeCursorNode(

JNIEXPORT void JNICALL Java_ai_serenade_treesitter_TreeSitter_treeCursorDelete(
JNIEnv* env, jclass self, jlong cursor) {
ts_tree_cursor_delete((TSTreeCursor*)cursor);
delete (TSTreeCursor*)cursor;
}

Expand Down