@@ -1588,6 +1588,128 @@ object Build {
15881588 )},
15891589 )
15901590
1591+ // ==============================================================================================
1592+ // ======================================= SCALA COMPILER =======================================
1593+ // ==============================================================================================
1594+
1595+ /* Configuration of the org.scala-lang:scala3-compiler_3:*.**.**-nonbootstrapped project */
1596+ lazy val `scala3-compiler-nonbootstrapped` = project.in(file(" compiler" ))
1597+ .dependsOn(`scala3-interfaces`, `tasty-core-nonbootstrapped`, `scala3-library-nonbootstrapped`)
1598+ .settings(
1599+ name := " scala3-compiler-nonbootstrapped" ,
1600+ moduleName := " scala3-compiler" ,
1601+ version := dottyNonBootstrappedVersion,
1602+ versionScheme := Some (" semver-spec" ),
1603+ scalaVersion := referenceVersion, // nonbootstrapped artifacts are compiled with the reference compiler (already officially published)
1604+ crossPaths := true , // org.scala-lang:scala3-compiler has a crosspath
1605+ // sbt shouldn't add stdlib automatically, we depend on `scala3-library-nonbootstrapped`
1606+ autoScalaLibrary := false ,
1607+ // Add the source directories for the stdlib (non-boostrapped)
1608+ Compile / unmanagedSourceDirectories := Seq (baseDirectory.value / " src" ),
1609+ Compile / unmanagedSourceDirectories += baseDirectory.value / " src-non-bootstrapped" ,
1610+ // All the dependencies needed by the compiler
1611+ libraryDependencies ++= Seq (
1612+ " org.scala-lang.modules" % " scala-asm" % " 9.8.0-scala-1" ,
1613+ Dependencies .compilerInterface,
1614+ " org.jline" % " jline-reader" % " 3.29.0" ,
1615+ " org.jline" % " jline-terminal" % " 3.29.0" ,
1616+ " org.jline" % " jline-terminal-jni" % " 3.29.0" ,
1617+ // ("io.get-coursier" %% "coursier" % "2.0.16" % Test).cross(CrossVersion.for3Use2_13),
1618+ ),
1619+ // NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1620+ Compile / scalacOptions := Seq (" -deprecation" , " -feature" , " -unchecked" , " -encoding" , " UTF8" , " -language:implicitConversions" ),
1621+ // TODO: Enable these flags when the new stdlib is explicitelly null checked
1622+ // Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-Wsafe-init"),
1623+ // Make sure that the produced artifacts have the minimum JVM version in the bytecode
1624+ Compile / javacOptions ++= Seq (" --target" , Versions .minimumJVMVersion),
1625+ Compile / scalacOptions ++= Seq (" --java-output-version" , Versions .minimumJVMVersion),
1626+ // Only publish compilation artifacts, no test artifacts
1627+ Compile / publishArtifact := true ,
1628+ Test / publishArtifact := false ,
1629+ // Do not allow to publish this project for now
1630+ publish / skip := true ,
1631+ // Project specific target folder. sbt doesn't like having two projects using the same target folder
1632+ target := target.value / " scala3-compiler-nonbootstrapped" ,
1633+ // Generate compiler.properties, used by sbt
1634+ Compile / resourceGenerators += Def .task {
1635+ import java .util ._
1636+ import java .text ._
1637+ val file = (Compile / resourceManaged).value / " compiler.properties"
1638+ val dateFormat = new SimpleDateFormat (" yyyyMMdd-HHmmss" )
1639+ dateFormat.setTimeZone(TimeZone .getTimeZone(" GMT" ))
1640+ val contents = // 2.11.11.v20170413-090219-8a413ba7cc
1641+ s """ version.number= ${version.value}
1642+ |maven.version.number= ${version.value}
1643+ |git.hash= ${VersionUtil .gitHash}
1644+ |copyright.string=Copyright 2002- $currentYear, LAMP/EPFL
1645+ """ .stripMargin
1646+
1647+ if (! (file.exists && IO .read(file) == contents)) {
1648+ IO .write(file, contents)
1649+ }
1650+
1651+ Seq (file)
1652+ }.taskValue,
1653+ // sbt adds all the projects to scala-tool config which breaks building the scalaInstance
1654+ // as a workaround, I build it manually by only adding the compiler
1655+ scalaInstance := {
1656+ val lm = dependencyResolution.value
1657+ val log = streams.value.log
1658+ val retrieveDir = streams.value.cacheDirectory / " scala3-compiler" / scalaVersion.value
1659+ val comp = lm.retrieve(" org.scala-lang" % " scala3-compiler_3" %
1660+ scalaVersion.value, scalaModuleInfo = None , retrieveDir, log)
1661+ .fold(w => throw w.resolveException, identity)
1662+ Defaults .makeScalaInstance(
1663+ scalaVersion.value,
1664+ Array .empty,
1665+ comp.toSeq,
1666+ Seq .empty,
1667+ state.value,
1668+ scalaInstanceTopLoader.value,
1669+ )},
1670+ /* Add the sources of scalajs-ir.
1671+ * To guarantee that dotty can bootstrap without depending on a version
1672+ * of scalajs-ir built with a different Scala compiler, we add its
1673+ * sources instead of depending on the binaries.
1674+ */
1675+ ivyConfigurations += SourceDeps .hide,
1676+ transitiveClassifiers := Seq (" sources" ),
1677+ libraryDependencies +=
1678+ (" org.scala-js" %% " scalajs-ir" % scalaJSVersion % " sourcedeps" ).cross(CrossVersion .for3Use2_13),
1679+ Compile / sourceGenerators += Def .task {
1680+ val s = streams.value
1681+ val cacheDir = s.cacheDirectory
1682+ val trgDir = (Compile / sourceManaged).value / " scalajs-ir-src"
1683+
1684+ val report = updateClassifiers.value
1685+ val scalaJSIRSourcesJar = report.select(
1686+ configuration = configurationFilter(" sourcedeps" ),
1687+ module = (_ : ModuleID ).name.startsWith(" scalajs-ir_" ),
1688+ artifact = artifactFilter(`type` = " src" )).headOption.getOrElse {
1689+ sys.error(s " Could not fetch scalajs-ir sources " )
1690+ }
1691+
1692+ FileFunction .cached(cacheDir / s " fetchScalaJSIRSource " ,
1693+ FilesInfo .lastModified, FilesInfo .exists) { dependencies =>
1694+ s.log.info(s " Unpacking scalajs-ir sources to $trgDir... " )
1695+ if (trgDir.exists)
1696+ IO .delete(trgDir)
1697+ IO .createDirectory(trgDir)
1698+ IO .unzip(scalaJSIRSourcesJar, trgDir)
1699+
1700+ val sjsSources = (trgDir ** " *.scala" ).get.toSet
1701+ sjsSources.foreach(f => {
1702+ val lines = IO .readLines(f)
1703+ val linesWithPackage = replacePackage(lines) {
1704+ case " org.scalajs.ir" => " dotty.tools.sjs.ir"
1705+ }
1706+ IO .writeLines(f, insertUnsafeNullsImport(linesWithPackage))
1707+ })
1708+ sjsSources
1709+ } (Set (scalaJSIRSourcesJar)).toSeq
1710+ }.taskValue,
1711+ )
1712+
15911713 def dottyLibrary (implicit mode : Mode ): Project = mode match {
15921714 case NonBootstrapped => `scala3-library`
15931715 case Bootstrapped => `scala3-library-bootstrapped`
0 commit comments