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 1/3] 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") ) From 3378b026cbffa6416ea7fc43ec5fc254cd145045 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Thu, 3 Feb 2022 14:15:11 +0100 Subject: [PATCH 2/3] Skip tasks with Scala Native / Scala 3.0 - Update Scala Native Scala 3 version to 3.1.1 --- .circleci/config.yml | 2 +- build.sbt | 86 ++++++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 52 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 27d9cb30..34b80553 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -159,4 +159,4 @@ workflows: scala_version: 2.13.8 - scalanative_job: name: native0.4_3 - scala_version: 3.1.0 + scala_version: 3.1.1 diff --git a/build.sbt b/build.sbt index ae66be95..74f5d5b5 100644 --- a/build.sbt +++ b/build.sbt @@ -140,7 +140,7 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform) ) .jsEnablePlugins(ScalaJSJUnitPlugin) .nativeSettings( - crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.0"), + crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.1"), mimaPreviousArtifacts := { // TODO remove this setting whien 2.0.2 released if (scalaBinaryVersion.value == "3") { @@ -151,55 +151,39 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform) }, // Scala Native cannot run forked tests Test / fork := false, - 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 - } + 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" }, - Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v") + Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v"), + // Scala Native doesn't support Scala 3.0 + Compile / nativeLink := { if(isScala30(scalaVersion.value)) null else (Compile / nativeLink).value }, + Test / nativeLink := { if(isScala30(scalaVersion.value)) null else (Test / nativeLink).value }, + Test / test := { if(isScala30(scalaVersion.value)) {} else (Test / test).value }, + Compile / sources := { if(isScala30(scalaVersion.value)) Nil else (Compile / sources).value }, + Test / sources := { if(isScala30(scalaVersion.value)) Nil else (Test / sources).value }, + libraryDependencies := { if(isScala30(scalaVersion.value)) Nil else libraryDependencies.value }, + Test / scalacOptions := { if(isScala30(scalaVersion.value)) Nil else (Test / scalacOptions).value }, + publish / skip := { isScala30(scalaVersion.value) }, ) + +def isScala30(scalaVersion: String) = { + CrossVersion.partialVersion(scalaVersion) match { + case Some((3, 0)) => true + case _ => false + } +} From 5bee75b7f40a7272716858f3d8e5585c4c9a29ee Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 14 Mar 2022 17:31:23 +0100 Subject: [PATCH 3/3] Fix typo in build.sbt Co-authored-by: Eric K Richardson --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 74f5d5b5..41a77e83 100644 --- a/build.sbt +++ b/build.sbt @@ -142,7 +142,7 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform) .nativeSettings( crossScalaVersions := Seq("2.13.8", "2.12.15", "3.1.1"), mimaPreviousArtifacts := { - // TODO remove this setting whien 2.0.2 released + // TODO remove this setting when 2.0.2 released if (scalaBinaryVersion.value == "3") { mimaPreviousArtifacts.value.filterNot(_.revision == "2.0.1") } else {