Skip to content

Commit 61666f0

Browse files
committed
Simplify Mill cross-build to only include major version
This simplifies commands from, e.g. `mill chisel[2.13.18].compile` to just `mill chisel[2.13].compile`. This makes it such that we no longer have to change CI and documentation whenever we add support for a new minor version of Scala.
1 parent c3a1aef commit 61666f0

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

benchmark/package.mill

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import mill.contrib.jmh.JmhModule
88
import build._
99

1010
object `package` extends ScalaModule with JmhModule with ScalafmtModule {
11-
def scalaVersion = v.scalaVersion
11+
def scalaVersion = v.defaultScalaVersion
1212
def jmhCoreVersion = v.jmhVersion
1313

14-
override def moduleDeps = Seq(chisel(v.scalaVersion))
14+
override def moduleDeps = Seq(chisel(v.defaultScalaVersion))
1515
}

build.mill

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import mill.scalalib.scalafmt._
1414

1515
object v extends Module {
1616

17+
// Add support for later Scala 2.13 by bumping this.
18+
val scala213MinorVersion: Int = 18
19+
20+
// Bump Scala 3 version by bumping this.
21+
val scala3MinorVersion: String = "3.4"
22+
1723
val javaVersion = {
1824
val rawVersion = sys.props("java.specification.version")
1925
// Older versions of Java started with 1., e.g. 1.8 == 8
@@ -32,20 +38,21 @@ object v extends Module {
3238
// Only publish plugin for 2.13.11+ when using Java > 11, but still
3339
// publish all versions when Java version <= 11.
3440
val pluginScalaCrossVersions = {
35-
val latest213 = 18
3641
val java21Min213 = 11
3742
val minVersion = if (javaVersion > 11) java21Min213 else 0
38-
val versions = minVersion to latest213
43+
val versions = minVersion to scala213MinorVersion
3944
val versionSeq = versions.map(v => s"2.13.$v").toSeq
40-
versionSeq ++ Seq("3.3.4")
45+
versionSeq :+ scalaCrossToVersion("3")
4146
}
4247

43-
val scalaCrossVersions = Seq(
44-
"2.13.18",
45-
"3.3.4"
46-
)
48+
val scalaCrossVersions = Seq("2.13", "3")
49+
50+
def scalaCrossToVersion(major: String): String = major match {
51+
case "2.13" => s"2.13.$scala213MinorVersion"
52+
case "3" => s"3.$scala3MinorVersion"
53+
}
4754

48-
def isScala3(ver: String): Boolean = ver.startsWith("3.")
55+
def isScala3(ver: String): Boolean = ver.startsWith("3")
4956

5057
def buildUnits(): Seq[ScalaModule] = {
5158
scalaCrossVersions.flatMap { ver =>
@@ -68,7 +75,10 @@ object v extends Module {
6875
}
6976
}
7077

71-
val scalaVersion = scalaCrossVersions.head
78+
def defaultCrossVersion = scalaCrossVersions.head
79+
80+
def defaultScalaVersion = scalaCrossToVersion(defaultCrossVersion)
81+
7282
val jmhVersion = "1.37"
7383
val osLib = mvn"com.lihaoyi::os-lib:0.10.7" // 0.11 requires Java 11
7484
val upickle = mvn"com.lihaoyi::upickle:3.3.1" // upickle 4.0 requires Scala 3.4 (we target Scala 3.3 LTS)
@@ -329,10 +339,12 @@ trait HasPanamaConverterModule extends ScalaModule with HasCIRCTPanamaBindingMod
329339
object chisel extends Cross[Chisel](v.scalaCrossVersions)
330340

331341
trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScalaPlugin with ScalafmtModule {
342+
def scalaVersion = v.scalaCrossToVersion(crossScalaVersion)
343+
332344
override def moduleDir = super.moduleDir / os.up
333345
def svsimModule = svsim.cross(crossScalaVersion)
334346
def coreModule = core.cross(crossScalaVersion)
335-
def pluginModule = plugin.cross()
347+
def pluginModule = plugin.cross(v.scalaCrossToVersion(crossScalaVersion))
336348

337349
override def scalacOptions = Task {
338350
if (v.isScala3(crossScalaVersion)) {

core/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object `package` extends Module {
1313
}
1414

1515
trait Core extends CrossSbtModule with HasScala2MacroAnno with HasCommonOptions with ScalafmtModule {
16-
def scalaVersion = crossScalaVersion
16+
def scalaVersion = v.scalaCrossToVersion(crossScalaVersion)
1717

1818
def moduleDir = super.moduleDir / os.up
1919

docs/package.mill

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import build._
1313
/** MDoc project */
1414
object `package` extends SbtModule with HasScalaPlugin with HasCommonOptions {
1515

16-
override def scalaVersion = v.scalaVersion
16+
override def scalaVersion = v.defaultScalaVersion
1717

1818
// This not really a CrossModule but HasScala2Plugin and HasCommonOptions require it
19-
override def crossValue = v.scalaVersion
19+
override def crossValue = v.scalaCrossVersions.head
2020

2121
def pluginModule = plugin.cross()
2222

@@ -25,7 +25,7 @@ object `package` extends SbtModule with HasScalaPlugin with HasCommonOptions {
2525

2626
override def mvnDeps = Task { Seq(v.mdoc, v.scalatest) }
2727

28-
override def moduleDeps = Seq(chisel(v.scalaVersion))
28+
override def moduleDeps = Seq(chisel(v.defaultScalaVersion))
2929

3030
// Suppress missing interpolator warnings because mdoc appears to introduce them.
3131
override def extraWarnConf = Seq("msg=possible missing interpolator:s")

firrtl/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Firrtl
1818
with HasScala2MacroAnno
1919
with HasCommonOptions
2020
with ScalafmtModule {
21-
def scalaVersion = crossScalaVersion
21+
def scalaVersion = v.scalaCrossToVersion(crossScalaVersion)
2222

2323
def moduleDir = super.moduleDir / os.up
2424

macros/package.mill

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ object `package` extends Module {
1313
}
1414

1515
trait Macros extends CrossSbtModule with HasScala2MacroAnno with HasCommonOptions with ScalafmtModule {
16+
def scalaVersion = v.scalaCrossToVersion(crossScalaVersion)
17+
1618
def moduleDir = super.moduleDir / os.up
1719

1820
override def mvnDeps =

release.mill

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait ChiselPublishModule extends SonatypeCentralPublishModule {
3636
*/
3737
trait Unipublish extends ScalaModule with ChiselPublishModule with Mima {
3838

39-
def scalaVersion = v.scalaVersion
39+
def scalaVersion = v.defaultScalaVersion
4040

4141
/** Is this a SNAPSHOT release? */
4242
def isSnapshot = Task { publishVersion().endsWith("-SNAPSHOT") }
@@ -69,12 +69,12 @@ trait Unipublish extends ScalaModule with ChiselPublishModule with Mima {
6969
transitive: Boolean = false
7070
) = Task.Command {
7171
// TODO consider making this parallel and publishing all cross-versions for plugin
72-
plugin.cross(v.scalaVersion).publishLocal(localMvnRepo, sources, doc, transitive)()
72+
plugin.cross(v.defaultScalaVersion).publishLocal(localMvnRepo, sources, doc, transitive)()
7373
super.publishLocal(localMvnRepo, sources, doc, transitive)()
7474
}
7575

7676
// Explicitly not using moduleDeps because that influences so many things
77-
def components = Seq(firrtl.cross, svsim.cross, macros.cross, core.cross, chisel).map(_(v.scalaVersion))
77+
def components = Seq(firrtl.cross, svsim.cross, macros.cross, core.cross, chisel).map(_(v.defaultCrossVersion))
7878

7979
/** Aggregated mvn deps to include as dependencies in POM */
8080
def mvnDeps = Task { Task.traverse(components)(_.mvnDeps)().flatten }

svsim/package.mill

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ object `package` extends Module {
1313
}
1414

1515
trait Svsim extends CrossSbtModule with HasCommonOptions with ScalafmtModule {
16+
def scalaVersion = v.scalaCrossToVersion(crossScalaVersion)
17+
1618
def moduleDir = super.moduleDir / os.up
1719

1820
override def scalacOptions = Task {

0 commit comments

Comments
 (0)