Skip to content

Commit

Permalink
Merge pull request #730 from PhoenixmitX/scala-native
Browse files Browse the repository at this point in the history
Add scala native support
  • Loading branch information
sirthias authored Dec 5, 2024
2 parents 8bbaa66 + 2e56b19 commit 97552e0
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 47 deletions.
38 changes: 23 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: CI

env:
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags # JDK_JAVA_OPTIONS is _the_ env. variable to use for modern Java
JVM_OPTS: -XX:+PrintCommandLineFlags # for Java 8 only (sadly, it is not modern enough for JDK_JAVA_OPTIONS)
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags

on:
pull_request:
Expand All @@ -14,53 +13,62 @@ on:

jobs:
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Checkout current branch
uses: actions/checkout@v2.4.0
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@v3.4.1
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
check-latest: true

- name: Setup sbt
uses: sbt/setup-sbt@v1
- name: Cache scala dependencies
uses: coursier/cache-action@v6
- name: Lint code
run: sbt ++3.3.1 check
run: sbt ++3.3.3 check

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
java: ['11', '17', '21']
scala: ['3.3.1']
platform: ['JVM', 'JS']
scala: ['3.3.3']
platform: ['JVM', 'JS', 'Native']
steps:
- name: Checkout current branch
uses: actions/checkout@v2.4.0
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@v3.4.1
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}
check-latest: true
- name: Setup sbt
uses: sbt/setup-sbt@v1
- name: Cache scala dependencies
uses: coursier/cache-action@v6
- name: Setup node
uses: actions/setup-node@v4
if: matrix.platform == 'JS'
with:
node-version: '22'
- name: Run tests
if: ${{ matrix.platform == 'JVM' }}
run: sbt ++${{ matrix.scala }}! testJVM
run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }}

ci:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
needs: [lint, test]
steps:
- name: Aggregate of lint, and all tests
run: echo "ci passed"
run: echo "ci passed"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# (See https://help.github.com/articles/ignoring-files/ for details)

.bsp
.bloop
.metals
metals.sbt
lib_managed
target
project/boot
Expand Down
49 changes: 36 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ addCommandAlias(
.mkString("; ", "/test ; ", "/test")
)

addCommandAlias(
"testNative",
Seq("coreNative", "derivationNative", "compat-catsNative", "compat-circeNative", "compat-scodecNative")
.mkString("; ", "/test ; ", "/test")
)

