Skip to content

Commit 473cce6

Browse files
committed
chore: add the build for org.scala-js:scalajs-scalalib
1 parent 55ab8d0 commit 473cce6

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

.github/workflows/stdlib.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ jobs:
219219
- name: Compile `scala3-tasty-inspector`
220220
run: ./project/scripts/sbt scala3-tasty-inspector-new/compile
221221

222+
scala-library-sjs:
223+
runs-on: ubuntu-latest
224+
## Add when we add support for caching here
225+
##needs: [scala3-library-nonbootstrapped,
226+
## tasty-core-nonbootstrapped,
227+
##  scala3-compiler-nonbootstrapped,
228+
##  scala3-sbt-bridge-nonbootstrapped]
229+
steps:
230+
- name: Git Checkout
231+
uses: actions/checkout@v5
232+
233+
- name: Set up JDK 17
234+
uses: actions/setup-java@v4
235+
with:
236+
distribution: 'temurin'
237+
java-version: 17
238+
cache: 'sbt'
239+
- uses: sbt/setup-sbt@v1
240+
- name: Compile `scala3-staging`
241+
run: ./project/scripts/sbt scala3-staging-new/compile
242+
- name: Compile `scala-library` for Scala.js
243+
run: ./project/scripts/sbt scala-library-sjs/compile
244+
222245
#################################################################################################
223246
########################################### TEST JOBS ###########################################
224247
#################################################################################################

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ val `scala3-compiler` = Build.`scala3-compiler`
77
val `scala3-compiler-nonbootstrapped` = Build.`scala3-compiler-nonbootstrapped`
88
val `scala3-compiler-bootstrapped-new` = Build.`scala3-compiler-bootstrapped-new`
99
val `scala3-compiler-bootstrapped` = Build.`scala3-compiler-bootstrapped`
10+
val `scala-library-sjs` = Build.`scala-library-sjs`
1011
val `scala-library-nonbootstrapped` = Build.`scala-library-nonbootstrapped`
1112
val `scala3-library-nonbootstrapped` = Build.`scala3-library-nonbootstrapped`
1213
val `scala-library-bootstrapped` = Build.`scala-library-bootstrapped`

