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

WIP: native bindings #8

Closed
wants to merge 17 commits into from
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
40 changes: 37 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
os: [ubuntu-latest, macos-latest]
scala: [2.12.17, 2.13.10, 3.2.0]
java: [temurin@8]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -79,6 +79,10 @@ jobs:
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/nativeLink

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

Expand All @@ -92,11 +96,11 @@ jobs:

- 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/.js/target target .js/target core/.js/target bindingsScala/.js/target bindingsPython/.jvm/target bindingsScala/.jvm/target core/.jvm/target tests/.js/target .jvm/target .native/target tests/.jvm/target project/target
run: mkdir -p bindingsScala/.native/target bindingsPython/.js/target bindingsPython/.native/target target .js/target core/.native/target core/.js/target bindingsScala/.js/target bindingsPython/.jvm/target bindingsScala/.jvm/target core/.jvm/target tests/.js/target .jvm/target .native/target tests/.jvm/target tests/.native/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/.js/target target .js/target core/.js/target bindingsScala/.js/target bindingsPython/.jvm/target bindingsScala/.jvm/target core/.jvm/target tests/.js/target .jvm/target .native/target tests/.jvm/target project/target
run: tar cf targets.tar bindingsScala/.native/target bindingsPython/.js/target bindingsPython/.native/target target .js/target core/.native/target core/.js/target bindingsScala/.js/target bindingsPython/.jvm/target bindingsScala/.jvm/target core/.jvm/target tests/.js/target .jvm/target .native/target tests/.jvm/target tests/.native/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down Expand Up @@ -169,6 +173,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.17, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootNative

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

- name: Download target directories (2.13.10, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -189,6 +203,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.10, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootNative

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

- name: Download target directories (3.2.0, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -209,6 +233,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (3.2.0, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.0-rootNative

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

- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ Feel free to try it if that's okay with you ;)

```scala
libraryDependencies ++= Seq(
// Pure Scala interface - cross-compiled for JVM & JS platforms
// Base interface - cross-compiled for JVM & JS platforms.
// Use %%% instead of %% for JS/Native.
"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,
)
Expand All @@ -34,6 +31,8 @@ libraryDependencies ++= Seq(

## Supported systems

### JVM

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

- macOS x86_64
Expand All @@ -43,3 +42,11 @@ Support can vary, but the following platforms are considered supported:

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.

### Native

All platforms are supported as long as you provide the binaries. TODO

### JS

All platforms are supported as long as you provide the binaries.
39 changes: 23 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ ThisBuild / tlFatalWarningsInCi := false

val commonSettings = Seq(
libraryDependencies ++= compilerPlugins ++ Seq(
"com.disneystreaming" %%% "weaver-cats" % "0.8.0" % Test,
"com.disneystreaming" %%% "weaver-discipline" % "0.8.0" % Test,
"com.disneystreaming" %%% "weaver-scalacheck" % "0.8.0" % Test,
"com.disneystreaming" %%% "weaver-cats" % "0.8.0" % Test
),
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
scalacOptions ++= {
Expand All @@ -40,6 +38,12 @@ val commonSettings = Seq(
else
Nil
},
scalacOptions ++= {
if (scalaVersion.value.startsWith("2.13"))
Seq("-Wnonunit-statement")
else
Nil
},
)

val jvmTargetOptions = Seq("-source", "8", "-target", "8")
Expand All @@ -48,22 +52,22 @@ val commonJVMSettings = Seq(
javacOptions ++= jvmTargetOptions,
doc / javacOptions --= (jvmTargetOptions :+ "-Xlint:all"),
Test / fork := true,
scalacOptions ++= {
if (scalaVersion.value.startsWith("2.13"))
Seq("-Wnonunit-statement")
else
Nil
},
)

val commonJSSettings = Seq(
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
)

lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("modules/core"))
.settings(
commonSettings
commonSettings,
// Skipping tests in this module to avoid dealing with Native's linking errors
// (the TS code isn't used in the tests so it doesn't see the glue - or something)
// This is also why there are tests in the binding modules.
// see https://github.com/scala-native/scala-native/issues/2778
Test / test := {},
)
.jvmSettings(
commonJVMSettings,
Expand All @@ -73,8 +77,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
)
.jsSettings(commonJSSettings)

lazy val bindingsScala = crossProject(JVMPlatform, JSPlatform)
lazy val languageScala = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("modules/language-scala"))
.settings(
name := "language-scala",
commonSettings,
Expand All @@ -83,8 +88,9 @@ lazy val bindingsScala = crossProject(JVMPlatform, JSPlatform)
.jvmSettings(commonJVMSettings)
.jsSettings(commonJSSettings)

lazy val bindingsPython = crossProject(JVMPlatform, JSPlatform)
lazy val languagePython = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("modules/language-python"))
.settings(
name := "language-python",
commonSettings,
Expand All @@ -93,18 +99,19 @@ lazy val bindingsPython = crossProject(JVMPlatform, JSPlatform)
.jvmSettings(commonJVMSettings)
.jsSettings(commonJSSettings)

lazy val tests = crossProject(JVMPlatform, JSPlatform)
lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("modules/tests"))
.settings(
commonSettings
)
.dependsOn(bindingsScala, bindingsPython)
.dependsOn(languageScala, languagePython)
.jvmSettings(commonJVMSettings)
.jsSettings(commonJSSettings)
.enablePlugins(NoPublishPlugin)

lazy val root = tlCrossRootProject
.aggregate(core, bindingsScala, bindingsPython, tests)
.aggregate(core, languageScala, languagePython, tests)
.settings(
Compile / doc / sources := Seq(),
sonatypeProfileName := "org.polyvariant",
Expand Down
Binary file not shown.
Loading
Loading