8000 Split the scalalib .sjsir files in a separate artifact scalajs-scalalib. by sjrd · Pull Request #4913 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Split the scalalib .sjsir files in a separate artifact scalajs-scalalib. #4913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ val sbtPlugin = Build.plugin
val javalibintf = Build.javalibintf
val javalibInternal = Build.javalibInternal
val javalib = Build.javalib
val scalalib = Build.scalalib
val scalalibInternal = Build.scalalibInternal
val libraryAux = Build.libraryAux
val scalalib = Build.scalalib
val library = Build.library
val testInterface = Build.testInterface
val testBridge = Build.testBridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap
import scala.util.matching.Regex

object ScalaJSVersions extends VersionChecks(
current = "1.14.1-SNAPSHOT",
current = "1.15.0-SNAPSHOT",
binaryEmitted = "1.13"
)

Expand Down
114 changes: 79 additions & 35 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ object MyScalaJSPlugin extends AutoPlugin {
*/
libraryDependencies ~= { libDeps =>
val blacklist =
Set("scalajs-compiler", "scalajs-library", "scalajs-test-bridge")
Set("scalajs-compiler", "scalajs-library", "scalajs-scalalib", "scalajs-test-bridge")
libDeps.filterNot(dep => blacklist.contains(dep.name))
},

Expand Down Expand Up @@ -638,7 +638,7 @@ object Build {
* - `"semver-spec"` for artifacts whose public API can only break in major releases (e.g., `library`)
*
* At the moment, we only set the version scheme for artifacts in the
* "library ecosystem", i.e., scalajs-javalib scalajs-library,
* "library ecosystem", i.e., scalajs-javalib, scalajs-scalalib, scalajs-library,
* scalajs-test-interface, scalajs-junit-runtime and scalajs-test-bridge.
* Artifacts of the "tools ecosystem" do not have a version scheme set, as
* the jury is still out on what is the best way to specify them.
Expand Down Expand Up @@ -749,17 +749,17 @@ object Build {
}
}

/** Depends on library and, by artificial transitivity, on the javalib. */
/** Depends on library and, by artificial transitivity, on the javalib and scalalib. */
def dependsOnLibrary2_12: Project = {
val library = LocalProject("library2_12")

// Add a real dependency on the library
val project1 = project
.dependsOn(library)

/* Because the javalib's exportsJar is false, but its actual products are
* only in its jar, we must manually add the jar on the internal
* classpath.
/* Because the javalib's and scalalib's exportsJar is false, but their
* actual products are only in their jar, we must manually add the jars
* on the internal classpath.
* Once published, only jars are ever used, so this is fine.
*/
if (isGeneratingForIDE) {
Expand All @@ -772,6 +772,12 @@ object Build {
Test / internalDependencyClasspath +=
(javalib / Compile / packageBin).value,
)
.settings(
Compile / internalDependencyClasspath +=
(scalalib.v2_12 / Compile / packageBin).value,
Test / internalDependencyClasspath +=
(scalalib.v2_12 / Compile / packageBin).value,
)
}
}

Expand Down Expand Up @@ -818,28 +824,36 @@ object Build {
}
}

/** Depends on library and, by transitivity, on the javalib. */
/** Depends on library and, by artificial transitivity, on the javalib and scalalib. */
def dependsOnLibrary: MultiScalaProject = {
// Add a real dependency on the library
val project1 = project
.dependsOn(library)

/* Because the javalib's exportsJar is false, but its actual products are
* only in its jar, we must manually add the jar on the internal
* classpath.
/* Because the javalib's and scalalib's exportsJar is false, but their
* actual products are only in their jar, we must manually add the jars
* on the internal classpath.
* Once published, only jars are ever used, so this is fine.
*/
if (isGeneratingForIDE) {
project1
} else {
// Actually add classpath dependencies on the javalib jar
// Actually add classpath dependencies on the javalib and scalalib jars
project1
.settings(
Compile / internalDependencyClasspath +=
(javalib / Compile / packageBin).value,
Test / internalDependencyClasspath +=
(javalib / Compile / packageBin).value,
)
.zippedSettings(scalalib) { scalalib =>
Def.settings(
Compile / internalDependencyClasspath +=
(scalalib / Compile / packageBin).value,
Test / internalDependencyClasspath +=
(scalalib / Compile / packageBin).value,
)
}
}
}

