Skip to content

Commit 0a77088

Browse files
committed
chore: add scala3-compiler-bootstrapped to the new build
1 parent 2f3878f commit 0a77088

File tree

3 files changed

+149
-1
lines changed

3 files changed

+149
-1
lines changed

.github/workflows/stdlib.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,20 @@ jobs:
148148
- uses: sbt/setup-sbt@v1
149149
- name: Compile `tasty-core-bootstrapped`
150150
run: ./project/scripts/sbt tasty-core-bootstrapped-new/compile
151+
152+
scala3-compiler-bootstrapped:
153+
runs-on: ubuntu-latest
154+
##needs: [tasty-core-bootstrapped, scala3-library-bootstrapped] Add when we add support for caching here
155+
steps:
156+
- name: Git Checkout
157+
uses: actions/checkout@v4
158+
159+
- name: Set up JDK 17
160+
uses: actions/setup-java@v4
161+
with:
162+
distribution: 'temurin'
163+
java-version: 17
164+
cache: 'sbt'
165+
- uses: sbt/setup-sbt@v1
166+
- name: Compile `scala3-compiler-bootstrapped`
167+
run: ./project/scripts/sbt scala3-compiler-bootstrapped-new/compile

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ val `scala3-bootstrapped` = Build.`scala3-bootstrapped`
44
val `scala3-interfaces` = Build.`scala3-interfaces`
55
val `scala3-compiler` = Build.`scala3-compiler`
66
val `scala3-compiler-nonbootstrapped` = Build.`scala3-compiler-nonbootstrapped`
7+
val `scala3-compiler-bootstrapped-new` = Build.`scala3-compiler-bootstrapped-new`
78
val `scala3-compiler-bootstrapped` = Build.`scala3-compiler-bootstrapped`
89
val `scala-library-nonbootstrapped` = Build.`scala-library-nonbootstrapped`
910
val `scala3-library-nonbootstrapped` = Build.`scala3-library-nonbootstrapped`