project/Build.scala

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ object Build {
14511451
lazy val `scala3-bootstrapped-new` = project
14521452
.aggregate(`scala3-interfaces`, `scala3-library-bootstrapped-new` , `scala-library-bootstrapped`,
14531453
`tasty-core-bootstrapped-new`, `scala3-compiler-bootstrapped-new`, `scala3-sbt-bridge-bootstrapped`,
1454-
`scala3-staging-new`, `scala3-tasty-inspector-new`)
1454+
`scala3-staging-new`, `scala3-tasty-inspector-new`, `scala-library-sjs`)
14551455
.settings(
14561456
name := "scala3-bootstrapped",
14571457
moduleName := "scala3-bootstrapped",
@@ -1833,6 +1833,94 @@ object Build {
18331833
target := target.value / "scala3-library-bootstrapped",
18341834
)
18351835

1836+
/* Configuration of the org.scala-js:scalajs-scalalib_2.13:*.**.**-bootstrapped project */
1837+
lazy val `scala-library-sjs` = project.in(file("library-js"))
1838+
// We add a dependency to the JVM library to have the classfile available
1839+
// (as they are not part of this artifact)
1840+
.dependsOn(`scala3-library-bootstrapped-new`)
1841+
.settings(
1842+
name := "scala-library-sjs",
1843+
organization := "org.scala-js",
1844+
// This is very tricky here since this is a Scala 3 project, but to be able to smoothly
1845+
// migrate the ecosystem, we need to be able to evict the Scala 2 library from the classpath.
1846+
// The problem is that the Scala 2 library for Scala.js has a _2.13 in the module's name, so we need
1847+
// to release Scala 3 for Scala.js with the same _2.13 instead of the _3.
1848+
// Yes, I know, this is weird and feels wrong.
1849+
moduleName := "scalajs-scalalib_2.13",
1850+
version := dottyVersion,
1851+
versionScheme := Some("semver-spec"),
1852+
crossPaths := false,
1853+
// sbt defaults to scala 2.12.x and metals will report issues as it doesn't consider the project a scala 3 project
1854+
// (not the actual version we use to compile the project)
1855+
scalaVersion := referenceVersion,
1856+
// Add the source directories for the stdlib (non-boostrapped)
1857+
Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"),
1858+
Compile / unmanagedSourceDirectories ++=
1859+
(`scala-library-bootstrapped` / Compile / unmanagedSourceDirectories).value,
1860+
// NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1861+
Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions", "-nowarn"),
1862+
Compile / scalacOptions += "-Yno-stdlib-patches",
1863+
Compile / scalacOptions += "-scalajs",
1864+
// Packaging configuration of the stdlib
1865+
Compile / packageBin / publishArtifact := true,
1866+
Compile / packageDoc / publishArtifact := false,
1867+
Compile / packageSrc / publishArtifact := true,
1868+
// Only publish compilation artifacts, no test artifacts
1869+
Test / publishArtifact := false,
1870+
// Do not allow to publish this project for now
1871+
publish / skip := false,
1872+
// Take into account the source files from the `library` folder
1873+
// but give the priority to the files in `library-js` that override files in `library`
1874+
Compile / sources := {
1875+
val files = (Compile / sources).value
1876+
val overwrittenSources =
1877+
(files ++ Seq(
1878+
baseDirectory.value / "src" / "scala" / "runtime" / "BoxesRunTime.java",
1879+
baseDirectory.value / "src" / "scala" / "math" / "ScalaNumber.java",
1880+
))
1881+
.flatMap(_.relativeTo(baseDirectory.value / "src")).toSet
1882+
1883+
files.filterNot(file =>
1884+
file.relativeTo((`scala-library-bootstrapped` / baseDirectory).value / "src")
1885+
.exists(overwrittenSources.contains))
1886+
1887+
},
1888+
libraryDependencies += ("org.scala-js" %% "scalajs-library" % scalaJSVersion).cross(CrossVersion.for3Use2_13),
1889+
libraryDependencies += ("org.scala-js" % "scalajs-javalib" % scalaJSVersion),
1890+
// Project specific target folder. sbt doesn't like having two projects using the same target folder
1891+
target := target.value / "scala-library",
1892+
// we need to have the `scala-library` artifact in the classpath for `ScalaLibraryPlugin` to work
1893+
// this was the only way to not get the artifact evicted by sbt. Even a custom configuration didn't work
1894+
// NOTE: true is the default value, just making things clearer here
1895+
managedScalaInstance := true,
1896+
// Configure the nonbootstrapped compiler
1897+
scalaInstance := {
1898+
val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet
1899+
1900+
// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
1901+
// just directories containing classfiles because sbt maintains a cache of
1902+
// compiler instances. This cache is invalidated based on timestamps
1903+
// however this is only implemented on jars, directories are never
1904+
// invalidated.
1905+
val tastyCore = (`tasty-core-nonbootstrapped` / Compile / packageBin).value
1906+
val scalaLibrary = (`scala-library-nonbootstrapped` / Compile / packageBin).value
1907+
val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value
1908+
val scala3Compiler = (`scala3-compiler-nonbootstrapped` / Compile / packageBin).value
1909+
1910+
Defaults.makeScalaInstance(
1911+
dottyNonBootstrappedVersion,
1912+
libraryJars = Array(scalaLibrary),
1913+
allCompilerJars = Seq(tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps,
1914+
allDocJars = Seq.empty,
1915+
state.value,
1916+
scalaInstanceTopLoader.value
1917+
)
1918+
},
1919+
scalaCompilerBridgeBinaryJar := {
1920+
Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value)
1921+
},
1922+
)
1923+
18361924
// ==============================================================================================
18371925
// ===================================== TASTY CORE LIBRARY =====================================
18381926
// ==============================================================================================

0 commit comments

Comments
 (0)