Skip to content

Commit a41c06b

Browse files
committed
support scala-native Scala 3 build
1 parent 302309d commit a41c06b

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,6 @@ workflows:
157157
- scalanative_job:
158158
name: native0.4_2.13
159159
scala_version: 2.13.8
160+
- scalanative_job:
161+
name: native0.4_3
162+
scala_version: 3.1.0

build.sbt

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,66 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
140140
)
141141
.jsEnablePlugins(ScalaJSJUnitPlugin)
142142
.nativeSettings(
143-
crossScalaVersions := Seq("2.13.8", "2.12.15"),
143+
crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.0"),
144+
mimaPreviousArtifacts := {
145+
// TODO remove this setting whien 2.0.2 released
146+
if (scalaBinaryVersion.value == "3") {
147+
mimaPreviousArtifacts.value.filterNot(_.revision == "2.0.1")
148+
} else {
149+
mimaPreviousArtifacts.value
150+
}
151+
},
144152
// Scala Native cannot run forked tests
145153
Test / fork := false,
146-
libraryDependencies += "org.scala-native" %%% "junit-runtime" % nativeVersion % Test,
147-
Test / scalacOptions += {
148-
val log = streams.value.log
149-
val retrieveDir = baseDirectory.value / "scala-native-junit-plugin-jars"
150-
val lm = dependencyResolution.value
151-
val cp = lm
152-
.retrieve(
153-
"org.scala-native" % s"junit-plugin_${scalaVersion.value}" % nativeVersion,
154-
scalaModuleInfo = None,
155-
retrieveDir,
156-
log
157-
)
158-
.fold(w => throw w.resolveException, identity(_))
159-
val jarPath = cp
160-
.find(_.toString.contains("junit-plugin"))
161-
.getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar"))
162-
s"-Xplugin:$jarPath"
154+
Seq(Compile, Test).map { s =>
155+
s / sources := {
156+
CrossVersion.partialVersion(scalaVersion.value) match {
157+
case Some((3, 0)) =>
158+
Nil
159+
case _ =>
160+
(s / sources).value
161+
}
162+
}
163+
},
164+
libraryDependencies := {
165+
CrossVersion.partialVersion(scalaVersion.value) match {
166+
case Some((3, 0)) =>
167+
// scala-native does not support Scala 3.0.x
168+
Nil
169+
case _ =>
170+
libraryDependencies.value ++ Seq("org.scala-native" %%% "junit-runtime" % nativeVersion % Test)
171+
}
172+
},
173+
Compile / doc / scalacOptions --= {
174+
// TODO remove this workaround
175+
// https://github.com/scala-native/scala-native/issues/2503
176+
if (scalaBinaryVersion.value == "3") {
177+
(Compile / doc / scalacOptions).value.filter(_.contains("-Xplugin"))
178+
} else {
179+
Nil
180+
}
181+
},
182+
publish / skip := CrossVersion.partialVersion(scalaVersion.value) == Some((3, 0)),
183+
Test / scalacOptions ++= {
184+
if (CrossVersion.partialVersion(scalaVersion.value) != Some((3, 0))) {
185+
val log = streams.value.log
186+
val retrieveDir = baseDirectory.value / "scala-native-junit-plugin-jars"
187+
val lm = dependencyResolution.value
188+
val cp = lm
189+
.retrieve(
190+
"org.scala-native" % s"junit-plugin_${scalaVersion.value}" % nativeVersion,
191+
scalaModuleInfo = None,
192+
retrieveDir,
193+
log
194+
)
195+
.fold(w => throw w.resolveException, identity(_))
196+
val jarPath = cp
197+
.find(_.toString.contains("junit-plugin"))
198+
.getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar"))
199+
Seq(s"-Xplugin:$jarPath")
200+
} else {
201+
Nil
202+
}
163203
},
164204
Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v")
165205
)

0 commit comments

Comments
 (0)