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

Cross build with Scala Native #282

Merged
merged 4 commits into from
Dec 23, 2024
Merged
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
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -25,8 +25,10 @@ jobs:
distribution: temurin
java-version: ${{matrix.java}}
- uses: sbt/setup-sbt@v1
- name: Test
run: sbt "setScalaVersion ${{matrix.scala}}" test core/headerCheck package
- name: Test JVM
run: sbt "setScalaVersion ${{matrix.scala}}" testJVM core/headerCheck package
- name: Test Native
run: sbt "setScalaVersion ${{matrix.scala}}" testNative

test-rc:
strategy:
@@ -52,4 +54,4 @@ jobs:
java-version: ${{matrix.java}}
- uses: sbt/setup-sbt@v1
- name: Test
run: sbt "setScalaVersion ${{matrix.scala}}" test core/headerCheck package
run: sbt "setScalaVersion ${{matrix.scala}}" testJVM core/headerCheck package
90 changes: 73 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
ThisBuild / crossScalaVersions := Seq("2.13.15", "3.3.4")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.head
val scalaVersions = Seq("2.13.15", "3.3.4")
val defaultScalaVersion = scalaVersions.head

// When defining JVM / Scala Native matrix we don't want duplicated projects for Scala 2/3
val matrixScalaVersions = Seq(defaultScalaVersion)

ThisBuild / crossScalaVersions := scalaVersions
ThisBuild / scalaVersion := defaultScalaVersion

Global / concurrentRestrictions += Tags.limit(NativeTags.Link, 1)
Global / cancelable := true
publish / skip := true // in root

lazy val commonSettings: Seq[Setting[_]] =
Seq(scalaModuleAutomaticModuleName := Some("scala.collection.parallel")) ++
ScalaModulePlugin.scalaModuleSettings ++ Seq(
versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,
crossScalaVersions := scalaVersions,
Compile / compile / scalacOptions --= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Xlint")
case _ => Seq()
@@ -18,43 +26,79 @@ lazy val commonSettings: Seq[Setting[_]] =
}),
)

lazy val core = project.in(file("core"))
lazy val testNativeSettings: Seq[Setting[_]] = Seq(
// Required by Scala Native testing infrastructure
Test / fork := false,
)

lazy val core = projectMatrix.in(file("core"))
.settings(commonSettings)
.settings(
name := "scala-parallel-collections",
Compile / doc / autoAPIMappings := true,
)
.jvmPlatform(matrixScalaVersions)
.nativePlatform(matrixScalaVersions, settings = testNativeSettings ++ Seq(
versionPolicyPreviousArtifacts := Nil, // TODO: not yet published
mimaPreviousArtifacts := Set.empty
))

lazy val junit = project.in(file("junit"))
lazy val junit = projectMatrix.in(file("junit"))
.settings(commonSettings)
.settings(
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test,
libraryDependencies += "junit" % "junit" % "4.13.2" % Test,
// for javax.xml.bind.DatatypeConverter, used in SerializationStabilityTest
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.1" % Test,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
Test / fork := true,
publish / skip := true,
).dependsOn(testmacros, core)
.jvmPlatform(matrixScalaVersions,
settings = Seq(
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test,
libraryDependencies += "junit" % "junit" % "4.13.2" % Test,
// for javax.xml.bind.DatatypeConverter, used in SerializationStabilityTest
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.1" % Test,
Test / fork := true,
)
)
.nativePlatform(matrixScalaVersions,
axisValues = Nil,
configure = _
.enablePlugins(ScalaNativeJUnitPlugin)
.settings(
Test/unmanagedSources/excludeFilter ~= { _ ||
"SerializationTest.scala" || // requires ObjectOutputStream
"SerializationStability.scala" || // requires jaxb-api
"SerializationStabilityBase.scala" ||
"SerializationStabilityTest.scala"
},
Test / fork := false
)
)

lazy val scalacheck = project.in(file("scalacheck"))
lazy val scalacheck = projectMatrix.in(file("scalacheck"))
.settings(commonSettings)
.settings(
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.18.1",
Test / fork := true,
libraryDependencies += "org.scalacheck" %%% "scalacheck" % "1.18.1",
Test / testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-workers", "1", "-minSize", "0", "-maxSize", "4000", "-minSuccessfulTests", "5"),
publish / skip := true
).dependsOn(core)
)
.dependsOn(core)
.jvmPlatform(matrixScalaVersions,
settings = Seq(
Test / fork := true
)
)
.nativePlatform(matrixScalaVersions, settings = testNativeSettings)

lazy val testmacros = project.in(file("testmacros"))
lazy val testmacros = projectMatrix.in(file("testmacros"))
.settings(commonSettings)
.settings(
libraryDependencies += (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => scalaOrganization.value %% "scala3-compiler" % scalaVersion.value
case _ => scalaOrganization.value % "scala-compiler" % scalaVersion.value
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Nil
case _ => List(scalaOrganization.value % "scala-compiler" % scalaVersion.value)
}),
publish / skip := true,
)
.jvmPlatform(matrixScalaVersions)
.nativePlatform(matrixScalaVersions, settings = testNativeSettings)

commands += Command.single("setScalaVersion") { (state, arg) =>
val command = arg match {
@@ -63,3 +107,15 @@ commands += Command.single("setScalaVersion") { (state, arg) =>
}
command :: state
}

import sbt.internal.{ProjectMatrix, ProjectFinder}
def testPlatformCommand(name: String, selector: ProjectMatrix => ProjectFinder): Command =
Command.command(name) { state =>
List(junit, scalacheck, testmacros)
.flatMap(selector(_).get)
.map{ project => s"${project.id}/test"}
.toList ::: state
}

commands += testPlatformCommand("testNative", _.native)
commands += testPlatformCommand("testJVM", _.jvm)
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "3.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.6")