Skip to content

Commit

Permalink
Support Scala Native 0.5.0-RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Feb 28, 2024
1 parent 126f574 commit 575f888
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
21 changes: 19 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -954,14 +963,22 @@ 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
def millSourcePath: os.Path = super.millSourcePath / scalaNativeWorkerVersion
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,
Expand Down
10 changes: 6 additions & 4 deletions scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 575f888

Please sign in to comment.