lazy val commonSettings = Seq(
scalaVersion := scala3,
scalacOptions ++= Seq(
Expand Down Expand Up @@ -126,13 +132,13 @@ val macrolizer = Def.setting("io.bullet" %%% "macrolizer" %
/////////////////////// PROJECTS /////////////////////////

lazy val borer = (project in file("."))
.aggregate(`core-jvm`, `core-js`)
.aggregate(`core-jvm`, `core-js`, `core-native`)
.aggregate(`compat-akka`)
.aggregate(`compat-pekko`)
.aggregate(`compat-cats-jvm`, `compat-cats-js`)
.aggregate(`compat-circe-jvm`, `compat-circe-js`)
.aggregate(`compat-scodec-jvm`, `compat-scodec-js`)
.aggregate(`derivation-jvm`, `derivation-js`)
.aggregate(`compat-cats-jvm`, `compat-cats-js`, `compat-cats-native`)
.aggregate(`compat-circe-jvm`, `compat-circe-js`, `compat-circe-native`)
.aggregate(`compat-scodec-jvm`, `compat-scodec-js`, `compat-scodec-native`)
.aggregate(`derivation-jvm`, `derivation-js`, `derivation-native`)
// .aggregate(benchmarks)
.aggregate(site)
.settings(commonSettings)
Expand All @@ -142,9 +148,10 @@ lazy val borer = (project in file("."))
onLoadMessage := welcomeMessage.value
)

lazy val `core-jvm` = core.jvm.enablePlugins(SpecializeJsonParserPlugin)
lazy val `core-js` = core.js
lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val `core-jvm` = core.jvm.enablePlugins(SpecializeJsonParserPlugin)
lazy val `core-js` = core.js
lazy val `core-native` = core.native.enablePlugins(SpecializeJsonParserPlugin)
lazy val core = crossProject(JSPlatform, NativePlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -159,6 +166,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
Compile / specializeJsonParser / sourceManaged := baseDirectory.value / "target" / "scala" / "src_managed" / "main",
Compile / managedSourceDirectories += (Compile / specializeJsonParser / sourceManaged).value
)
.nativeSettings(
Compile / specializeJsonParser / sourceDirectory := baseDirectory.value.getParentFile / "src" / "main",
Compile / specializeJsonParser / sourceManaged := baseDirectory.value / "target" / "scala" / "src_managed" / "main",
Compile / managedSourceDirectories += (Compile / specializeJsonParser / sourceManaged).value
)
.jsSettings(scalajsSettings: _*)

lazy val `compat-akka` = project
Expand Down Expand Up @@ -197,7 +209,10 @@ lazy val `compat-cats-jvm` = `compat-cats`.jvm
lazy val `compat-cats-js` = `compat-cats`.js
.dependsOn(`core-js` % "compile->compile;test->test")
.dependsOn(`derivation-js` % "test->compile")
lazy val `compat-cats` = crossProject(JSPlatform, JVMPlatform)
lazy val `compat-cats-native` = `compat-cats`.native
.dependsOn(`core-native` % "compile->compile;test->test")
.dependsOn(`derivation-native` % "test->compile")
lazy val `compat-cats` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -215,7 +230,10 @@ lazy val `compat-circe-jvm` = `compat-circe`.jvm
lazy val `compat-circe-js` = `compat-circe`.js
.dependsOn(`core-js` % "compile->compile;test->test")
.dependsOn(`derivation-js` % "test->compile")
lazy val `compat-circe` = crossProject(JSPlatform, JVMPlatform)
lazy val `compat-circe-native` = `compat-circe`.native
.dependsOn(`core-native` % "compile->compile;test->test")
.dependsOn(`derivation-native` % "test->compile")
lazy val `compat-circe` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -238,7 +256,10 @@ lazy val `compat-scodec-jvm` = `compat-scodec`.jvm
lazy val `compat-scodec-js` = `compat-scodec`.js
.dependsOn(`core-js` % "compile->compile;test->test")
.dependsOn(`derivation-js` % "test->compile")
lazy val `compat-scodec` = crossProject(JSPlatform, JVMPlatform)
lazy val `compat-scodec-native` = `compat-scodec`.native
.dependsOn(`core-native` % "compile->compile;test->test")
.dependsOn(`derivation-native` % "test->compile")
lazy val `compat-scodec` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -257,15 +278,17 @@ lazy val `derivation-jvm` = derivation.jvm
.dependsOn(`core-jvm` % "compile->compile;test->test")
lazy val `derivation-js` = derivation.js
.dependsOn(`core-js` % "compile->compile;test->test")
lazy val derivation = crossProject(JSPlatform, JVMPlatform)
lazy val `derivation-native` = derivation.native
.dependsOn(`core-native` % "compile->compile;test->test")
lazy val derivation = crossProject(JSPlatform, NativePlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(releaseSettings)
.settings(
moduleName := "borer-derivation",
libraryDependencies ++= Seq(macrolizer.value, munit.value),
libraryDependencies ++= Seq(/* macrolizer.value, */ munit.value), // TODO port macrolizer to scala native
)
.jsSettings(scalajsSettings: _*)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ object Unsafe:
def setOctaByteBigEndian(byteArray: Array[Byte], ix: Int, value: Long): Unit =
_setOctaByteBigEndian(byteArray, ix, JLong.reverseBytes(value))

final class BigEndianByteArrayAccess extends UnsafeByteArrayAccess(ByteOrder.LITTLE_ENDIAN):
final class BigEndianByteArrayAccess extends UnsafeByteArrayAccess(ByteOrder.BIG_ENDIAN):

def doubleByteBigEndian(byteArray: Array[Byte], ix: Int): Char =
_doubleByteBigEndian(byteArray, ix)
Expand Down
Loading

0 comments on commit 97552e0

Please sign in to comment.