Skip to content
Closed
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
24 changes: 18 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ on:
paths-ignore:
- "**/README.md"
jobs:
test:
name: Test on ${{ matrix.os }}
native:
name: Build native on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-15-intel, macos-14]
include:
- os: ubuntu-22.04
targets: x86_64-linux-gnu,aarch64-linux-gnu
- os: windows-2022
targets: x86_64-windows
- os: macos-15-intel
targets: x86_64-macos
- os: macos-14
targets: aarch64-macos
env:
ORG_GRADLE_PROJECT_ossrhUsername: na
ORG_GRADLE_PROJECT_ossrhPassword: na
Expand All @@ -26,8 +34,12 @@ jobs:
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4.2.1
- name: Test with Gradle
run: ./gradlew test --stacktrace
- name: Build native libraries with Gradle
run: >
./gradlew
buildNative
-PtreeSitterTargets=${{ matrix.targets }}
--stacktrace

android-native:
name: Build Android native library
Expand All @@ -51,4 +63,4 @@ jobs:
run: |
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" "ndk;${ANDROID_NDK_VERSION}"
- name: Build Android native library
run: ./gradlew :tree-sitter:buildNative -PtreeSitterTargets=aarch64-linux-android --stacktrace
run: ./gradlew buildNative -PtreeSitterTargets=aarch64-linux-android --stacktrace
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,21 @@ subprojects {
useJUnitPlatform()
}

