Skip to content

Commit

Permalink
Crosscompile worker to support SN 0.4.1-
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Jan 25, 2022
1 parent 12d1585 commit 16a419c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
11 changes: 7 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
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.scalaVersion
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
15 changes: 12 additions & 3 deletions scalanativelib/src/ScalaNativeModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ 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")
resolveFilter = _.toString.contains("mill-scalanativelib-worker"),
artifactSuffix = s"_$workerScalaBinaryVersion"
)
}

Expand Down Expand Up @@ -84,7 +93,7 @@ trait ScalaNativeModule extends ScalaModule { outer =>
def bridgeFullClassPath: T[Agg[os.Path]] = T {
Lib.resolveDependencies(
repositoriesTask(),
Lib.depToDependency(_, mill.BuildInfo.scalaVersion, ""),
Lib.depToDependency(_, scalaNativeWorkerScalaVersion(), ""),
toolsIvyDeps(),
ctx = Some(T.log)
).map(t => (scalaNativeWorkerClasspath() ++ t).map(_.path))
Expand Down
4 changes: 3 additions & 1 deletion scalanativelib/src/ScalaNativeWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +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,
getClass.getClassLoader
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 @@ -24,7 +24,7 @@ object HelloNativeWorldTests extends TestSuite {
}

val scala213 = "2.13.6"
val scalaNative04 = "0.4.2"
val scalaNative04 = "0.4.0"

object HelloNativeWorld extends TestUtil.BaseModule {
val matrix = for {
Expand Down Expand Up @@ -231,7 +231,7 @@ object HelloNativeWorldTests extends TestSuite {
)

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

common ++ scalaVersionSpecific ++ scalaNativeVersionSpecific
Expand Down
2 changes: 1 addition & 1 deletion scalanativelib/worker/0.4/src/ScalaNativeWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ScalaNativeWorkerImpl extends mill.scalanativelib.api.ScalaNativeWorkerApi
logLevel: NativeLogLevel
): NativeConfig = {
val entry = Versions.current match {
case "0.4.2" => mainClass + "$"
case "0.4.0" | "0.4.1" | "0.4.2" => mainClass + "$"
case _ => mainClass
}
val config =
Expand Down

0 comments on commit 16a419c

Please sign in to comment.