-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
409 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
|
||
|
||
import org.treesitter.build.Utils | ||
|
||
plugins { | ||
id 'java' | ||
id 'signing' | ||
id 'maven-publish' | ||
} | ||
|
||
group = 'io.github.bonede' | ||
version = libVersion | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation platform('org.junit:junit-bom:5.9.1') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
implementation project(":tree-sitter") | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
def libName = "tree-sitter-nginx" | ||
|
||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
name = "MavenCentral" | ||
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" | ||
credentials { | ||
username = ossrhUsername | ||
password = ossrhPassword | ||
} | ||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl | ||
} | ||
} | ||
publications { | ||
maven(MavenPublication) { | ||
from components.java | ||
pom { | ||
name = libName | ||
url = 'https://github.com/bonede/tree-sitter-ng' | ||
description = "Next generation Tree Sitter Java binding" | ||
licenses { | ||
license { | ||
name = 'MIT' | ||
} | ||
} | ||
scm { | ||
connection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git' | ||
developerConnection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git' | ||
url = 'https://github.com/bonede/tree-sitter-ng' | ||
} | ||
developers { | ||
developer { | ||
id = 'bonede' | ||
name = 'Wang Liang' | ||
email = '[email protected]' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
signing { | ||
sign configurations.archives | ||
sign publishing.publications | ||
} | ||
tasks.register('downloadSource') { | ||
group = "build setup" | ||
description = "Download parser source" | ||
def zipUrl = "https://gitlab.com/joncoole/tree-sitter-nginx/-/archive/main/tree-sitter-nginx-main.zip" | ||
def downloadDir = Utils.libDownloadDir(project, libName) | ||
def zip = Utils.libZipFile(project, libName, libVersion) | ||
def parserCFile = Utils.libParserCFile(project, libName, libVersion) | ||
inputs.files(layout.projectDirectory.file("gradle.properties")) | ||
outputs.files(parserCFile) | ||
doLast { | ||
download.run { | ||
src zipUrl | ||
dest zip | ||
overwrite false | ||
} | ||
copy { | ||
from zipTree(zip) | ||
into downloadDir | ||
} | ||
} | ||
|
||
} | ||
|
||
tasks.register("buildNative") { | ||
group = "build" | ||
description = "Build parser native modules" | ||
dependsOn "downloadSource", rootProject.bootstrap | ||
def jniSrcDir = Utils.jniSrcDir(project) | ||
def outDir = Utils.jniOutDir(project) | ||
def jniCFile = Utils.jniCFile(project, "org_treesitter_TreeSitterNginx.c") | ||
def parserCFile = Utils.libParserCFile(project, libName, libVersion) | ||
def scannerCFile = Utils.libScannerCFile(project, libName, libVersion) | ||
def libSrcDir = Utils.libSrcDir(project, libName, libVersion) | ||
def jniInclude = Utils.jniIncludeDir(project) | ||
|
||
def targets = Utils.treeSitterTargets(project) | ||
def outputFiles = targets.collect() | ||
{ t -> Utils.jniOutFile(project, t, libName)} | ||
def srcFiles = project.fileTree(libSrcDir) { | ||
include(Utils.libFiles()) | ||
}.toList() | ||
outputs.files(outputFiles) | ||
def inputFiles = srcFiles + [parserCFile, rootProject.layout.projectDirectory.file("gradle.properties")] | ||
inputs.files(inputFiles) | ||
doLast{ | ||
mkdir(outDir) | ||
targets.each {target -> | ||
def jniMdInclude = Utils.jniMdInclude(project, target) | ||
def jniOutFile = Utils.jniOutFile(project, target, libName) | ||
def files = project.fileTree(libSrcDir) { | ||
include(Utils.libFiles()) | ||
}.toList() | ||
def cmd = [ | ||
rootProject.downloadZig.zigExe, "c++", | ||
"-g0", | ||
"-shared", | ||
"-target", target, | ||
"-I", libSrcDir, | ||
"-I", jniInclude, | ||
"-I", jniMdInclude, | ||
"-o", jniOutFile, | ||
jniCFile, | ||
] | ||
|
||
cmd.addAll(files) | ||
exec{ | ||
workingDir jniSrcDir | ||
commandLine(cmd) | ||
} | ||
} | ||
Utils.removeWindowsDebugFiles(project) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libVersion=main |
12 changes: 12 additions & 0 deletions
12
tree-sitter-nginx/src/main/c/org_treesitter_TreeSitterNginx.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
#include <jni.h> | ||
void *tree_sitter_nginx(); | ||
/* | ||
* Class: org_treesitter_TreeSitterNginx | ||
* Method: tree_sitter_nginx | ||
* Signature: ()J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_org_treesitter_TreeSitterNginx_tree_1sitter_1nginx | ||
(JNIEnv *env, jclass clz){ | ||
return (jlong) tree_sitter_nginx(); | ||
} |
23 changes: 23 additions & 0 deletions
23
tree-sitter-nginx/src/main/java/org/treesitter/TreeSitterNginx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
package org.treesitter; | ||
|
||
import org.treesitter.utils.NativeUtils; | ||
|
||
public class TreeSitterNginx implements TSLanguage { | ||
|
||
static { | ||
NativeUtils.loadLib("lib/tree-sitter-nginx"); | ||
} | ||
private native static long tree_sitter_nginx(); | ||
|
||
private final long ptr; | ||
|
||
public TreeSitterNginx() { | ||
ptr = tree_sitter_nginx(); | ||
} | ||
|
||
@Override | ||
public long getPtr() { | ||
return ptr; | ||
} | ||
} |
Binary file added
BIN
+94.5 KB
tree-sitter-nginx/src/main/resources/lib/aarch64-linux-gnu-tree-sitter-nginx.so
Binary file not shown.
Binary file added
BIN
+113 KB
tree-sitter-nginx/src/main/resources/lib/aarch64-macos-tree-sitter-nginx.dylib
Binary file not shown.
Binary file added
BIN
+72.8 KB
tree-sitter-nginx/src/main/resources/lib/x86_64-linux-gnu-tree-sitter-nginx.so
Binary file not shown.
Binary file added
BIN
+77.1 KB
tree-sitter-nginx/src/main/resources/lib/x86_64-macos-tree-sitter-nginx.dylib
Binary file not shown.
Binary file added
BIN
+217 KB
tree-sitter-nginx/src/main/resources/lib/x86_64-windows-tree-sitter-nginx.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
tree-sitter-nginx/src/test/java/org/treesitter/TreeSitterNginxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
package org.treesitter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class TreeSitterNginxTest { | ||
@Test | ||
void init() { | ||
new TreeSitterNginx(); | ||
} | ||
} |
Oops, something went wrong.