@@ -40,6 +40,9 @@ import sbttastymima.TastyMiMaPlugin.autoImport._
40
40
41
41
import scala .util .Properties .isJavaAtLeast
42
42
43
+ import scala .xml .{Node => XmlNode , NodeSeq => XmlNodeSeq , _ }
44
+ import scala .xml .transform .{RewriteRule , RuleTransformer }
45
+
43
46
import org .portablescala .sbtplatformdeps .PlatformDepsPlugin .autoImport ._
44
47
45
48
object Build {
@@ -1451,7 +1454,7 @@ object Build {
1451
1454
lazy val `scala3-bootstrapped-new` = project
1452
1455
.aggregate(`scala3-interfaces`, `scala3-library-bootstrapped-new` , `scala-library-bootstrapped`,
1453
1456
`tasty-core-bootstrapped-new`, `scala3-compiler-bootstrapped-new`, `scala3-sbt-bridge-bootstrapped`,
1454
- `scala3-staging-new`, `scala3-tasty-inspector-new`)
1457
+ `scala3-staging-new`, `scala3-tasty-inspector-new`, `scala-library-sjs`, `scala3-library-sjs` )
1455
1458
.settings(
1456
1459
name := " scala3-bootstrapped" ,
1457
1460
moduleName := " scala3-bootstrapped" ,
@@ -1833,6 +1836,153 @@ object Build {
1833
1836
target := target.value / " scala3-library-bootstrapped" ,
1834
1837
)
1835
1838
1839
+ /* Configuration of the org.scala-js:scalajs-scalalib_2.13:*.**.**-bootstrapped project */
1840
+ lazy val `scala-library-sjs` = project.in(file(" library-js" ))
1841
+ // We add a dependency to the JVM library to have the classfile available
1842
+ // (as they are not part of this artifact)
1843
+ .dependsOn(`scala3-library-bootstrapped-new`)
1844
+ .settings(
1845
+ name := " scala-library-sjs" ,
1846
+ organization := " org.scala-js" ,
1847
+ // This is very tricky here since this is a Scala 3 project, but to be able to smoothly
1848
+ // migrate the ecosystem, we need to be able to evict the Scala 2 library from the classpath.
1849
+ // The problem is that the Scala 2 library for Scala.js has a _2.13 in the module's name, so we need
1850
+ // to release Scala 3 for Scala.js with the same _2.13 instead of the _3.
1851
+ // Yes, I know, this is weird and feels wrong.
1852
+ moduleName := " scalajs-scalalib_2.13" ,
1853
+ version := dottyVersion,
1854
+ versionScheme := Some (" semver-spec" ),
1855
+ crossPaths := false ,
1856
+ // sbt defaults to scala 2.12.x and metals will report issues as it doesn't consider the project a scala 3 project
1857
+ // (not the actual version we use to compile the project)
1858
+ scalaVersion := referenceVersion,
1859
+ // Add the source directories for the stdlib (non-boostrapped)
1860
+ Compile / unmanagedSourceDirectories := Seq (baseDirectory.value / " src" ),
1861
+ Compile / unmanagedSourceDirectories ++=
1862
+ (`scala-library-bootstrapped` / Compile / unmanagedSourceDirectories).value,
1863
+ // NOTE: The only difference here is that we drop `-Werror` and semanticDB for now
1864
+ Compile / scalacOptions := Seq (" -deprecation" , " -feature" , " -unchecked" , " -encoding" , " UTF8" , " -language:implicitConversions" , " -nowarn" ),
1865
+ Compile / scalacOptions += " -Yno-stdlib-patches" ,
1866
+ Compile / scalacOptions += " -scalajs" ,
1867
+ // Packaging configuration of the stdlib
1868
+ Compile / packageBin / publishArtifact := true ,
1869
+ Compile / packageDoc / publishArtifact := false ,
1870
+ Compile / packageSrc / publishArtifact := true ,
1871
+ // Only publish compilation artifacts, no test artifacts
1872
+ Test / publishArtifact := false ,
1873
+ // Do not allow to publish this project for now
1874
+ publish / skip := false ,
1875
+ // Take into account the source files from the `library` folder
1876
+ // but give the priority to the files in `library-js` that override files in `library`
1877
+ Compile / sources := {
1878
+ val files = (Compile / sources).value
1879
+ val overwrittenSources =
1880
+ (files ++ Seq (
1881
+ baseDirectory.value / " src" / " scala" / " runtime" / " BoxesRunTime.java" ,
1882
+ baseDirectory.value / " src" / " scala" / " math" / " ScalaNumber.java" ,
1883
+ ))
1884
+ .flatMap(_.relativeTo(baseDirectory.value / " src" )).toSet
1885
+
1886
+ files.filterNot(file =>
1887
+ file.relativeTo((`scala-library-bootstrapped` / baseDirectory).value / " src" )
1888
+ .exists(overwrittenSources.contains))
1889
+
1890
+ },
1891
+ // Drop all the tasty files and the classfiles when packaging bu the scalajs exclusive classes
1892
+ // More info here: https://github.com/scala-js/scala-js/issues/5217
1893
+ Compile / packageBin / mappings := {
1894
+ (Compile / packageBin / mappings).value.filter(file =>
1895
+ file._2.endsWith(" .sjsir" )
1896
+ || file._2.endsWith(" UnitOps.tasty" ) || file._2.endsWith(" UnitOps.class" ) || file._2.endsWith(" UnitOps$.class" )
1897
+ || file._2.endsWith(" AnonFunctionXXL.tasty" ) || file._2.endsWith(" AnonFunctionXXL.class" ))
1898
+ },
1899
+ libraryDependencies += (" org.scala-js" %% " scalajs-library" % scalaJSVersion % Provided ).cross(CrossVersion .for3Use2_13),
1900
+ libraryDependencies += (" org.scala-js" % " scalajs-javalib" % scalaJSVersion),
1901
+ // Project specific target folder. sbt doesn't like having two projects using the same target folder
1902
+ target := target.value / " scala-library" ,
1903
+ // we need to have the `scala-library` artifact in the classpath for `ScalaLibraryPlugin` to work
1904
+ // this was the only way to not get the artifact evicted by sbt. Even a custom configuration didn't work
1905
+ // NOTE: true is the default value, just making things clearer here
1906
+ managedScalaInstance := true ,
1907
+ autoScalaLibrary := false ,
1908
+ // Configure the nonbootstrapped compiler
1909
+ scalaInstance := {
1910
+ val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet
1911
+
1912
+ // IMPORTANT: We need to use actual jars to form the ScalaInstance and not
1913
+ // just directories containing classfiles because sbt maintains a cache of
1914
+ // compiler instances. This cache is invalidated based on timestamps
1915
+ // however this is only implemented on jars, directories are never
1916
+ // invalidated.
1917
+ val tastyCore = (`tasty-core-nonbootstrapped` / Compile / packageBin).value
1918
+ val scalaLibrary = (`scala-library-nonbootstrapped` / Compile / packageBin).value
1919
+ val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value
1920
+ val scala3Compiler = (`scala3-compiler-nonbootstrapped` / Compile / packageBin).value
1921
+
1922
+ Defaults .makeScalaInstance(
1923
+ dottyNonBootstrappedVersion,
1924
+ libraryJars = Array (scalaLibrary),
1925
+ allCompilerJars = Seq (tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps,
1926
+ allDocJars = Seq .empty,
1927
+ state.value,
1928
+ scalaInstanceTopLoader.value
1929
+ )
1930
+ },
1931
+ scalaCompilerBridgeBinaryJar := {
1932
+ Some ((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value)
1933
+ },
1934
+ // See https://stackoverflow.com/a/51416386
1935
+ pomPostProcess := { (node : XmlNode ) =>
1936
+ new RuleTransformer (new RewriteRule {
1937
+ override def transform (node : XmlNode ): XmlNodeSeq = node match {
1938
+ case e : Elem if e.label == " dependency" && e.child.exists(child => child.label == " artifactId" && child.text == " scalajs-library_2.13" ) =>
1939
+ XmlNodeSeq .Empty
1940
+ case _ => node
1941
+ }
1942
+ }).transform(node).head
1943
+ },
1944
+ )
1945
+
1946
+ /* Configuration of the org.scala-lang:scala3-library_sjs1_3:*.**.**-bootstrapped project */
1947
+ lazy val `scala3-library-sjs` = project.in(file(" library-js" ))
1948
+ .dependsOn(`scala-library-sjs`)
1949
+ .settings(
1950
+ name := " scala3-library-sjs" ,
1951
+ moduleName := " scala3-library_sjs1" ,
1952
+ version := dottyVersion,
1953
+ versionScheme := Some (" semver-spec" ),
1954
+ // sbt defaults to scala 2.12.x and metals will report issues as it doesn't consider the project a scala 3 project
1955
+ // (not the actual version we use to compile the project)
1956
+ scalaVersion := referenceVersion,
1957
+ crossPaths := true , // org.scala-lang:scala3-library_sjs1 has a crosspath
1958
+ // Do not depend on the `org.scala-lang:scala3-library` automatically, we manually depend on `scala-library-bootstrapped`
1959
+ autoScalaLibrary := false ,
1960
+ // Drop all the scala tools in this project, so we can never generate any bytecode, or documentation
1961
+ managedScalaInstance := false ,
1962
+ // This Project only has a dependency to `org.scala-js:scalajs-scalalib:*.**.**-bootstrapped`
1963
+ Compile / sources := Seq (),
1964
+ Compile / resources := Seq (),
1965
+ Test / sources := Seq (),
1966
+ Test / resources := Seq (),
1967
+ // Bridge the common task to call the ones of the actual library project
1968
+ Compile / compile := (`scala-library-sjs` / Compile / compile).value,
1969
+ Compile / doc := (`scala-library-sjs` / Compile / doc).value,
1970
+ Compile / run := (`scala-library-sjs` / Compile / run).evaluated,
1971
+ Test / compile := (`scala-library-sjs` / Test / compile).value,
1972
+ Test / doc := (`scala-library-sjs` / Test / doc).value,
1973
+ Test / run := (`scala-library-sjs` / Test / run).evaluated,
1974
+ // Packaging configuration of the stdlib
1975
+ Compile / packageBin / publishArtifact := true ,
1976
+ Compile / packageDoc / publishArtifact := false ,
1977
+ Compile / packageSrc / publishArtifact := true ,
1978
+ // Only publish compilation artifacts, no test artifacts
1979
+ Test / publishArtifact := false ,
1980
+ // Do not allow to publish this project for now
1981
+ publish / skip := false ,
1982
+ // Project specific target folder. sbt doesn't like having two projects using the same target folder
1983
+ target := target.value / " scala3-library" ,
1984
+ )
1985
+
1836
1986
// ==============================================================================================
1837
1987
// ===================================== TASTY CORE LIBRARY =====================================
1838
1988
// ==============================================================================================
0 commit comments