Skip to content

Commit 822df05

Browse files
lefounatsukagami
andauthored
Implement support for Scala 3.8 (#5751)
Instead of using a scala-library-2.13.x, since Scala 3.8.0 the used scala-library has the same version as the Scala version. Fix #5739 Co-authored-by: Natsu Kagami <[email protected]>
1 parent baf9887 commit 822df05

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

libs/javalib/api/src/mill/javalib/api/JvmWorkerUtil.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object JvmWorkerUtil {
4242
))
4343
}
4444

45-
val PartialVersion: Regex = raw"""(\d+)\.(\d+)\.*""".r
45+
val PartialVersion: Regex = raw"""(\d+)\.(\d+)\..*""".r
4646
val ReleaseVersion: Regex = raw"""(\d+)\.(\d+)\.(\d+)""".r
4747
val MinorSnapshotVersion: Regex = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r
4848
val DottyVersion: Regex = raw"""0\.(\d+)\.(\d+).*""".r
@@ -63,6 +63,10 @@ object JvmWorkerUtil {
6363
case _ => scalaVersion
6464
}
6565

66+
private def minorMajorVersion(version: String): (major: Int, minor: Int) = version match {
67+
case PartialVersion(major, minor) => (major = major.toInt, minor = minor.toInt)
68+
}
69+
6670
private val ScalaJSFullVersion = """^([0-9]+)\.([0-9]+)\.([0-9]+)(-.*)?$""".r
6771

6872
def scalaJSBinaryVersion(scalaJSVersion: String): String = scalaJSVersion match {
@@ -146,4 +150,22 @@ object JvmWorkerUtil {
146150
all.filter(v => v.nonEmpty && v >= versionParts.take(v.length)).map(_.mkString(".") + "-")
147151
(plus ++ minus).distinct.toSeq
148152
}
153+
154+
/**
155+
* Checks whether the version of the scala-library should be `2.13.x` or just match the given `scalaVersion`
156+
*
157+
* Background:
158+
* To help in Scala 3 adoption and ensure binary compatibility,
159+
* Scala 3.x up to 3.7.x used the same Scala standard library as Scala 2.13.
160+
* Since this also hinders further improvements of the standard library,
161+
* Scala 3.8 will ship with a newer library built with a Scala 3 compiler.
162+
*
163+
* @param scalaVersion The Scala version
164+
* @return `true` if the scala-library version should be enforced to be a `2.13.`
165+
*/
166+
def enforceScala213Library(scalaVersion: String): Boolean = {
167+
val sv = minorMajorVersion(scalaVersion)
168+
// Some Dotty versions and all Scala 3 versions before 3.8
169+
sv.major == 0 || (sv.major == 3 && sv.minor < 8)
170+
}
149171
}

libs/javalib/worker/src/mill/javalib/zinc/ZincWorker.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ class ZincWorker(
106106
loaderLibraryOnly = ClasspathUtil.rootLoader,
107107
libraryJars = Array(libraryJarNameGrep(
108108
compilerClasspath,
109-
// we don't support too outdated dotty versions
110-
// and because there will be no scala 2.14, so hardcode "2.13." here is acceptable
111-
if (JvmWorkerUtil.isDottyOrScala3(key.scalaVersion)) "2.13." else key.scalaVersion
109+
// if Dotty or Scala 3.0 - 3.7, use the 2.13 version of the standard library
110+
if (JvmWorkerUtil.enforceScala213Library(key.scalaVersion)) "2.13."
111+
// otherwise use the library matching the Scala version
112+
else key.scalaVersion
112113
).path.toIO),
113114
compilerJars = combinedCompilerJars,
114115
allJars = combinedCompilerJars,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package mill.scalalib
2+
3+
import mill.*
4+
import mill.api.{Discover, ModuleRef}
5+
import mill.testkit.{TestRootModule, UnitTester}
6+
import utest.*
7+
8+
// TODO: Once Scala 3.8.0 is out, we can change this test to use 3.8.0 and remove the extra repo
9+
object Scala38NightlyTests extends TestSuite {
10+
11+
val repo = "https://repo.scala-lang.org/artifactory/maven-nightlies"
12+
13+
object Scala38Nightly extends TestRootModule {
14+
object JvmWorker extends JvmWorkerModule {
15+
override def repositories = super.repositories() ++ Seq(repo)
16+
}
17+
object foo extends ScalaModule {
18+
override def jvmWorker: ModuleRef[JvmWorkerModule] = ModuleRef(JvmWorker)
19+
override def repositories = super.repositories() ++ Seq(repo)
20+
override def scalaVersion = "3.8.0-RC1-bin-20250825-ee2f641-NIGHTLY"
21+
override def mvnDeps = Seq(
22+
mvn"org.scala-lang.modules::scala-xml:2.4.0"
23+
)
24+
}
25+
26+
lazy val millDiscover = Discover[this.type]
27+
}
28+
29+
def tests: Tests = Tests {
30+
31+
test("scala38nightly") - UnitTester(
32+
Scala38Nightly,
33+
sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "dotty213"
34+
).scoped { eval =>
35+
val Right(result) = eval.apply(Scala38Nightly.foo.run()): @unchecked
36+
assert(result.evalCount > 0)
37+
}
38+
39+
}
40+
}

libs/scalalib/test/src/mill/scalalib/ScalaDotty213Tests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ object ScalaDotty213Tests extends TestSuite {
99
object Dotty213 extends TestRootModule {
1010
object foo extends ScalaModule {
1111
def scalaVersion = "0.18.1-RC1"
12-
override def mvnDeps =
13-
Seq(mvn"org.scala-lang.modules::scala-xml:1.2.0".withDottyCompat(scalaVersion()))
12+
override def mvnDeps = Seq(
13+
mvn"org.scala-lang.modules::scala-xml:1.2.0".withDottyCompat(scalaVersion())
14+
)
1415
}
1516

1617
lazy val millDiscover = Discover[this.type]

0 commit comments

Comments
 (0)