From 575f8889de4acbabf2c7be50173cd5000ede79fb Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Wed, 28 Feb 2024 16:35:20 +0100 Subject: [PATCH] Support Scala Native 0.5.0-RC1 --- build.sc | 21 +++++++++++++++++-- .../scalanativelib/ScalaNativeModule.scala | 10 +++++---- .../HelloNativeWorldTests.scala | 16 +++++++++----- .../worker/ScalaNativeWorkerImpl.scala | 11 +++------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/build.sc b/build.sc index 3b65aedf441..c5ff6f8585a 100644 --- a/build.sc +++ b/build.sc @@ -86,6 +86,14 @@ object Deps { val scalanativeTestRunner = ivy"org.scala-native::test-runner:${scalanativeVersion}" } + object Scalanative_0_5 { + val scalanativeVersion = "0.5.0-RC1" + val scalanativeTools = ivy"org.scala-native::tools:${scalanativeVersion}" + val scalanativeUtil = ivy"org.scala-native::util:${scalanativeVersion}" + val scalanativeNir = ivy"org.scala-native::nir:${scalanativeVersion}" + val scalanativeTestRunner = ivy"org.scala-native::test-runner:${scalanativeVersion}" + } + trait Play { def playVersion: String def playBinVersion: String = playVersion.split("[.]").take(2).mkString(".") @@ -395,7 +403,8 @@ trait MillBaseTestsModule extends MillJavaModule with TestModule { s"-DTEST_SCALA_3_2_VERSION=${Deps.testScala32Version}", s"-DTEST_SCALA_3_3_VERSION=${Deps.testScala33Version}", s"-DTEST_SCALAJS_VERSION=${Deps.Scalajs_1.scalaJsVersion}", - s"-DTEST_SCALANATIVE_VERSION=${Deps.Scalanative_0_4.scalanativeVersion}", + s"-DTEST_SCALANATIVE_0_4_VERSION=${Deps.Scalanative_0_4.scalanativeVersion}", + s"-DTEST_SCALANATIVE_0_5_VERSION=${Deps.Scalanative_0_5.scalanativeVersion}", s"-DTEST_UTEST_VERSION=${Deps.utest.dep.version}", s"-DTEST_SCALATEST_VERSION=${Deps.TestDeps.scalaTest.dep.version}", s"-DTEST_TEST_INTERFACE_VERSION=${Deps.sbtTestInterface.dep.version}", @@ -954,7 +963,7 @@ object scalanativelib extends MillStableScalaModule { def ivyDeps = Agg(Deps.sbtTestInterface) } - object worker extends Cross[WorkerModule]("0.4") + object worker extends Cross[WorkerModule]("0.4", "0.5") trait WorkerModule extends MillPublishScalaModule with Cross.Module[String] { def scalaNativeWorkerVersion = crossValue @@ -962,6 +971,14 @@ object scalanativelib extends MillStableScalaModule { def testDepPaths = T { Seq(compile().classes) } def moduleDeps = Seq(scalanativelib.`worker-api`) def ivyDeps = scalaNativeWorkerVersion match { + case "0.5" => + Agg( + Deps.osLib, + Deps.Scalanative_0_5.scalanativeTools, + Deps.Scalanative_0_5.scalanativeUtil, + Deps.Scalanative_0_5.scalanativeNir, + Deps.Scalanative_0_5.scalanativeTestRunner + ) case "0.4" => Agg( Deps.osLib, diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index faaa6a2fd67..1e94fe7a8bc 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -66,10 +66,12 @@ trait ScalaNativeModule extends ScalaModule { outer => def nativeIvyDeps: T[Agg[Dep]] = T { val scalaVersionSpecific = - if (ZincWorkerUtil.isScala3(scalaVersion())) - Agg(ivy"org.scala-native::scala3lib::${scalaNativeVersion()}") - else - Agg(ivy"org.scala-native::scalalib::${scalaNativeVersion()}") + if (ZincWorkerUtil.isScala3(scalaVersion())) { + if (scalaNativeVersion().startsWith("0.4")) + Agg(ivy"org.scala-native::scala3lib::${scalaNativeVersion()}") + else + Agg(ivy"org.scala-native::scala3lib::${scalaVersion()}+${scalaNativeVersion()}") + } else Agg(ivy"org.scala-native::scalalib::${scalaNativeVersion()}") Agg( ivy"org.scala-native::nativelib::${scalaNativeVersion()}", diff --git a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala index 618320d60af..a3bf98f6d1e 100644 --- a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala +++ b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala @@ -30,18 +30,24 @@ object HelloNativeWorldTests extends TestSuite { override def mainClass = Some("hello.Main") } - val scala213 = "2.13.6" - val scalaNative04 = "0.4.2" + val scala213 = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + val scala31 = sys.props.getOrElse("TEST_SCALA_3_1_VERSION", ???) + val scala33 = sys.props.getOrElse("TEST_SCALA_3_3_VERSION", ???) + val scalaNative04Old = "0.4.2" + val scalaNative04 = sys.props.getOrElse("TEST_SCALANATIVE_0_4_VERSION", ???) + val scalaNative05 = sys.props.getOrElse("TEST_SCALANATIVE_0_5_VERSION", ???) object HelloNativeWorld extends TestUtil.BaseModule { implicit object ReleaseModeToSegments extends Cross.ToSegments[ReleaseMode](v => List(v.toString)) val matrix = for { - scala <- Seq("3.2.1", "3.1.3", scala213, "2.12.13", "2.11.12") - scalaNative <- Seq(scalaNative04, "0.4.9") + scala <- Seq(scala33, scala31, scala213, "2.12.13", "2.11.12") + scalaNative <- Seq(scalaNative04Old, scalaNative04, scalaNative05) mode <- List(ReleaseMode.Debug, ReleaseMode.ReleaseFast) - if !(ZincWorkerUtil.isScala3(scala) && scalaNative == scalaNative04) + if !(ZincWorkerUtil.isScala3(scala) && scalaNative == scalaNative04Old) + if !(scala.startsWith("2.11") && scalaNative == scalaNative05) + if !(scala.startsWith("2.12") && scalaNative == scalaNative05) } yield (scala, scalaNative, mode) object helloNativeWorld extends Cross[RootModule](matrix) diff --git a/scalanativelib/worker/0.4/src/mill/scalanativelib/worker/ScalaNativeWorkerImpl.scala b/scalanativelib/worker/0.4/src/mill/scalanativelib/worker/ScalaNativeWorkerImpl.scala index db356fd0c29..39a36b7f777 100644 --- a/scalanativelib/worker/0.4/src/mill/scalanativelib/worker/ScalaNativeWorkerImpl.scala +++ b/scalanativelib/worker/0.4/src/mill/scalanativelib/worker/ScalaNativeWorkerImpl.scala @@ -20,15 +20,10 @@ import scala.scalanative.build.{ import scala.scalanative.nir.Versions import scala.scalanative.testinterface.adapter.TestAdapter -import scala.util.{Success, Try} - class ScalaNativeWorkerImpl extends mill.scalanativelib.worker.api.ScalaNativeWorkerApi { - private def patchIsGreaterThanOrEqual(number: Int) = { - val patch = Versions.current.stripPrefix("0.4.") - Try(patch.toInt) match { - case Success(n) if n < number => false - case _ => true - } + private def patchIsGreaterThanOrEqual(number: Int) = Versions.current match { + case s"0.4.$n" if n.toIntOption.exists(_ < number) => false + case _ => true } def logger(level: NativeLogLevel): Logger =