Skip to content
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
61 changes: 15 additions & 46 deletions build.mill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import mill._
import mill.api.Loose
import scalalib.{publish => _, _}
import mill.contrib.bloop.Bloop
import mill.define.Task.Simple
import mill.testrunner.TestResult

import _root_.scala.util.{Properties, Using}
Expand Down Expand Up @@ -109,15 +110,6 @@ object `test-runner` extends Cross[TestRunner](Scala.runnerScalaVersions)
with CrossScalaDefaultToRunner
object `tasty-lib` extends Cross[TastyLib](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
// Runtime classes used within native image on Scala 3 replacing runtime from Scala
object `scala3-runtime` extends Cross[Scala3Runtime](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
// Logic to process classes that is shared between build and the scala-cli itself
object `scala3-graal` extends Cross[Scala3Graal](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal
// Main app used to process classpath within build itself
object `scala3-graal-processor` extends Cross[Scala3GraalProcessor](Scala.scala3MainVersions)
with CrossScalaDefaultToInternal

object `scala-cli-bsp` extends JavaModule with ScalaCliPublishModule {
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Seq(
Expand Down Expand Up @@ -685,38 +677,6 @@ trait Options extends ScalaCliCrossSbtModule with ScalaCliPublishModule with Has
}
}

trait Scala3Runtime extends CrossSbtModule with ScalaCliPublishModule {
override def crossScalaVersion: String = crossValue
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps()
}

trait Scala3Graal extends ScalaCliCrossSbtModule
with ScalaCliPublishModule with ScalaCliScalafixModule {
override def crossScalaVersion: String = crossValue
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(
Deps.asm,
Deps.osLib
)

override def resources: T[Seq[PathRef]] = Task.Sources {
val extraResourceDir = Task.dest / "extra"
// scala3RuntimeFixes.jar is also used within
// resource-config.json and BytecodeProcessor.scala
os.copy.over(
`scala3-runtime`(crossScalaVersion).jar().path,
extraResourceDir / "scala3RuntimeFixes.jar",
createFolders = true
)
super.resources() ++ Seq(mill.PathRef(extraResourceDir))
}
}

trait Scala3GraalProcessor extends CrossScalaModule with ScalaCliPublishModule {
override def moduleDeps: Seq[SonatypeCentralPublishModule] =
Seq(`scala3-graal`(crossScalaVersion))
override def finalMainClass: T[String] = "scala.cli.graal.CoursierCacheProcessor"
}

trait Build extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with HasTests
Expand Down Expand Up @@ -926,7 +886,6 @@ trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
`build-module`(crossScalaVersion),
config(crossScalaVersion),
`scala3-graal`(crossScalaVersion),
`specification-level`(crossScalaVersion)
)

Expand All @@ -948,21 +907,31 @@ trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
Deps.signingCli.exclude((organization, "config_2.13")),
Deps.slf4jNop, // to silence jgit
Deps.sttp,
Deps.scalafixInterfaces
Deps.scalafixInterfaces,
Deps.scala3Graal, // TODO: drop this if we ever bump internal JDK to 24+
Deps.scala3GraalProcessor // TODO: drop this if we ever bump internal JDK to 24+
)
override def compileIvyDeps: T[Agg[Dep]] = super.compileIvyDeps() ++ Agg(
Deps.jsoniterMacros,
Deps.svm
)
override def mainClass: T[Option[String]] = Some("scala.cli.ScalaCli")

private def scala3GraalProcessorClassPath: T[Agg[PathRef]] = T {
resolveDeps(T {
val bind = bindDependency()
Agg(Deps.scala3GraalProcessor).map(bind)
})()
}

override def nativeImageClassPath: T[Seq[PathRef]] = Task {
val classpath = super.nativeImageClassPath().map(_.path).mkString(File.pathSeparator)
val cache = Task.dest / "native-cp"
// `scala3-graal-processor`.run() do not give me output and I cannot pass dynamically computed values like classpath
// `scala3-graal-processor`.run() does not give me output and I cannot pass dynamically computed values like classpath
// TODO: drop this if we ever bump internal JDK to 24+
val res = mill.util.Jvm.callProcess(
mainClass = `scala3-graal-processor`(crossScalaVersion).finalMainClass(),
classPath = `scala3-graal-processor`(crossScalaVersion).runClasspath().map(_.path),
mainClass = "scala.cli.graal.CoursierCacheProcessor",
classPath = scala3GraalProcessorClassPath().map(_.path).toList,
mainArgs = Seq(cache.toNIO.toString, classpath)
)
val cp = res.out.trim()
Expand Down
13 changes: 11 additions & 2 deletions modules/cli/src/main/scala/scala/cli/packaging/NativeImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import java.io.File

import scala.annotation.tailrec
import scala.build.internal.{ManifestJar, Runner}
import scala.build.internals.ConsoleUtils.ScalaCliConsole.warnPrefix
import scala.build.internals.EnvVar
import scala.build.{Build, Logger, Positioned}
import scala.build.{Build, Logger, Positioned, coursierVersion}
import scala.cli.errors.GraalVMNativeImageError
import scala.cli.graal.{BytecodeProcessor, TempCache}
import scala.cli.internal.CachedBinary
Expand Down Expand Up @@ -206,7 +207,15 @@ object NativeImage {
// seems native-image doesn't correctly parse paths in manifests - this is especially a problem on Windows
wrongSimplePathsInManifest = true
) { processedClassPath =>
val needsProcessing = builds.head.scalaParams.exists(_.scalaVersion.startsWith("3."))
val needsProcessing =
builds.head.scalaParams.map(_.scalaVersion.coursierVersion)
.exists(sv => (sv >= "3.0.0".coursierVersion) && (sv < "3.3.0".coursierVersion))
if needsProcessing then
logger.message(
s"""$warnPrefix building native images with Scala 3 older than 3.3.0 is deprecated.
|$warnPrefix support will be dropped in a future Scala CLI version.
|$warnPrefix it is advised to upgrade to a more recent Scala version.""".stripMargin
)
val (classPath, toClean, scala3extraOptions) =
if needsProcessing then {
val cpString = processedClassPath.mkString(File.pathSeparator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ class TestNativeImageOnScala3 extends ScalaCliSuite {
}
}

test("lazy vals") {
runTest("1")("2") {
"""//> using scala 3.1.1
|class A(a: String) { lazy val b = a.toInt + 1 }
|@main def add1(i: String) = println(A(i).b)
|""".stripMargin
}
for {
scalaVersion <- TestUtil.legacyScalaVersionsOnePerMinor.sorted ++ Seq(
Constants.scala3Lts,
Constants.scala3Next,
Constants.scala3NextRc
)
}
test(s"lazy vals ($scalaVersion)") {
runTest("1")("2") {
s"""//> using scala $scalaVersion
|class A(a: String) { lazy val b = a.toInt + 1 }
|@main def add1(i: String) = println(A(i).b)
|""".stripMargin
}
}

test("lazy vals and enums with default scala version") {
runTest("1")("2", "A") {
Expand Down

This file was deleted.

Loading