tasks.register('downloadSource', DownloadSourceTask)
if (project.hasProperty('libVersion')) {
tasks.register('downloadSource', DownloadSourceTask)

if (project.name != 'tree-sitter' && project.name != 'tree-sitter-demo' && project.name != 'tree-sitter-tests') {
tasks.named('test') {
dependsOn tasks.named('downloadSource')
tasks.register('buildNative', BuildNativeTask) {
zigExe = rootProject.downloadZig.zigExe
dependsOn downloadSource, rootProject.downloadZig
if (((String) rootProject.properties.get("treeSitterTargets")).contains("android")) {
dependsOn rootProject.downloadAndroidNdk
}
}
}

tasks.register('buildNative', BuildNativeTask) {
zigExe = rootProject.downloadZig.zigExe
dependsOn downloadSource, rootProject.downloadZig
if (((String) rootProject.properties.get("treeSitterTargets")).contains("android")) {
dependsOn rootProject.downloadAndroidNdk
if (project.name != 'tree-sitter') {
tasks.named('test') {
dependsOn tasks.named('downloadSource')
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions buildSrc/src/main/groovy/BuildNativeTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ class BuildNativeTask extends DefaultTask{
cmd.addAll(jniCFiles)
cmd.addAll(parserCFiles)
cmd.addAll(additionalCFiles)
project.exec{
project.providers.exec {
workingDir jniCDir
commandLine(cmd)
}
}.result.get()
}
this.removeWindowsDebugFiles()
}
Expand Down Expand Up @@ -220,6 +220,12 @@ class BuildNativeTask extends DefaultTask{
}

def sdkDir = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if (!sdkDir) {
def defaultSdk = new File(System.getProperty("user.home"), "Library/Android/sdk")
if (defaultSdk.exists()) {
sdkDir = defaultSdk.absolutePath
}
}
if (sdkDir) {
def ndkRoot = new File(sdkDir, "ndk")
def ndks = ndkRoot.listFiles()?.findAll { it.isDirectory() }?.sort { a, b -> b.name <=> a.name }
Expand All @@ -237,7 +243,7 @@ class BuildNativeTask extends DefaultTask{
throw new GradleException("Android NDK not found. Set ANDROID_NDK_HOME, ANDROID_NDK_ROOT, ANDROID_HOME, or ANDROID_SDK_ROOT, or run the downloadAndroidNdk task.")
}

private void removeWindowsDebugFiles(){
void removeWindowsDebugFiles(){
def files = jniOutDir.asFileTree.matching {
include("**/*.pdb")
include("**/*.lib")
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/src/main/groovy/DownloadAndroidNdkTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class DownloadAndroidNdkTask extends DefaultTask {
}

def sdkDir = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if (!sdkDir) {
def defaultSdk = new File(System.getProperty("user.home"), "Library/Android/sdk")
if (defaultSdk.exists()) {
sdkDir = defaultSdk.absolutePath
}
}
if (sdkDir) {
def ndkRoot = new File(sdkDir, "ndk")
def ndks = ndkRoot.listFiles()?.findAll { it.isDirectory() }?.sort { a, b -> b.name <=> a.name }
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/groovy/DownloadZigTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ class DownloadZigTask extends DefaultTask{
def mirrorUrls = mirrorUrls()
downloadZigFromMirrors(mirrorUrls, zigZipFile.asFile, zigSignatureFile.asFile)
miniSignExe.asFile.setExecutable(true, true)
def zipVerified = project.exec {
def zipVerified = project.providers.exec {
ignoreExitValue = true
workingDir zigDir.asFile
commandLine miniSignExe,
"-qVm",
zigZipFile,
"-P",
zigPubKey
}
}.result.get().exitValue == 0
if(!zipVerified) {
throw new GradleException("$zigZipFile signature does not match!")
}
Expand Down
Binary file not shown.
Binary file modified tree-sitter-css/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-css.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-css/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-css.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-css/src/main/resources/lib/x86_64-windows-tree-sitter-css.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-go/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-go.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-go/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-go.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-go/src/main/resources/lib/x86_64-windows-tree-sitter-go.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-html/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-html.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-html/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-html.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-html/src/main/resources/lib/x86_64-windows-tree-sitter-html.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-java/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-java.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-java/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-java.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-java/src/main/resources/lib/x86_64-windows-tree-sitter-java.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-javascript/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-javascript.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-javascript/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-javascript.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-javascript/src/main/resources/lib/x86_64-windows-tree-sitter-javascript.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-json/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-json.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-json/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-json.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-json/src/main/resources/lib/x86_64-windows-tree-sitter-json.dll
100644 → 100755
Binary file not shown.
10 changes: 9 additions & 1 deletion tree-sitter-ocaml/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
tasks.named('downloadSource') {
url = "https://github.com/tree-sitter/tree-sitter-ocaml/archive/refs/tags/v${libVersion}.zip"
}
}

tasks.named("buildNative") {
def newSrcDir = srcDir.dir("grammars/ocaml/src")
additionalCFiles = newSrcDir.asFileTree.matching {
include("**/*.c")
}
additionalIncludeDirs = [newSrcDir]
}
Binary file not shown.
Binary file modified tree-sitter-python/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-python.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-python/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-python.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-python/src/main/resources/lib/x86_64-windows-tree-sitter-python.dll
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-typescript/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-typescript.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-typescript/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-typescript.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter-typescript/src/main/resources/lib/x86_64-windows-tree-sitter-typescript.dll
100644 → 100755
Binary file not shown.
4 changes: 2 additions & 2 deletions tree-sitter/src/main/c/org_treesitter_TSParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ JavaVM* java_vm = NULL;

jint JNI_OnLoad(JavaVM* vm, void* reserved) {
java_vm = vm;
return JNI_VERSION_10;
return JNI_VERSION_1_6;
}

jfieldID ts_jni_get_field_id(JNIEnv *env, jclass clz, const char *field_name, const char*field_type){
Expand Down Expand Up @@ -2050,4 +2050,4 @@ JNIEXPORT jlong JNICALL Java_org_treesitter_TSParser_ts_1load_1lang

const TSLanguage *ts_lang = lang_fn();
return (jlong) ts_lang;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public synchronized static void loadLib(String libName) {
if (loadedLibs.contains(libName)) {
return;
}
String vmName = System.getProperty("java.vm.name", "").toLowerCase();
String runtimeName = System.getProperty("java.runtime.name", "").toLowerCase();
boolean isAndroid = vmName.contains("dalvik") || runtimeName.contains("android");
if (isAndroid) {
String[] parts = libName.split("/");
System.loadLibrary(parts[parts.length - 1]);
loadedLibs.add(libName);
return;
}
Path path = libFile(libName);
System.load(path.toAbsolutePath().toString());
loadedLibs.add(libName);
Expand Down
Binary file not shown.
Binary file modified tree-sitter/src/main/resources/lib/aarch64-linux-gnu-tree-sitter.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter/src/main/resources/lib/x86_64-linux-gnu-tree-sitter.so
100644 → 100755
Binary file not shown.
Binary file not shown.
Binary file modified tree-sitter/src/main/resources/lib/x86_64-windows-tree-sitter.dll
100644 → 100755
Binary file not shown.
Loading