project/Build.scala

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ object Build {
17221722
// ======================================= SCALA COMPILER =======================================
17231723
// ==============================================================================================
17241724

1725-
/* Configuration of the org.scala-lang:scala3-compiler_3:*.**.**-nonbootstrapped project */
1725+
/* Configuration of the org.scala-lang:scala3-compiler_3:*.**.**-nonbootstrapped project */
17261726
lazy val `scala3-compiler-nonbootstrapped` = project.in(file("compiler"))
17271727
.dependsOn(`scala3-interfaces`, `tasty-core-nonbootstrapped`, `scala3-library-nonbootstrapped`)
17281728
.settings(
@@ -1843,6 +1843,136 @@ object Build {
18431843
}.taskValue,
18441844
)
18451845

1846+
/* Configuration of the org.scala-lang:scala3-compiler_3:*.**.**-bootstrapped project */
1847+
lazy val `scala3-compiler-bootstrapped-new` = project.in(file("compiler"))
1848+
.dependsOn(`scala3-interfaces`, `tasty-core-bootstrapped`, `scala3-library-bootstrapped`)
1849+
.settings(
1850+
name := "scala3-compiler-bootstrapped",
1851+
moduleName := "scala3-compiler",
1852+
version := dottyVersion,
1853+
versionScheme := Some("semver-spec"),
1854+
scalaVersion := dottyNonBootstrappedVersion, // nonbootstrapped artifacts are compiled with the reference compiler (already officially published)
1855+
crossPaths := true, // org.scala-lang:scala3-compiler has a crosspath
1856+
// sbt shouldn't add stdlib automatically, we depend on `scala3-library-nonbootstrapped`
1857+
autoScalaLibrary := false,
1858+
// Add the source directories for the stdlib (non-boostrapped)
1859+
Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"),
1860+
Compile / unmanagedSourceDirectories += baseDirectory.value / "src-bootstrapped",
1861+
// All the dependencies needed by the compiler
1862+
libraryDependencies ++= Seq(
1863+
"org.scala-lang.modules" % "scala-asm" % "9.8.0-scala-1",
1864+
Dependencies.compilerInterface,
1865+
"org.jline" % "jline-reader" % "3.29.0",
1866+
"org.jline" % "jline-terminal" % "3.29.0",
1867+
"org.jline" % "jline-terminal-jni" % "3.29.0",
1868+
//("io.get-coursier" %% "coursier" % "2.0.16" % Test).cross(CrossVersion.for3Use2_13),
1869+
),
1870+
// NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1871+
Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"),
1872+
// TODO: Enable these flags when the new stdlib is explicitelly null checked
1873+
//Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-Wsafe-init"),
1874+
// Make sure that the produced artifacts have the minimum JVM version in the bytecode
1875+
Compile / javacOptions ++= Seq("--target", Versions.minimumJVMVersion),
1876+
Compile / scalacOptions ++= Seq("--java-output-version", Versions.minimumJVMVersion),
1877+
// Packaging configuration of the stdlib
1878+
Compile / packageBin / publishArtifact := true,
1879+
Compile / packageDoc / publishArtifact := false,
1880+
Compile / packageSrc / publishArtifact := true,
1881+
// Only publish compilation artifacts, no test artifacts
1882+
Test / publishArtifact := false,
1883+
// Do not allow to publish this project for now
1884+
publish / skip := false,
1885+
// Project specific target folder. sbt doesn't like having two projects using the same target folder
1886+
target := target.value / "scala3-compiler-bootstrapped",
1887+
// Generate compiler.properties, used by sbt
1888+
Compile / resourceGenerators += Def.task {
1889+
import java.util._
1890+
import java.text._
1891+
val file = (Compile / resourceManaged).value / "compiler.properties"
1892+
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
1893+
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
1894+
val contents = //2.11.11.v20170413-090219-8a413ba7cc
1895+
s"""version.number=${version.value}
1896+
|maven.version.number=${version.value}
1897+
|git.hash=${VersionUtil.gitHash}
1898+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
1899+
""".stripMargin
1900+
1901+
if (!(file.exists && IO.read(file) == contents)) {
1902+
IO.write(file, contents)
1903+
}
1904+
1905+
Seq(file)
1906+
}.taskValue,
1907+
// Configure to use the non-bootstrapped compiler
1908+
scalaInstance := {
1909+
val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet
1910+
1911+
// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
1912+
// just directories containing classfiles because sbt maintains a cache of
1913+
// compiler instances. This cache is invalidated based on timestamps
1914+
// however this is only implemented on jars, directories are never
1915+
// invalidated.
1916+
val tastyCore = (`tasty-core-nonbootstrapped` / Compile / packageBin).value
1917+
val scalaLibrary = (`scala-library-nonbootstrapped` / Compile / packageBin).value
1918+
val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value
1919+
val scala3Compiler = (`scala3-compiler-nonbootstrapped` / Compile / packageBin).value
1920+
1921+
Defaults.makeScalaInstance(
1922+
dottyNonBootstrappedVersion,
1923+
libraryJars = Array(scalaLibrary),
1924+
allCompilerJars = Seq(tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps,
1925+
allDocJars = Seq.empty,
1926+
state.value,
1927+
scalaInstanceTopLoader.value
1928+
)
1929+
},
1930+
scalaCompilerBridgeBinaryJar := {
1931+
Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value)
1932+
},
1933+
/* Add the sources of scalajs-ir.
1934+
* To guarantee that dotty can bootstrap without depending on a version
1935+
* of scalajs-ir built with a different Scala compiler, we add its
1936+
* sources instead of depending on the binaries.
1937+
*/
1938+
ivyConfigurations += SourceDeps.hide,
1939+
transitiveClassifiers := Seq("sources"),
1940+
libraryDependencies +=
1941+
("org.scala-js" %% "scalajs-ir" % scalaJSVersion % "sourcedeps").cross(CrossVersion.for3Use2_13),
1942+
Compile / sourceGenerators += Def.task {
1943+
val s = streams.value
1944+
val cacheDir = s.cacheDirectory
1945+
val trgDir = (Compile / sourceManaged).value / "scalajs-ir-src"
1946+
1947+
val report = updateClassifiers.value
1948+
val scalaJSIRSourcesJar = report.select(
1949+
configuration = configurationFilter("sourcedeps"),
1950+
module = (_: ModuleID).name.startsWith("scalajs-ir_"),
1951+
artifact = artifactFilter(`type` = "src")).headOption.getOrElse {
1952+
sys.error(s"Could not fetch scalajs-ir sources")
1953+
}
1954+
1955+
FileFunction.cached(cacheDir / s"fetchScalaJSIRSource",
1956+
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
1957+
s.log.info(s"Unpacking scalajs-ir sources to $trgDir...")
1958+
if (trgDir.exists)
1959+
IO.delete(trgDir)
1960+
IO.createDirectory(trgDir)
1961+
IO.unzip(scalaJSIRSourcesJar, trgDir)
1962+
1963+
val sjsSources = (trgDir ** "*.scala").get.toSet
1964+
sjsSources.foreach(f => {
1965+
val lines = IO.readLines(f)
1966+
val linesWithPackage = replacePackage(lines) {
1967+
case "org.scalajs.ir" => "dotty.tools.sjs.ir"
1968+
}
1969+
IO.writeLines(f, insertUnsafeNullsImport(linesWithPackage))
1970+
})
1971+
sjsSources
1972+
} (Set(scalaJSIRSourcesJar)).toSeq
1973+
}.taskValue,
1974+
)
1975+
18461976
def dottyLibrary(implicit mode: Mode): Project = mode match {
18471977
case NonBootstrapped => `scala3-library`
18481978
case Bootstrapped => `scala3-library-bootstrapped`

0 commit comments

Comments
 (0)