Expand Down Expand Up @@ -919,7 +933,7 @@ object Build {
linkerInterface, linkerInterfaceJS, linker, linkerJS,
testAdapter,
javalibintf,
javalibInternal, javalib, scalalib, libraryAux, library,
javalibInternal, javalib, scalalibInternal, libraryAux, scalalib, library,
testInterface, jUnitRuntime, testBridge, jUnitPlugin, jUnitAsyncJS,
jUnitAsyncJVM, jUnitTestOutputsJS, jUnitTestOutputsJVM,
helloworld, reversi, testingExample, testSuite, testSuiteJVM,
Expand Down Expand Up @@ -1358,12 +1372,14 @@ object Build {
// JS libs
publishLocal in javalib,

publishLocal in scalalib.v2_12,
publishLocal in library.v2_12,
publishLocal in testInterface.v2_12,
publishLocal in testBridge.v2_12,
publishLocal in jUnitRuntime.v2_12,
publishLocal in irProjectJS.v2_12,

publishLocal in scalalib.v2_13,
publishLocal in library.v2_13,
publishLocal in testInterface.v2_13,
publishLocal in testBridge.v2_13,
Expand Down Expand Up @@ -1478,7 +1494,7 @@ object Build {
* copied from `javalibInternal`.
*
* This the "public" version of the javalib, as depended on by the `library`
* and published on Maven.
* and `scalalib`, and published on Maven.
*/
lazy val javalib: Project = Project(
id = "javalib", base = file("javalib-public")
Expand Down Expand Up @@ -1506,8 +1522,13 @@ object Build {
},
)

lazy val scalalib: MultiScalaProject = MultiScalaProject(
id = "scalalib", base = file("scalalib")
/** The project that actually compiles the `scalalib`, but which is not
* exposed.
*
* Instead, its products are copied in `scalalib`.
*/
lazy val scalalibInternal: MultiScalaProject = MultiScalaProject(
id = "scalalibInternal", base = file("scalalib")
).enablePlugins(
MyScalaJSPlugin
).settings(
Expand All @@ -1523,7 +1544,7 @@ object Build {
s"https://raw.githubusercontent.com/scala/scala/v${scalaVersion.value}/src/library/")
option ++ prev
},
name := "Scala library for Scala.js",
name := "scalajs-scalalib-internal",
publishArtifact in Compile := false,
NoIDEExport.noIDEExportSettings,
delambdafySetting,
Expand Down Expand Up @@ -1669,12 +1690,54 @@ object Build {
recompileAllOrNothingSettings,
).withScalaJSCompiler.dependsOnLibraryNoJar

/** An empty project, without source nor dependencies (other than the javalib),
* whose products are copied from `scalalibInternal` and `libraryAux`.
*
* This the "public" version of the scalalib, as depended on by the `library`
* and published on Maven.
*/
lazy val scalalib: MultiScalaProject = MultiScalaProject(
id = "scalalib", base = file("scalalib-public")
).dependsOn(
javalib,
).settings(
commonSettings,
name := "scalajs-scalalib",
publishSettings(Some(VersionScheme.BreakOnMajor)),

/* The scalalib has a special version number that encodes both the Scala
* version and the Scala.js version. This allows us to back-publish for
* newer versions of Scala and older versions of Scala.js. The Scala
* version comes first so that Ivy resolution will choose 2.13.20+1.15.0
* over 2.13.18+1.16.0. The former might not be as optimized as the
* latter, but at least it will contain all the binary API that might be
* required.
*/
version := scalaVersion.value + "+" + scalaJSVersion,

exportJars := false, // very important, otherwise there's a cycle with the `library`
).zippedSettings(Seq("scalalibInternal", "libraryAux"))(localProjects =>
inConfig(Compile)(Seq(
// Use the .sjsir files from scalalibInternal and libraryAux (but not the .class files)
Compile / packageBin / mappings := {
val scalalibInternalMappings = (localProjects(0) / packageBin / mappings).value
val libraryAuxMappings = (localProjects(1) / packageBin / mappings).value
val allMappings = scalalibInternalMappings ++ libraryAuxMappings
allMappings.filter(_._2.endsWith(".sjsir"))
},
))
)

lazy val library: MultiScalaProject = MultiScalaProject(
id = "library", base = file("library")
).enablePlugins(
MyScalaJSPlugin
).dependsOn(
// Project dependencies
javalibintf % Provided, javalib,
).dependsOn(
// MultiScalaProject dependencies
scalalib,
).settings(
commonSettings,
publishSettings(Some(VersionScheme.BreakOnMajor)),
Expand Down Expand Up @@ -1727,25 +1790,6 @@ object Build {
*/
dependencyClasspath in doc ++= exportedProducts.value,
))
).zippedSettings(Seq("scalalib", "libraryAux"))(localProjects =>
inConfig(Compile)(Seq(
/* Add the .sjsir files from other lib projects
* (but not .class files)
*/
mappings in packageBin := {
val libraryMappings = (mappings in packageBin).value

val filter = ("*.sjsir": NameFilter)

val otherProducts = (
(products in localProjects(0)).value ++
(products in localProjects(1)).value)
val otherMappings =
otherProducts.flatMap(base => Path.selectSubpaths(base, filter))

libraryMappings ++ otherMappings
},
))
).withScalaJSCompiler

// The Scala.js version of sbt-testing-interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ private[sbtplugin] object ScalaJSPluginInternal {
scalaOrg %% "scala3-library_sjs1" % scalaV,
/* scala3-library_sjs1 depends on some version of scalajs-library_2.13,
* but we bump it to be at least scalaJSVersion.
* (It will also depend on some version of scalajs-scalalib_2.13,
* but we do not have to worry about that here.)
*/
"org.scala-js" % "scalajs-library_2.13" % scalaJSVersion,
"org.scala-js" % "scalajs-test-bridge_2.13" % scalaJSVersion % "test"
Expand All @@ -803,6 +805,12 @@ private[sbtplugin] object ScalaJSPluginInternal {
prev ++ Seq(
compilerPlugin("org.scala-js" % "scalajs-compiler" % scalaJSVersion cross CrossVersion.full),
"org.scala-js" %% "scalajs-library" % scalaJSVersion,
/* scalajs-library depends on some version of scalajs-scalalib,
* but we want to make sure to bump it to be at least the one
* of our own `scalaVersion` (which would have back-published in
* the meantime).
*/
"org.scala-js" %% "scalajs-scalalib" % s"$scalaV+$scalaJSVersion",
"org.scala-js" %% "scalajs-test-bridge" % scalaJSVersion % "test"
)
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi
SUFFIXES="2_12 2_13"

JAVA_LIBS="javalibintf javalib"
COMPILER="compiler jUnitPlugin"
FULL_SCALA_LIBS="compiler jUnitPlugin scalalib"
JS_LIBS="library irJS linkerInterfaceJS linkerJS testInterface testBridge jUnitRuntime"
JVM_LIBS="ir linkerInterface linker testAdapter"
SCALA_LIBS="$JS_LIBS $JVM_LIBS"
Expand All @@ -22,10 +22,10 @@ for p in $JAVA_LIBS; do
done
$CMD $ARGS

# Publish compiler
# Publish artifacts built with the full Scala version
for s in $SUFFIXES; do
ARGS=""
for p in $COMPILER; do
for p in $FULL_SCALA_LIBS; do
ARGS="$ARGS +$p$s/publishSigned"
done
$CMD $ARGS
Expand Down
0