Skip to content

Commit f1f42c1

Browse files
build: patch tree-sitter library lookup
Closes #59
1 parent 353dc66 commit f1f42c1

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ max_line_length = off
1919
[*.{xml,yml,json}]
2020
indent_size = 2
2121
max_line_length = off
22+
23+
[*.ps1]
24+
end_of_line = crlf
25+
26+
[*.patch]
27+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
3+
scripts/jextract.ps1 eol=crlf

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
<arg value="${project.basedir}"/>
9090
<arg value="${project.build.directory}"/>
9191
</exec>
92+
<exec executable="git" dir="${project.build.directory}" failonerror="true">
93+
<arg value="apply"/>
94+
<arg value="--no-index"/>
95+
<arg value="${project.basedir}/scripts/TreeSitter_java.patch"/>
96+
</exec>
9297
</target>
9398
</configuration>
9499
</execution>

scripts/TreeSitter_java.patch

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- a/generated-sources/jextract/io/github/treesitter/jtreesitter/internal/TreeSitter.java
2+
+++ b/generated-sources/jextract/io/github/treesitter/jtreesitter/internal/TreeSitter.java
3+
@@ -55,9 +55,16 @@ public class TreeSitter {
4+
};
5+
}
6+
7+
- static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("tree-sitter"), LIBRARY_ARENA)
8+
- .or(SymbolLookup.loaderLookup())
9+
- .or(Linker.nativeLinker().defaultLookup());
10+
+ static final SymbolLookup SYMBOL_LOOKUP = findLibrary().or(Linker.nativeLinker().defaultLookup());
11+
+
12+
+ private static final SymbolLookup findLibrary() {
13+
+ try {
14+
+ String library = System.mapLibraryName("tree-sitter");
15+
+ return SymbolLookup.libraryLookup(library, LIBRARY_ARENA);
16+
+ } catch (IllegalArgumentException e) {
17+
+ return SymbolLookup.loaderLookup();
18+
+ }
19+
+ }
20+
21+
public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;
22+
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;

scripts/jextract.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/env pwsh
2-
3-
$env:package = 'io.github.treesitter.jtreesitter.internal'
1+
$package = 'io.github.treesitter.jtreesitter.internal'
2+
$output = "$($args[1])/generated-sources/jextract"
3+
$lib = "$($args[0])/core/lib"
44

55
& jextract.bat `
66
--include-struct TSInput `
@@ -177,10 +177,10 @@ $env:package = 'io.github.treesitter.jtreesitter.internal'
177177
--include-constant TSSymbolTypeRegular `
178178
--include-constant TSSymbolTypeSupertype `
179179
--header-class-name TreeSitter `
180-
--output "$($args[1])/generated-sources/jextract" `
181-
-t $env:package `
180+
--output $output `
181+
-t $package `
182182
-l tree-sitter `
183-
-I "$($args[0])/core/lib/src" `
184-
-I "$($args[0])/core/lib/include" `
183+
-I "$lib/src" `
184+
-I "$lib/include" `
185185
-DTREE_SITTER_HIDE_SYMBOLS `
186-
"$($args[0])/core/lib/include/tree_sitter/api.h"
186+
"$lib/include/tree_sitter/api.h"

scripts/jextract.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash -eu
22

33
package=io.github.treesitter.jtreesitter.internal
4+
output="$2/generated-sources/jextract"
5+
lib="$1/core/lib"
46

57
exec jextract \
68
--include-struct TSInput \
@@ -178,10 +180,10 @@ exec jextract \
178180
--include-constant TSSymbolTypeRegular \
179181
--include-constant TSSymbolTypeSupertype \
180182
--header-class-name TreeSitter \
181-
--output "$2"/generated-sources/jextract \
183+
--output "$output" \
182184
-t "$package" \
183185
-l tree-sitter \
184-
-I "$1"/core/lib/src \
185-
-I "$1"/core/lib/include \
186+
-I "$lib/src" \
187+
-I "$lib/include" \
186188
-DTREE_SITTER_HIDE_SYMBOLS \
187-
"$1"/core/lib/include/tree_sitter/api.h
189+
"$lib/include/tree_sitter/api.h"

0 commit comments

Comments
 (0)