Skip to content

Commit 97552e0

Browse files
authored
Merge pull request #730 from PhoenixmitX/scala-native
Add scala native support
2 parents 8bbaa66 + 2e56b19 commit 97552e0

File tree

9 files changed

+384
-47
lines changed

9 files changed

+384
-47
lines changed

.github/workflows/ci.yml

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: CI
22

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

76
on:
87
pull_request:
@@ -14,53 +13,62 @@ on:
1413

1514
jobs:
1615
lint:
17-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-24.04
1817
timeout-minutes: 30
1918
steps:
2019
- name: Checkout current branch
21-
uses: actions/checkout@v2.4.0
20+
uses: actions/checkout@v4
2221
with:
2322
fetch-depth: 0
2423
- name: Setup Java
25-
uses: actions/setup-java@v3.4.1
24+
uses: actions/setup-java@v4
2625
with:
2726
distribution: temurin
2827
java-version: 17
2928
check-latest: true
29+
30+
- name: Setup sbt
31+
uses: sbt/setup-sbt@v1
3032
- name: Cache scala dependencies
3133
uses: coursier/cache-action@v6
3234
- name: Lint code
33-
run: sbt ++3.3.1 check
35+
run: sbt ++3.3.3 check
3436

3537
test:
36-
runs-on: ubuntu-20.04
38+
runs-on: ubuntu-24.04
3739
timeout-minutes: 30
3840
strategy:
3941
fail-fast: false
4042
matrix:
4143
java: ['11', '17', '21']
42-
scala: ['3.3.1']
43-
platform: ['JVM', 'JS']
44+
scala: ['3.3.3']
45+
platform: ['JVM', 'JS', 'Native']
4446
steps:
4547
- name: Checkout current branch
46-
uses: actions/checkout@v2.4.0
48+
uses: actions/checkout@v4
4749
with:
4850
fetch-depth: 0
4951
- name: Setup Java
50-
uses: actions/setup-java@v3.4.1
52+
uses: actions/setup-java@v4
5153
with:
5254
distribution: temurin
5355
java-version: ${{ matrix.java }}
5456
check-latest: true
57+
- name: Setup sbt
58+
uses: sbt/setup-sbt@v1
5559
- name: Cache scala dependencies
5660
uses: coursier/cache-action@v6
61+
- name: Setup node
62+
uses: actions/setup-node@v4
63+
if: matrix.platform == 'JS'
64+
with:
65+
node-version: '22'
5766
- name: Run tests
58-
if: ${{ matrix.platform == 'JVM' }}
59-
run: sbt ++${{ matrix.scala }}! testJVM
67+
run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }}
6068

6169
ci:
62-
runs-on: ubuntu-20.04
70+
runs-on: ubuntu-24.04
6371
needs: [lint, test]
6472
steps:
6573
- name: Aggregate of lint, and all tests
66-
run: echo "ci passed"
74+
run: echo "ci passed"

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# (See https://help.github.com/articles/ignoring-files/ for details)
66

77
.bsp
8+
.bloop
9+
.metals
10+
metals.sbt
811
lib_managed
912
target
1013
project/boot

build.sbt

+36-13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ addCommandAlias(
3636
.mkString("; ", "/test ; ", "/test")
3737
)
3838

