Skip to content

Commit af1aad8

Browse files
authored
Merge pull request typelevel#3750 from arashi01/scala-native-support
Support scala-native 0.4
2 parents 75be21a + 2fc4504 commit af1aad8

File tree

10 files changed

+217
-27
lines changed

10 files changed

+217
-27
lines changed

.github/workflows/ci.yml

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,33 @@ jobs:
2020
build:
2121
name: Build and Test
2222
strategy:
23+
fail-fast: false
2324
matrix:
2425
os: [ubuntu-latest]
25-
scala: [2.12.12, 2.13.4, 3.0.0-M2, 3.0.0-M3]
26+
scala: [2.12.13, 2.13.4, 3.0.0-M2, 3.0.0-M3]
2627
java:
2728
2829
2930
3031
31-
platform: [jvm, js]
32+
platform: [jvm, js, native]
3233
exclude:
3334
- platform: js
3435
36+
- platform: native
37+
3538
- platform: js
3639
40+
- platform: native
41+
3742
- platform: js
3843
44+
- platform: native
45+
46+
- platform: native
47+
scala: 3.0.0-M2
48+
- platform: native
49+
scala: 3.0.0-M3
3950
runs-on: ${{ matrix.os }}
4051
steps:
4152
- name: Checkout current branch (full)
@@ -67,6 +78,10 @@ jobs:
6778
if: matrix.platform == 'js'
6879
run: sbt ++${{ matrix.scala }} validateAllJS
6980

81+
- name: Validate Scala Native
82+
if: matrix.platform == 'native'
83+
run: sbt ++${{ matrix.scala }} validateAllNative
84+
7085
- name: Validate JVM (scala 2)
7186
if: matrix.platform == 'jvm' && (matrix.scala != '3.0.0-M2' && matrix.scala != '3.0.0-M3')
7287
run: sbt ++${{ matrix.scala }} buildJVM bench/test
@@ -84,7 +99,7 @@ jobs:
8499
strategy:
85100
matrix:
86101
os: [ubuntu-latest]
87-
scala: [2.12.12, 2.13.4, 3.0.0-M2, 3.0.0-M3]
102+
scala: [2.12.13, 2.13.4, 3.0.0-M2, 3.0.0-M3]
88103
89104
runs-on: ${{ matrix.os }}
90105
steps:
@@ -120,7 +135,7 @@ jobs:
120135
strategy:
121136
matrix:
122137
os: [ubuntu-latest]
123-
scala: [2.12.12, 2.13.4, 3.0.0-M2, 3.0.0-M3]
138+
scala: [2.12.13, 2.13.4, 3.0.0-M2, 3.0.0-M3]
124139
125140
runs-on: ${{ matrix.os }}
126141
steps:
@@ -155,7 +170,7 @@ jobs:
155170
strategy:
156171
matrix:
157172
os: [ubuntu-latest]
158-
scala: [2.12.12]
173+
scala: [2.12.13]
159174
160175
runs-on: ${{ matrix.os }}
161176
steps:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Support this project with your organization. Your logo will show up here with a
8787

8888
### Getting Started
8989

