Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ScalaNativeModule use Scala 2.13 toolchain when available #1693

Merged
merged 3 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ object Deps {
}

object Scalanative_0_4 {
val scalanativeTools = ivy"org.scala-native::tools:0.4.0"
val scalanativeUtil = ivy"org.scala-native::util:0.4.0"
val scalanativeNir = ivy"org.scala-native::nir:0.4.0"
val scalanativeTestRunner = ivy"org.scala-native::test-runner:0.4.0"
val scalanativeTools = ivy"org.scala-native::tools:0.4.2"
val scalanativeUtil = ivy"org.scala-native::util:0.4.2"
val scalanativeNir = ivy"org.scala-native::nir:0.4.2"
val scalanativeTestRunner = ivy"org.scala-native::test-runner:0.4.2"
}

val acyclic = ivy"com.lihaoyi::acyclic:0.2.1"
Expand Down Expand Up @@ -291,6 +291,8 @@ object main extends MillModule {
|object BuildInfo {
| /** Scala version used to compile mill core. */
| val scalaVersion = "$scalaVersion"
| /** Scala 2.12 version used by some workers. */
| val workerScalaVersion212 = "${Deps.workerScalaVersion212}"
| /** Mill version. */
| val millVersion = "$millVersion"
| /** Mill binary platform version. */
Expand Down Expand Up @@ -708,7 +710,8 @@ object scalanativelib extends MillModule {

override def testArgs = T {
val mapping = Map(
"MILL_SCALANATIVE_WORKER_0_4" -> worker("0.4").compile().classes.path
"MILL_SCALANATIVE_WORKER_0_4_2_12" -> worker("0.4", Deps.workerScalaVersion212).compile().classes.path,
"MILL_SCALANATIVE_WORKER_0_4_2_13" -> worker("0.4", Deps.scalaVersion).compile().classes.path
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
Expand All @@ -718,9 +721,9 @@ object scalanativelib extends MillModule {
object api extends MillPublishModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.4")
class WorkerModule(scalaNativeWorkerVersion: String) extends MillInternalModule {
override def scalaVersion = Deps.workerScalaVersion212
object worker extends Cross[WorkerModule](("0.4", Deps.scalaVersion), ("0.4", Deps.workerScalaVersion212))
class WorkerModule(scalaNativeWorkerVersion: String, val crossScalaVersion: String) extends CrossModuleBase with MillInternalModule {
override def scalaVersion = T { crossScalaVersion }
override def moduleDeps = Seq(scalanativelib.api)
override def ivyDeps = scalaNativeWorkerVersion match {
case "0.4" =>
Expand Down
2 changes: 1 addition & 1 deletion contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object BloopTests extends TestSuite {
object scalanativeModule extends scalanativelib.ScalaNativeModule with testBloop.Module {
override def skipBloop: Boolean = scala.util.Properties.isWin
override def scalaVersion = "2.13.4"
override def scalaNativeVersion = "0.4.0"
override def scalaNativeVersion = "0.4.2"
override def releaseMode = T(ReleaseMode.Debug)
}

Expand Down
20 changes: 13 additions & 7 deletions scalanativelib/src/ScalaNativeModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,29 @@ trait ScalaNativeModule extends ScalaModule { outer =>
mill.scalanativelib.ScalaNativeWorkerApi.scalaNativeWorker().impl(bridgeFullClassPath())
}

private def scalaNativeWorkerScalaVersion = T.task {
scalaNativeVersion() match {
case "0.4.0" | "0.4.1" => mill.BuildInfo.workerScalaVersion212
case _ => mill.BuildInfo.scalaVersion
}
}

def scalaNativeWorkerClasspath = T {
val workerKey = "MILL_SCALANATIVE_WORKER_" + scalaNativeWorkerVersion().replace('.', '_')
val workerScalaBinaryVersion = scalaBinaryVersion(scalaNativeWorkerScalaVersion())
val workerKey = s"MILL_SCALANATIVE_WORKER_${scalaNativeWorkerVersion()}_$workerScalaBinaryVersion".replace('.', '_')
mill.modules.Util.millProjectModule(
workerKey,
s"mill-scalanativelib-worker-${scalaNativeWorkerVersion()}",
repositoriesTask(),
resolveFilter = _.toString.contains("mill-scalanativelib-worker"),
artifactSuffix = "_2.12"
artifactSuffix = s"_$workerScalaBinaryVersion"
)
}

def toolsIvyDeps = T {
Agg(
ivy"org.scala-native:tools_2.12:${scalaNativeVersion()}",
ivy"org.scala-native:test-runner_2.12:${scalaNativeVersion()}"
ivy"org.scala-native::tools:${scalaNativeVersion()}",
ivy"org.scala-native::test-runner:${scalaNativeVersion()}"
)
}

Expand All @@ -82,12 +90,10 @@ trait ScalaNativeModule extends ScalaModule { outer =>
super.mandatoryIvyDeps() ++ nativeIvyDeps()
}

// Using `resolveDeps` from `CoursierModule` incorrectly resolves
// scala-library 2.13 instead of the required 2.12
def bridgeFullClassPath: T[Agg[os.Path]] = T {
Lib.resolveDependencies(
repositoriesTask(),
resolveCoursierDependency().apply(_),
Lib.depToDependency(_, scalaNativeWorkerScalaVersion(), ""),
toolsIvyDeps(),
ctx = Some(T.log)
).map(t => (scalaNativeWorkerClasspath() ++ t).map(_.path))
Expand Down
5 changes: 3 additions & 2 deletions scalanativelib/src/ScalaNativeWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class ScalaNativeWorker {

def impl(toolsClasspath: Agg[os.Path])(implicit ctx: mill.api.Ctx.Home): ScalaNativeWorkerApi = {
val classloaderSig = toolsClasspath.map(p => p.toString().hashCode + os.mtime(p)).sum
val isScala213 = toolsClasspath.exists(_.last.endsWith("_2.13.jar"))
scalaInstanceCache match {
case Some((sig, bridge)) if sig == classloaderSig => bridge
case _ =>
val cl = mill.api.ClassLoader.create(
toolsClasspath.map(_.toIO.toURI.toURL).toSeq,
null,
sharedPrefixes = Seq("mill.scalanativelib.api.", "sbt.testing.")
parent = if(isScala213) getClass.getClassLoader else null,
sharedPrefixes = if(isScala213) Seq.empty else Seq("mill.scalanativelib.api.", "sbt.testing.")
)
try {
val bridge = cl
Expand Down
4 changes: 2 additions & 2 deletions scalanativelib/test/src/HelloNativeWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object HelloNativeWorldTests extends TestSuite {
object HelloNativeWorld extends TestUtil.BaseModule {
val matrix = for {
scala <- Seq("3.1.0", scala213, "2.12.13", "2.11.12")
scalaNative <- Seq(scalaNative04, "0.4.3-RC2")
scalaNative <- Seq(scalaNative04, "0.4.3")
mode <- List(ReleaseMode.Debug, ReleaseMode.ReleaseFast)
if !(isScala3(scala) && scalaNative == scalaNative04)
} yield (scala, scalaNative, mode)
Expand Down Expand Up @@ -231,7 +231,7 @@ object HelloNativeWorldTests extends TestSuite {
)

val scalaNativeVersionSpecific =
if (scalaNativeVersion == "0.4.0") Set.empty
if (scalaNativeVersion == scalaNative04) Set.empty
else Set("Main.nir", "ArgsParser.nir")

common ++ scalaVersionSpecific ++ scalaNativeVersionSpecific
Expand Down