39+
addCommandAlias(
40+
"testNative",
41+
Seq("coreNative", "derivationNative", "compat-catsNative", "compat-circeNative", "compat-scodecNative")
42+
.mkString("; ", "/test ; ", "/test")
43+
)
44+
3945
lazy val commonSettings = Seq(
4046
scalaVersion := scala3,
4147
scalacOptions ++= Seq(
@@ -126,13 +132,13 @@ val macrolizer = Def.setting("io.bullet" %%% "macrolizer" %
126132
/////////////////////// PROJECTS /////////////////////////
127133

128134
lazy val borer = (project in file("."))
129-
.aggregate(`core-jvm`, `core-js`)
135+
.aggregate(`core-jvm`, `core-js`, `core-native`)
130136
.aggregate(`compat-akka`)
131137
.aggregate(`compat-pekko`)
132-
.aggregate(`compat-cats-jvm`, `compat-cats-js`)
133-
.aggregate(`compat-circe-jvm`, `compat-circe-js`)
134-
.aggregate(`compat-scodec-jvm`, `compat-scodec-js`)
135-
.aggregate(`derivation-jvm`, `derivation-js`)
138+
.aggregate(`compat-cats-jvm`, `compat-cats-js`, `compat-cats-native`)
139+
.aggregate(`compat-circe-jvm`, `compat-circe-js`, `compat-circe-native`)
140+
.aggregate(`compat-scodec-jvm`, `compat-scodec-js`, `compat-scodec-native`)
141+
.aggregate(`derivation-jvm`, `derivation-js`, `derivation-native`)
136142
// .aggregate(benchmarks)
137143
.aggregate(site)
138144
.settings(commonSettings)
@@ -142,9 +148,10 @@ lazy val borer = (project in file("."))
142148
onLoadMessage := welcomeMessage.value
143149
)
144150

145-
lazy val `core-jvm` = core.jvm.enablePlugins(SpecializeJsonParserPlugin)
146-
lazy val `core-js` = core.js
147-
lazy val core = crossProject(JSPlatform, JVMPlatform)
151+
lazy val `core-jvm` = core.jvm.enablePlugins(SpecializeJsonParserPlugin)
152+
lazy val `core-js` = core.js
153+
lazy val `core-native` = core.native.enablePlugins(SpecializeJsonParserPlugin)
154+
lazy val core = crossProject(JSPlatform, NativePlatform, JVMPlatform)
148155
.withoutSuffixFor(JVMPlatform)
149156
.crossType(CrossType.Pure)
150157
.enablePlugins(AutomateHeaderPlugin)
@@ -159,6 +166,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
159166
Compile / specializeJsonParser / sourceManaged := baseDirectory.value / "target" / "scala" / "src_managed" / "main",
160167
Compile / managedSourceDirectories += (Compile / specializeJsonParser / sourceManaged).value
161168
)
169+
.nativeSettings(
170+
Compile / specializeJsonParser / sourceDirectory := baseDirectory.value.getParentFile / "src" / "main",
171+
Compile / specializeJsonParser / sourceManaged := baseDirectory.value / "target" / "scala" / "src_managed" / "main",
172+
Compile / managedSourceDirectories += (Compile / specializeJsonParser / sourceManaged).value
173+
)
162174
.jsSettings(scalajsSettings: _*)
163175

164176
lazy val `compat-akka` = project
@@ -197,7 +209,10 @@ lazy val `compat-cats-jvm` = `compat-cats`.jvm
197209
lazy val `compat-cats-js` = `compat-cats`.js
198210
.dependsOn(`core-js` % "compile->compile;test->test")
199211
.dependsOn(`derivation-js` % "test->compile")
200-
lazy val `compat-cats` = crossProject(JSPlatform, JVMPlatform)
212+
lazy val `compat-cats-native` = `compat-cats`.native
213+
.dependsOn(`core-native` % "compile->compile;test->test")
214+
.dependsOn(`derivation-native` % "test->compile")
215+
lazy val `compat-cats` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
201216
.withoutSuffixFor(JVMPlatform)
202217
.crossType(CrossType.Pure)
203218
.enablePlugins(AutomateHeaderPlugin)
@@ -215,7 +230,10 @@ lazy val `compat-circe-jvm` = `compat-circe`.jvm
215230
lazy val `compat-circe-js` = `compat-circe`.js
216231
.dependsOn(`core-js` % "compile->compile;test->test")
217232
.dependsOn(`derivation-js` % "test->compile")
218-
lazy val `compat-circe` = crossProject(JSPlatform, JVMPlatform)
233+
lazy val `compat-circe-native` = `compat-circe`.native
234+
.dependsOn(`core-native` % "compile->compile;test->test")
235+
.dependsOn(`derivation-native` % "test->compile")
236+
lazy val `compat-circe` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
219237
.withoutSuffixFor(JVMPlatform)
220238
.crossType(CrossType.Pure)
221239
.enablePlugins(AutomateHeaderPlugin)
@@ -238,7 +256,10 @@ lazy val `compat-scodec-jvm` = `compat-scodec`.jvm
238256
lazy val `compat-scodec-js` = `compat-scodec`.js
239257
.dependsOn(`core-js` % "compile->compile;test->test")
240258
.dependsOn(`derivation-js` % "test->compile")
241-
lazy val `compat-scodec` = crossProject(JSPlatform, JVMPlatform)
259+
lazy val `compat-scodec-native` = `compat-scodec`.native
260+
.dependsOn(`core-native` % "compile->compile;test->test")
261+
.dependsOn(`derivation-native` % "test->compile")
262+
lazy val `compat-scodec` = crossProject(JSPlatform, NativePlatform, JVMPlatform)
242263
.withoutSuffixFor(JVMPlatform)
243264
.crossType(CrossType.Pure)
244265
.enablePlugins(AutomateHeaderPlugin)
@@ -257,15 +278,17 @@ lazy val `derivation-jvm` = derivation.jvm
257278
.dependsOn(`core-jvm` % "compile->compile;test->test")
258279
lazy val `derivation-js` = derivation.js
259280
.dependsOn(`core-js` % "compile->compile;test->test")
260-
lazy val derivation = crossProject(JSPlatform, JVMPlatform)
281+
lazy val `derivation-native` = derivation.native
282+
.dependsOn(`core-native` % "compile->compile;test->test")
283+
lazy val derivation = crossProject(JSPlatform, NativePlatform, JVMPlatform)
261284
.withoutSuffixFor(JVMPlatform)
262285
.crossType(CrossType.Pure)
263286
.enablePlugins(AutomateHeaderPlugin)
264287
.settings(commonSettings)
265288
.settings(releaseSettings)
266289
.settings(
267290
moduleName := "borer-derivation",
268-
libraryDependencies ++= Seq(macrolizer.value, munit.value),
291+
libraryDependencies ++= Seq(/* macrolizer.value, */ munit.value), // TODO port macrolizer to scala native
269292
)
270293
.jsSettings(scalajsSettings: _*)
271294

core/.jvm/src/main/scala/io/bullet/borer/internal/Unsafe.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ object Unsafe:
290290
def setOctaByteBigEndian(byteArray: Array[Byte], ix: Int, value: Long): Unit =
291291
_setOctaByteBigEndian(byteArray, ix, JLong.reverseBytes(value))
292292

293-
final class BigEndianByteArrayAccess extends UnsafeByteArrayAccess(ByteOrder.LITTLE_ENDIAN):
293+
final class BigEndianByteArrayAccess extends UnsafeByteArrayAccess(ByteOrder.BIG_ENDIAN):
294294

295295
def doubleByteBigEndian(byteArray: Array[Byte], ix: Int): Char =
296296
_doubleByteBigEndian(byteArray, ix)

0 commit comments

Comments
 (0)