Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start over #12

Merged
merged 34 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9c29eee
Initialize project (#1)
kubukoz Aug 22, 2022
c289660
Add initial bindings (#2)
kubukoz Oct 13, 2022
1bcbbee
Add node text + fields (#5)
kubukoz Oct 13, 2022
36a569a
Make source more lazy
kubukoz Oct 13, 2022
a9d34e7
remove param from toString
kubukoz Oct 13, 2022
296386b
Update base to 0.2
kubukoz Oct 13, 2022
14381b9
Merge modules for better interop future (#6)
kubukoz Oct 28, 2022
8c8ea67
Scala.js bindings (#7)
kubukoz Oct 29, 2022
3c35feb
disable flake updater
kubukoz Jan 7, 2024
ceeb242
Update native libs (2024-05-17)
kubukoz May 17, 2024
8db4de3
bump everything
kubukoz May 17, 2024
cd7300e
uh
kubukoz May 17, 2024
1c25740
drop nix crap
kubukoz May 17, 2024
7d1c120
drop things
kubukoz May 17, 2024
180ee6a
re-bump sbt
kubukoz May 17, 2024
25e2afb
update CI
kubukoz May 17, 2024
9740c97
scale down more
kubukoz May 17, 2024
f3e6d92
fix demo
kubukoz May 17, 2024
e3ffc4e
remove more
kubukoz May 17, 2024
4d211e1
remove reload
kubukoz May 17, 2024
8760d6e
fix doc
kubukoz May 17, 2024
bcf7d91
Download tree-sitter and build from source
kubukoz May 17, 2024
6dacd1e
Compile python bindings from source
kubukoz May 17, 2024
28784d7
prePR + set explicit jvm version
kubukoz May 17, 2024
0c87a92
jdk 11
kubukoz May 17, 2024
65e42ba
Reuse some code
kubukoz May 17, 2024
d2c3139
Cache the build tasks
kubukoz May 17, 2024
76d403e
refactor
kubukoz May 18, 2024
417d938
Put cached input/output somewhere nested
kubukoz May 18, 2024
017ded6
Start working on an sbt plugin
kubukoz May 18, 2024
b417162
Move compiler logic to plugin
kubukoz May 18, 2024
807017e
prePR
kubukoz May 18, 2024
c79a4c9
Full-blown dogfooding
kubukoz May 18, 2024
f5416e7
Make things actually nice
kubukoz May 18, 2024
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
205 changes: 205 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
pull_request:
branches: ['**', '!update/**', '!pr/**']
push:
branches: ['**', '!update/**', '!pr/**']
tags: [v*]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


concurrency:
group: ${{ github.workflow }} @ ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
scala: [2.13, 3]
java: [temurin@11]
project: [rootJVM]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@11' && steps.setup-java-temurin-11.outputs.cache-hit == 'false'
run: sbt +update

- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

- run: yarn

- name: Check headers and formatting
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: Test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p bindingsPython/.jvm/target core/.jvm/target sbtPlugin/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar bindingsPython/.jvm/target core/.jvm/target sbtPlugin/.jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
uses: actions/upload-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
path: targets.tar

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@11' && steps.setup-java-temurin-11.outputs.cache-hit == 'false'
run: sbt +update

- name: Download target directories (2.13, rootJVM)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-rootJVM

- name: Inflate target directories (2.13, rootJVM)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (3, rootJVM)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-rootJVM

- name: Inflate target directories (3, rootJVM)
run: |
tar xf targets.tar
rm targets.tar

- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
run: echo $PGP_SECRET | base64 -d -i - | gpg --import

- name: Import signing key and strip passphrase
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != ''
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
run: |
echo "$PGP_SECRET" | base64 -d -i - > /tmp/signing-key.gpg
echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)

- name: Publish
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }}
run: sbt tlCiRelease

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@11' && steps.setup-java-temurin-11.outputs.cache-hit == 'false'
run: sbt +update

- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: rootjs_2.13 rootjs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 tests_2.13 tests_3
configs-ignore: test scala-tool scala-doc-tool test-internal
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}

# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }

# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$

# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT

# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do

# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")

# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE

# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))

# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do

# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))

id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/target
.direnv/
.scala-build/
**/target
.bsp/

node_modules/
result
.vscode/
**/.DS_Store
1 change: 1 addition & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-J-Xmx8G
32 changes: 32 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
runner.dialect = "scala213"
version = 3.5.8
maxColumn = 100
align.preset = some

newlines.beforeMultiline = unfold
newlines.topLevelStatements = [before, after]
newlines.topLevelStatementsMinBreaks = 2
newlines.implicitParamListModifierForce = [before]
continuationIndent.defnSite = 2
continuationIndent.extendSite = 2
optIn.breakChainOnFirstMethodDot = true
includeCurlyBraceInSelectChains = true
includeNoParensInSelectChains = true

trailingCommas = "multiple"

rewrite.rules = [
RedundantBraces,
RedundantParens,
ExpandImportSelectors,
PreferCurlyFors
]

runner.optimizer.forceConfigStyleMinArgCount = 3
danglingParentheses.defnSite = true
danglingParentheses.callSite = true
danglingParentheses.exclude = [
"`trait`"
]
verticalMultiline.newlineAfterOpenParen = true
verticalMultiline.atDefnSite = true
13 changes: 13 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2022 treesitter4s contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# treesitter4s

Tree-sitter wrapper for Scala (JVM). Uses JNA to wrap the native library.

## Usage

# Work in progress note

This project is still in the oven and under active development.
Don't assume anything will work or that anything will stay as it is right now.

Feel free to try it if that's okay with you ;)

```scala
libraryDependencies ++= Seq(
// Pure Scala interface - cross-compiled for JVM & JS platforms
"org.polyvariant.treesitter4s" %% "core" % version,
// Bindings for the JVM artifact. Brings in JNA and the native library.
// You probably want to use this one.
"org.polyvariant.treesitter4s" %% "bindings" % version,
// Language support for a specific language.
// There's active work to split these out to separate artifacts.
// "org.polyvariant.treesitter4s" %% "language-scala" % version,
// "org.polyvariant.treesitter4s" %% "language-python" % version,
)
```

## Goals

- **immutable**, read-only, Scala-friendly API
- complete, 1-1 native/Java interface via [JNA](https://github.com/java-native-access/jna)
- binary convenience: no dealing with native libraries if you're on a supported system
- extensible language support

## Supported systems

Support can vary, but the following platforms are considered supported:

- macOS x86_64
- macOS aarch64
- Linux x86_64
- Linux aarch64

CI runs on x86_64 macOS/Linux machines. Development is currently done on an aarch64 Mac.
linux-aarch64 binaries are included thanks to the magic of [Nix](https://nixos.org/) and [Nixbuild](https://nixbuild.net/), but the library isn't being tested on that platform.
Loading