From a41c06bc7c6cfd89c26dd5d6de8f55422bf7d595 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Wed, 5 Jan 2022 15:00:09 +0900 Subject: [PATCH] support scala-native Scala 3 build --- .circleci/config.yml | 3 ++ build.sbt | 76 +++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ea99f344..27d9cb30 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -157,3 +157,6 @@ workflows: - scalanative_job: name: native0.4_2.13 scala_version: 2.13.8 + - scalanative_job: + name: native0.4_3 + scala_version: 3.1.0 diff --git a/build.sbt b/build.sbt index e7113a38..ae66be95 100644 --- a/build.sbt +++ b/build.sbt @@ -140,26 +140,66 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform) ) .jsEnablePlugins(ScalaJSJUnitPlugin) .nativeSettings( - crossScalaVersions := Seq("2.13.8", "2.12.15"), + crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.0"), + mimaPreviousArtifacts := { + // TODO remove this setting whien 2.0.2 released + if (scalaBinaryVersion.value == "3") { + mimaPreviousArtifacts.value.filterNot(_.revision == "2.0.1") + } else { + mimaPreviousArtifacts.value + } + }, // Scala Native cannot run forked tests Test / fork := false, - libraryDependencies += "org.scala-native" %%% "junit-runtime" % nativeVersion % Test, - Test / scalacOptions += { - val log = streams.value.log - val retrieveDir = baseDirectory.value / "scala-native-junit-plugin-jars" - val lm = dependencyResolution.value - val cp = lm - .retrieve( - "org.scala-native" % s"junit-plugin_${scalaVersion.value}" % nativeVersion, - scalaModuleInfo = None, - retrieveDir, - log - ) - .fold(w => throw w.resolveException, identity(_)) - val jarPath = cp - .find(_.toString.contains("junit-plugin")) - .getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar")) - s"-Xplugin:$jarPath" + Seq(Compile, Test).map { s => + s / sources := { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((3, 0)) => + Nil + case _ => + (s / sources).value + } + } + }, + libraryDependencies := { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((3, 0)) => + // scala-native does not support Scala 3.0.x + Nil + case _ => + libraryDependencies.value ++ Seq("org.scala-native" %%% "junit-runtime" % nativeVersion % Test) + } + }, + Compile / doc / scalacOptions --= { + // TODO remove this workaround + // https://github.com/scala-native/scala-native/issues/2503 + if (scalaBinaryVersion.value == "3") { + (Compile / doc / scalacOptions).value.filter(_.contains("-Xplugin")) + } else { + Nil + } + }, + publish / skip := CrossVersion.partialVersion(scalaVersion.value) == Some((3, 0)), + Test / scalacOptions ++= { + if (CrossVersion.partialVersion(scalaVersion.value) != Some((3, 0))) { + val log = streams.value.log + val retrieveDir = baseDirectory.value / "scala-native-junit-plugin-jars" + val lm = dependencyResolution.value + val cp = lm + .retrieve( + "org.scala-native" % s"junit-plugin_${scalaVersion.value}" % nativeVersion, + scalaModuleInfo = None, + retrieveDir, + log + ) + .fold(w => throw w.resolveException, identity(_)) + val jarPath = cp + .find(_.toString.contains("junit-plugin")) + .getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar")) + Seq(s"-Xplugin:$jarPath") + } else { + Nil + } }, Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v") )