Skip to content

Commit c5ed749

Browse files
authored
Add support for Scala Native (#338)
1 parent c33f783 commit c5ed749

File tree

6 files changed

+61
-29
lines changed

6 files changed

+61
-29
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: [ubuntu-latest]
26-
scala: [2.13.5, 2.12.12, 3.0.0-M2, 3.0.0-M3]
26+
scala: [2.13.5, 2.12.13, 3.0.0-RC2]
2727
28-
platform: [jvm, js]
28+
platform: [jvm, js, native]
2929
exclude:
30-
- platform: js
31-
scala: 3.0.0-M2
32-
- platform: js
33-
scala: 3.0.0-M3
30+
- platform: native
31+
scala: 3.0.0-RC2
3432
runs-on: ${{ matrix.os }}
3533
steps:
3634
- name: Checkout current branch (full)
@@ -62,30 +60,34 @@ jobs:
6260
if: matrix.platform == 'js'
6361
run: sbt ++${{ matrix.scala }} js/checkCI
6462

63+
- name: Validate Native
64+
if: matrix.platform == 'native'
65+
run: sbt ++${{ matrix.scala }} native/checkCI
66+
6567
- name: Validate JVM
66-
if: matrix.platform == 'jvm' && matrix.scala != '2.12.12'
68+
if: matrix.platform == 'jvm' && matrix.scala != '2.12.13'
6769
run: sbt ++${{ matrix.scala }} jvm/checkCI
6870

6971
- name: Setup Python
70-
if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
72+
if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
7173
uses: actions/setup-python@v2
7274
with:
7375
python-version: 3.x
7476

7577
- name: Setup codecov
76-
if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
78+
if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
7779
run: pip install codecov
7880

7981
- name: Validate JVM (scala 2)
80-
if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
81-
run: sbt ++${{ matrix.scala }} coverage jvm/checkCI docs/mdoc coverageReport
82+
if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
83+
run: sbt ++${{ matrix.scala }} jvm/checkCI docs/mdoc
8284

8385
- name: Upload Codecov Results
84-
if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
86+
if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
8587
run: codecov
8688

8789
- name: Binary compatibility ${{ matrix.scala }}
88-
if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
90+
if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
8991
run: sbt ++${{ matrix.scala }} mimaReportBinaryIssues
9092

9193
publish:
@@ -126,7 +128,7 @@ jobs:
126128
strategy:
127129
matrix:
128130
os: [ubuntu-latest]
129-
scala: [2.13.5, 2.12.12, 3.0.0-M2, 3.0.0-M3]
131+
scala: [2.13.5, 2.12.13, 3.0.0-RC2]
130132
131133
runs-on: ${{ matrix.os }}
132134
steps:
@@ -152,8 +154,8 @@ jobs:
152154
~/Library/Caches/Coursier/v1
153155
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
154156

155-
- if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
157+
- if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
156158
run: sbt ++${{ matrix.scala }} scalafmtCheckAll
157159

158-
- if: matrix.platform == 'jvm' && matrix.scala == '2.12.12'
160+
- if: matrix.platform == 'jvm' && matrix.scala == '2.12.13'
159161
run: sbt ++${{ matrix.scala }} scalafmtSbtCheck

build.sbt

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import sbtcrossproject.{crossProject, CrossType}
22

3-
val Scala212 = "2.12.12"
3+
val Scala212 = "2.12.13"
44
val Scala213 = "2.13.5"
55

6-
ThisBuild / crossScalaVersions := Seq(Scala213, Scala212, "3.0.0-M2", "3.0.0-M3")
6+
ThisBuild / crossScalaVersions := Seq(Scala213, Scala212, "3.0.0-RC2")
77
ThisBuild / scalaVersion := Scala213
88

99
ThisBuild / githubWorkflowJavaVersions := Seq("[email protected]")
1010

11-
ThisBuild / githubWorkflowBuildMatrixAdditions += "platform" -> List("jvm", "js")
11+
ThisBuild / githubWorkflowBuildMatrixAdditions += "platform" -> List("jvm", "js", "native")
1212

1313
ThisBuild / githubWorkflowBuildMatrixExclusions ++=
1414
(ThisBuild / crossScalaVersions).value.filter(_.startsWith("3.")).map { dottyVersion =>
15-
MatrixExclude(Map("platform" -> "js", "scala" -> dottyVersion))
15+
MatrixExclude(Map("platform" -> "native", "scala" -> dottyVersion))
1616
}
1717

1818
val JvmCond = s"matrix.platform == 'jvm'"
1919
val JsCond = s"matrix.platform == 'js'"
20+
val NativeCond = s"matrix.platform == 'native'"
2021

2122
val Scala212Cond = s"matrix.scala == '$Scala212'"
2223

2324
ThisBuild / githubWorkflowBuild := Seq(
2425
WorkflowStep.Sbt(List("js/checkCI"), name = Some("Validate JavaScript"), cond = Some(JsCond)),
26+
WorkflowStep.Sbt(List("native/checkCI"), name = Some("Validate Native"), cond = Some(NativeCond)),
2527
WorkflowStep.Sbt(List("jvm/checkCI"),
2628
name = Some("Validate JVM"),
2729
cond = Some(JvmCond + " && " + s"matrix.scala != '$Scala212'")
@@ -35,7 +37,8 @@ ThisBuild / githubWorkflowBuild := Seq(
3537
name = Some("Setup codecov"),
3638
cond = Some(JvmCond + " && " + Scala212Cond)
3739
),
38-
WorkflowStep.Sbt(List("coverage", "jvm/checkCI", "docs/mdoc", "coverageReport"),
40+
// Avoid coverage, see https://github.com/scoverage/sbt-scoverage/issues/319
41+
WorkflowStep.Sbt(List(/*"coverage",*/ "jvm/checkCI", "docs/mdoc"/*, "coverageReport"*/),
3942
name = Some("Validate JVM (scala 2)"),
4043
cond = Some(JvmCond + " && " + Scala212Cond)
4144
),
@@ -131,7 +134,12 @@ lazy val js = project
131134
.settings(noPublish)
132135
.aggregate(coreJS, catsJS)
133136

134-
lazy val core = crossProject(JSPlatform, JVMPlatform)
137+
lazy val native = project
138+
.in(file(".native"))
139+
.settings(noPublish)
140+
.aggregate(coreNative, catsNative)
141+
142+
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
135143
.crossType(CrossType.Pure)
136144
.in(file("core"))
137145
.settings(
@@ -143,18 +151,20 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
143151
else previousArtifact(version.value, "core")
144152
},
145153
libraryDependencies ++= Seq(
146-
"org.scalatestplus" %%% "scalacheck-1-15" % "3.2.3.0" % Test,
147-
"org.scalatest" %%% "scalatest-funsuite" % "3.2.3" % Test
154+
"org.scalatestplus" %%% "scalacheck-1-15" % "3.2.7.0" % Test,
155+
"org.scalatest" %%% "scalatest-funsuite" % "3.2.7" % Test
148156
)
149157
)
150158
.disablePlugins(JmhPlugin)
151159
.jsSettings(commonJsSettings)
152160
.jvmSettings(commonJvmSettings)
161+
.nativeSettings(commonNativeSettings)
153162

154163
lazy val coreJVM = core.jvm
155164
lazy val coreJS = core.js
165+
lazy val coreNative = core.native
156166

157-
lazy val cats = crossProject(JSPlatform, JVMPlatform)
167+
lazy val cats = crossProject(JSPlatform, JVMPlatform, NativePlatform)
158168
.crossType(CrossType.Full)
159169
.in(file("cats"))
160170
.dependsOn(core % "compile->compile;test->test")
@@ -163,9 +173,9 @@ lazy val cats = crossProject(JSPlatform, JVMPlatform)
163173
name := "paiges-cats",
164174
moduleName := "paiges-cats",
165175
libraryDependencies ++= Seq(
166-
"org.typelevel" %%% "cats-core" % "2.4.1",
167-
"org.typelevel" %%% "cats-laws" % "2.4.1" % Test,
168-
"org.typelevel" %%% "discipline-scalatest" % "2.1.1" % Test
176+
"org.typelevel" %%% "cats-core" % "2.5.0",
177+
"org.typelevel" %%% "cats-laws" % "2.5.0" % Test,
178+
"org.typelevel" %%% "discipline-scalatest" % "2.1.3" % Test
169179
),
170180
mimaPreviousArtifacts := {
171181
if (isDotty.value) Set.empty
@@ -175,9 +185,11 @@ lazy val cats = crossProject(JSPlatform, JVMPlatform)
175185
.disablePlugins(JmhPlugin)
176186
.jsSettings(commonJsSettings)
177187
.jvmSettings(commonJvmSettings)
188+
.nativeSettings(commonNativeSettings)
178189

179190
lazy val catsJVM = cats.jvm
180191
lazy val catsJS = cats.js
192+
lazy val catsNative = cats.native
181193

182194
lazy val benchmark = project
183195
.in(file("benchmark"))
@@ -270,13 +282,17 @@ lazy val commonJvmSettings = Seq(
270282
)
271283

272284
lazy val commonJsSettings = Seq(
273-
crossScalaVersions := crossScalaVersions.value.filter(_.startsWith("2.")),
274285
scalaJSStage in Global := FastOptStage,
275286
parallelExecution := false,
276287
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
277288
coverageEnabled := false
278289
)
279290

291+
lazy val commonNativeSettings = Seq(
292+
crossScalaVersions := crossScalaVersions.value.filter(_.startsWith("2.")),
293+
coverageEnabled := false
294+
)
295+
280296
def previousArtifact(version: String, proj: String) = {
281297
def mod(x: Int, y: Int, z: Int): ModuleID =
282298
"org.typelevel" %% s"paiges-$proj" % s"$x.$y.$z"

cats/js/src/main/scala/org/typelevel/paiges/Platform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ private[paiges] object Platform {
55
// $COVERAGE-OFF$
66
final val isJvm = false
77
final val isJs = true
8+
final val isNative = false
89
// $COVERAGE-ON$
910
}

cats/jvm/src/main/scala/org/typelevel/paiges/Platform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ private[paiges] object Platform {
55
// $COVERAGE-OFF$
66
final val isJvm = true
77
final val isJs = false
8+
final val isNative = false
89
// $COVERAGE-ON$
910
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.typelevel.paiges
2+
3+
private[paiges] object Platform {
4+
// using `final val` makes compiler constant-fold any use of these values, dropping dead code automatically
5+
// $COVERAGE-OFF$
6+
final val isJvm = false
7+
final val isJs = false
8+
final val isNative = true
9+
// $COVERAGE-ON$
10+
}

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.4")
1010
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.10.1")
1111
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
1212
addSbtPlugin("io.crashbox" % "sbt-gpg" % "0.2.1")
13+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
14+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")

0 commit comments

Comments
 (0)