90-
Cats is currently available for Scala 2.10 (up to 1.2.x), 2.11, 2.12, 2.13, and [Scala.js](http://www.scala-js.org/).
90+
Cats is currently available for Scala 2.10 (up to 1.2.x), 2.11, 2.12, 2.13, [Scala.js](http://www.scala-js.org/), and [Scala Native](https://www.scala-native.org/).
9191

9292
Cats relies on improved type inference via the fix for [SI-2712](https://github.com/scala/bug/issues/2712), which is not enabled by default. For **Scala 2.11.9+ or 2.12** you should add the following to your `build.sbt`:
9393

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package alleycats.tests
2+
3+
import org.scalacheck.Test.Parameters
4+
5+
trait TestSettings {
6+
7+
lazy val checkConfiguration: Parameters =
8+
Parameters.default
9+
.withMinSuccessfulTests(50)
10+
.withMaxDiscardRatio(5.0f)
11+
.withMaxSize(10)
12+
.withMinSize(0)
13+
.withWorkers(1)
14+
}

build.sbt

+100-18
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ val GraalVM8 = "[email protected]"
3535

3636
ThisBuild / githubWorkflowJavaVersions := Seq(PrimaryJava, LTSJava, LatestJava, GraalVM8)
3737

38-
val Scala212 = "2.12.12"
38+
val Scala212 = "2.12.13"
3939
val Scala213 = "2.13.4"
4040
val DottyOld = "3.0.0-M2"
4141
val DottyNew = "3.0.0-M3"
@@ -46,24 +46,34 @@ ThisBuild / scalaVersion := Scala213
4646
ThisBuild / githubWorkflowPublishTargetBranches := Seq() // disable publication for now
4747

4848
ThisBuild / githubWorkflowBuildMatrixAdditions +=
49-
"platform" -> List("jvm", "js")
49+
"platform" -> List("jvm", "js", "native")
5050

5151
ThisBuild / githubWorkflowBuildMatrixExclusions ++=
52-
githubWorkflowJavaVersions.value.filterNot(Set(PrimaryJava)).map { java =>
53-
MatrixExclude(Map("platform" -> "js", "java" -> java))
52+
githubWorkflowJavaVersions.value.filterNot(Set(PrimaryJava)).flatMap { java =>
53+
Seq(MatrixExclude(Map("platform" -> "js", "java" -> java)),
54+
MatrixExclude(Map("platform" -> "native", "java" -> java))
55+
)
5456
}
5557

58+
ThisBuild / githubWorkflowBuildMatrixExclusions ++= Seq(DottyOld, DottyNew).map { dottyVersion =>
59+
MatrixExclude(Map("platform" -> "native", "scala" -> dottyVersion))
60+
} // Dotty is not yet supported by Scala Native
61+
5662
// we don't need this since we aren't publishing
5763
ThisBuild / githubWorkflowArtifactUpload := false
5864

65+
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
66+
5967
val JvmCond = s"matrix.platform == 'jvm'"
6068
val JsCond = s"matrix.platform == 'js'"
69+
val NativeCond = s"matrix.platform == 'native'"
6170

6271
val Scala2Cond = s"(matrix.scala != '$DottyOld' && matrix.scala != '$DottyNew')"
6372
val Scala3Cond = s"(matrix.scala == '$DottyOld' || matrix.scala == '$DottyNew')"
6473

6574
ThisBuild / githubWorkflowBuild := Seq(
6675
WorkflowStep.Sbt(List("validateAllJS"), name = Some("Validate JavaScript"), cond = Some(JsCond)),
76+
WorkflowStep.Sbt(List("validateAllNative"), name = Some("Validate Scala Native"), cond = Some(NativeCond)),
6777
WorkflowStep.Sbt(List("buildJVM", "bench/test"),
6878
name = Some("Validate JVM (scala 2)"),
6979
cond = Some(JvmCond + " && " + Scala2Cond)
@@ -199,6 +209,14 @@ lazy val commonJsSettings = Seq(
199209
doctestGenTests := Seq.empty
200210
)
201211

212+
lazy val commonNativeSettings = Seq(
213+
// currently sbt-doctest doesn't work in Native/JS builds
214+
// https://github.com/tkawachi/sbt-doctest/issues/52
215+
doctestGenTests := Seq.empty,
216+
// Currently scala-native does not support Dotty
217+
crossScalaVersions := { crossScalaVersions.value.filterNot(Seq(DottyOld, DottyNew).contains) }
218+
)
219+
202220
lazy val commonJvmSettings = Seq(
203221
testOptions in Test += {
204222
val flag = if (githubIsWorkflowBuild.value) "-oCI" else "-oDF"
@@ -497,8 +515,8 @@ lazy val cats = project
497515
.settings(moduleName := "root")
498516
.settings(publishSettings) // these settings are needed to release all aggregated modules under this root module
499517
.settings(noPublishSettings) // this is to exclude the root module itself from being published.
500-
.aggregate(catsJVM, catsJS)
501-
.dependsOn(catsJVM, catsJS, tests.jvm % "test-internal -> test")
518+
.aggregate(catsJVM, catsJS, catsNative)
519+
.dependsOn(catsJVM, catsJS, catsNative, tests.jvm % "test-internal -> test")
502520

503521
lazy val catsJVM = project
504522
.in(file(".catsJVM"))
@@ -565,7 +583,41 @@ lazy val catsJS = project
565583
)
566584
.enablePlugins(ScalaJSPlugin)
567585

568-
lazy val kernel = crossProject(JSPlatform, JVMPlatform)
586+
lazy val catsNative = project
587+
.in(file(".catsNative"))
588+
.settings(moduleName := "cats")
589+
.settings(noPublishSettings)
590+
.settings(catsSettings)
591+
.settings(commonNativeSettings)
592+
.aggregate(
593+
kernel.native,
594+
kernelLaws.native,
595+
core.native,
596+
laws.native,
597+
free.native,
598+
testkit.native,
599+
tests.native,
600+
alleycatsCore.native,
601+
alleycatsLaws.native,
602+
alleycatsTests.native,
603+
native
604+
)
605+
.dependsOn(
606+
kernel.native,
607+
kernelLaws.native,
608+
core.native,
609+
laws.native,
610+
free.native,
611+
testkit.native,
612+
tests.native % "test-internal -> test",
613+
alleycatsCore.native,
614+
alleycatsLaws.native,
615+
alleycatsTests.native % "test-internal -> test",
616+
native
617+
)
618+
.enablePlugins(ScalaNativePlugin)
619+
620+
lazy val kernel = crossProject(JSPlatform, JVMPlatform, NativePlatform)
569621
.crossType(CrossType.Pure)
570622
.in(file("kernel"))
571623
.settings(moduleName := "cats-kernel", name := "Cats kernel")
@@ -575,11 +627,13 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform)
575627
.settings(includeGeneratedSrc)
576628
.jsSettings(commonJsSettings)
577629
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-kernel"))
630+
.nativeSettings(commonNativeSettings)
631+
.settings(testingDependencies)
578632
.settings(
579633
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test
580634
)
581635

582-
lazy val kernelLaws = crossProject(JSPlatform, JVMPlatform)
636+
lazy val kernelLaws = crossProject(JSPlatform, JVMPlatform, NativePlatform)
583637
.in(file("kernel-laws"))
584638
.settings(moduleName := "cats-kernel-laws", name := "Cats kernel laws")
585639
.settings(commonSettings)
@@ -590,8 +644,9 @@ lazy val kernelLaws = crossProject(JSPlatform, JVMPlatform)
590644
.jsSettings(commonJsSettings)
591645
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-kernel-laws", includeCats1 = false))
592646
.dependsOn(kernel)
647+
.nativeSettings(commonNativeSettings)
593648

594-
lazy val core = crossProject(JSPlatform, JVMPlatform)
649+
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
595650
.crossType(CrossType.Pure)
596651
.dependsOn(kernel)
597652
.settings(moduleName := "cats-core", name := "Cats core")
@@ -611,8 +666,10 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
611666
)
612667
.jsSettings(commonJsSettings)
613668
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-core"))
669+
.settings(testingDependencies)
670+
.nativeSettings(commonNativeSettings)
614671

615-
lazy val laws = crossProject(JSPlatform, JVMPlatform)
672+
lazy val laws = crossProject(JSPlatform, JVMPlatform, NativePlatform)
616673
.crossType(CrossType.Pure)
617674
.dependsOn(kernel, core, kernelLaws)
618675
.settings(moduleName := "cats-laws", name := "Cats laws")
@@ -621,16 +678,18 @@ lazy val laws = crossProject(JSPlatform, JVMPlatform)
621678
.settings(testingDependencies)
622679
.jsSettings(commonJsSettings)
623680
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-laws", includeCats1 = false))
681+
.nativeSettings(commonNativeSettings)
624682

625-
lazy val free = crossProject(JSPlatform, JVMPlatform)
683+
lazy val free = crossProject(JSPlatform, JVMPlatform, NativePlatform)
626684
.crossType(CrossType.Pure)
627685
.dependsOn(core, tests % "test-internal -> test")
628686
.settings(moduleName := "cats-free", name := "Cats Free")
629687
.settings(catsSettings)
630688
.jsSettings(commonJsSettings)
631689
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-free"))
690+
.nativeSettings(commonNativeSettings)
632691

633-
lazy val tests = crossProject(JSPlatform, JVMPlatform)
692+
lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
634693
.crossType(CrossType.Pure)
635694
.dependsOn(testkit % Test)
636695
.settings(moduleName := "cats-tests")
@@ -640,8 +699,9 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform)
640699
.jsSettings(commonJsSettings)
641700
.jvmSettings(commonJvmSettings)
642701
.settings(scalacOptions in Test := (scalacOptions in Test).value.filter(_ != "-Xfatal-warnings"))
702+
.nativeSettings(commonNativeSettings)
643703

644-
lazy val testkit = crossProject(JSPlatform, JVMPlatform)
704+
lazy val testkit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
645705
.crossType(CrossType.Pure)
646706
.dependsOn(core, laws)
647707
.enablePlugins(BuildInfoPlugin)
@@ -652,8 +712,9 @@ lazy val testkit = crossProject(JSPlatform, JVMPlatform)
652712
.jsSettings(commonJsSettings)
653713
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-testkit", includeCats1 = false))
654714
.settings(scalacOptions := scalacOptions.value.filter(_ != "-Xfatal-warnings"))
715+
.nativeSettings(commonNativeSettings)
655716

656-
lazy val alleycatsCore = crossProject(JSPlatform, JVMPlatform)
717+
lazy val alleycatsCore = crossProject(JSPlatform, JVMPlatform, NativePlatform)
657718
.crossType(CrossType.Pure)
658719
.in(file("alleycats-core"))
659720
.dependsOn(core)
@@ -663,8 +724,9 @@ lazy val alleycatsCore = crossProject(JSPlatform, JVMPlatform)
663724
.settings(includeGeneratedSrc)
664725
.jsSettings(commonJsSettings)
665726
.jvmSettings(commonJvmSettings ++ mimaSettings("alleycats-core", includeCats1 = false))
727+
.nativeSettings(commonNativeSettings)
666728

667-
lazy val alleycatsLaws = crossProject(JSPlatform, JVMPlatform)
729+
lazy val alleycatsLaws = crossProject(JSPlatform, JVMPlatform, NativePlatform)
668730
.crossType(CrossType.Pure)
669731
.in(file("alleycats-laws"))
670732
.dependsOn(alleycatsCore, laws)
@@ -675,8 +737,9 @@ lazy val alleycatsLaws = crossProject(JSPlatform, JVMPlatform)
675737
.settings(testingDependencies)
676738
.jsSettings(commonJsSettings)
677739
.jvmSettings(commonJvmSettings ++ mimaSettings("alleycats-laws", includeCats1 = false))
740+
.nativeSettings(commonNativeSettings)
678741

679-
lazy val alleycatsTests = crossProject(JSPlatform, JVMPlatform)
742+
lazy val alleycatsTests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
680743
.in(file("alleycats-tests"))
681744
.dependsOn(alleycatsLaws, tests % "test-internal -> test")
682745
.settings(moduleName := "alleycats-tests")
@@ -685,6 +748,7 @@ lazy val alleycatsTests = crossProject(JSPlatform, JVMPlatform)
685748
.jsSettings(commonJsSettings)
686749
.jvmSettings(commonJvmSettings)
687750
.settings(scalacOptions in Test := (scalacOptions in Test).value.filter(_ != "-Xfatal-warnings"))
751+
.nativeSettings(commonNativeSettings)
688752

689753
// bench is currently JVM-only
690754

@@ -729,6 +793,14 @@ lazy val js = project
729793
.settings(commonJsSettings)
730794
.enablePlugins(ScalaJSPlugin)
731795

796+
// cats-native is Native-only
797+
lazy val native = project
798+
.dependsOn(core.native, tests.native % "test-internal -> test")
799+
.settings(moduleName := "cats-native")
800+
.settings(catsSettings)
801+
.settings(commonNativeSettings)
802+
.enablePlugins(ScalaNativePlugin)
803+
732804
// cats-jvm is JVM-only
733805
lazy val jvm = project
734806
.dependsOn(core.jvm, tests.jvm % "test-internal -> test")
@@ -833,14 +905,24 @@ addCommandAlias("buildTestsJVM", ";lawsJVM/test;testkitJVM/test;testsJVM/test;jv
833905
addCommandAlias("buildFreeJVM", ";freeJVM/test")
834906
addCommandAlias("buildAlleycatsJVM", ";alleycatsCoreJVM/test;alleycatsLawsJVM/test;alleycatsTestsJVM/test")
835907
addCommandAlias("buildJVM", ";buildKernelJVM;buildCoreJVM;buildTestsJVM;buildFreeJVM;buildAlleycatsJVM")
836-
addCommandAlias("validateBC", ";binCompatTest/test;mimaReportBinaryIssues")
908+
addCommandAlias("validateBC", ";binCompatTest/test;catsJVM/mimaReportBinaryIssues")
837909
addCommandAlias("validateJVM", ";fmtCheck;buildJVM;bench/test;validateBC;makeMicrosite")
838910
addCommandAlias("validateJS", ";testsJS/test;js/test")
839911
addCommandAlias("validateKernelJS", "kernelLawsJS/test")
840912
addCommandAlias("validateFreeJS", "freeJS/test")
841913
addCommandAlias("validateAlleycatsJS", "alleycatsTestsJS/test")
842914
addCommandAlias("validateAllJS", "all testsJS/test js/test kernelLawsJS/test freeJS/test alleycatsTestsJS/test")
843-
addCommandAlias("validate", ";clean;validateJS;validateKernelJS;validateFreeJS;validateJVM")
915+
addCommandAlias("validateNative", ";testsNative/test;native/test")
916+
addCommandAlias("validateKernelNative", "kernelLawsNative/test")
917+
addCommandAlias("validateFreeNative", "freeNative/test")
918+
addCommandAlias("validateAlleycatsNative", "alleycatsTestsNative/test")
919+
addCommandAlias("validateAllNative",
920+
"all testsNative/test native/test kernelLawsNative/test freeNative/test alleycatsTestsNative/test"
921+
)
922+
addCommandAlias(
923+
"validate",
924+
";clean;validateJS;validateKernelJS;validateFreeJS;validateNative;validateKernelNative;validateFreeNative;validateJVM"
925+
)
844926

845927
addCommandAlias("prePR", "fmt")
846928

kernel-laws/js/src/main/scala/cats/platform/Platform.scala

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

kernel-laws/jvm/src/main/scala/cats/platform/Platform.scala

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ private[cats] object Platform {
55
// $COVERAGE-OFF$
66
final val isJvm = true
77
final val isJs = false
8+
final val isNative = false
89
// $COVERAGE-ON$
910
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cats.platform
2+
3+
private[cats] 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+
}

0 commit comments

Comments
 (0)