Skip to content
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

Add support for Scala Native 0.4.0 and cross-publish native for 2.11/2.12/2.13 #298

Merged
merged 1 commit into from
Jan 22, 2021
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
8 changes: 6 additions & 2 deletions bin/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ coursier resolve \
org.scalameta:munit_3.0.0-M2:$version \
org.scalameta:munit_3.0.0-M3:$version \
org.scalameta:munit_0.27:$version \
org.scalameta:munit_native0.4.0-M2_2.11:$version \
org.scalameta:munit_native0.4.0_2.11:$version \
org.scalameta:munit_native0.4.0_2.12:$version \
org.scalameta:munit_native0.4.0_2.13:$version \
org.scalameta:munit_sjs1_2.11:$version \
org.scalameta:munit_sjs1_2.12:$version \
org.scalameta:munit_sjs1_2.13:$version \
Expand All @@ -22,7 +24,9 @@ coursier resolve \
org.scalameta:munit-scalacheck_0.27:$version \
org.scalameta:munit-scalacheck_3.0.0-M2:$version \
org.scalameta:munit-scalacheck_3.0.0-M3:$version \
org.scalameta:munit-scalacheck_native0.4.0-M2_2.11:$version \
org.scalameta:munit-scalacheck_native0.4.0_2.11:$version \
org.scalameta:munit-scalacheck_native0.4.0_2.12:$version \
org.scalameta:munit-scalacheck_native0.4.0_2.13:$version \
org.scalameta:munit-scalacheck_sjs1_2.11:$version \
org.scalameta:munit-scalacheck_sjs1_2.12:$version \
org.scalameta:munit-scalacheck_sjs1_2.13:$version \
Expand Down
24 changes: 10 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossPlugin.autoImport.CrossType
import scala.collection.mutable
val scalaJSVersion = "1.4.0"
val scalaNativeVersion = "0.4.0-M2"
val scalaNativeVersion = "0.4.0"
def previousVersion = "0.7.0"
def scala213 = "2.13.4"
def scala212 = "2.12.13"
Expand Down Expand Up @@ -66,12 +66,6 @@ val isScala3Setting = Def.setting {
}

def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 != 2)
val isScalaJS = Def.setting[Boolean](
SettingKey[Boolean]("scalaJSUseMainModuleInitializer").?.value.isDefined
)
val isScalaNative = Def.setting[Boolean](
SettingKey[String]("nativeGC").?.value.isDefined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nativeGC is now a TaskKey so we can't depend on it to produce a Setting.

Since this was only used to set the unmanagedSourceDirectories below, I've moved the relevant setting down to nativeSettings and jsSettings so we don't need isScalaNative and isScalaJS anymore

)

// NOTE(olafur): disable Scala.js and Native settings for IntelliJ.
lazy val skipIdeaSettings = SettingKey[Boolean]("ide-skip-project") := true
Expand Down Expand Up @@ -116,8 +110,7 @@ val sharedJSConfigure: Project => Project =
_.disablePlugins(MimaPlugin)
val sharedNativeSettings: List[Def.Setting[_]] = List(
skipIdeaSettings,
scalaVersion := scala211,
crossScalaVersions := List(scala211)
crossScalaVersions := scala2Versions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

)
val sharedNativeConfigure: Project => Project =
_.disablePlugins(ScalafixPlugin, MimaPlugin)
Expand Down Expand Up @@ -174,9 +167,6 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
val base = root / "shared" / "src" / "main"
val result = mutable.ListBuffer.empty[File]
val partialVersion = CrossVersion.partialVersion(scalaVersion.value)
if (isScalaJS.value || isScalaNative.value) {
result += root / "non-jvm" / "src" / "main"
}
if (isPreScala213(partialVersion)) {
result += base / "scala-pre-2.13"
}
Expand All @@ -203,7 +193,10 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
sharedNativeSettings,
libraryDependencies ++= List(
"org.scala-native" %%% "test-interface" % scalaNativeVersion
)
),
unmanagedSourceDirectories.in(Compile) += baseDirectory
.in(ThisBuild)
.value / "munit" / "non-jvm" / "src" / "main"
)
.jsConfigure(sharedJSConfigure)
.jsSettings(
Expand All @@ -213,7 +206,10 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.withDottyCompat(scalaVersion.value),
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion)
.withDottyCompat(scalaVersion.value)
)
),
unmanagedSourceDirectories.in(Compile) += baseDirectory
.in(ThisBuild)
.value / "munit" / "non-jvm" / "src" / "main"
)
.jvmSettings(
sharedJVMSettings,
Expand Down
19 changes: 10 additions & 9 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ object test extends Tests {

### Scala.js setup

Additionally, if you are using Scala.js you will need to export your tests as CommonJS modules:
Additionally, if you are using Scala.js you will need to export your tests as
CommonJS modules:

**sbt:**

Expand All @@ -58,18 +59,18 @@ Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
```scala
object test extends Tests {
...

override def moduleKind = T(mill.scalajslib.api.ModuleKind.CommonJSModule)
}
```

| Scala Version | JVM | Scala.js (0.6.x) | Scala.js (1.x) | Native (0.4.x) |
| ------------------------- | :-: | :--------------: | :------------: | :------------: |
| 2.11.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ |
| 2.12.x | ✅ | ✅ until 0.7.16 | ✅ | n/a |
| 2.13.x | ✅ | ✅ until 0.7.16 | ✅ | n/a |
| @SCALA3_PREVIOUS_VERSION@ | ✅ | n/a | ✅ | n/a |
| @SCALA3_STABLE_VERSION@ | ✅ | n/a | ✅ | n/a |
| Scala Version | JVM | Scala.js (0.6.x) | Scala.js (1.x) | Native (0.4.x) |
| ------------------------- | :-: | :--------------: | :------------: | :------------: |
| 2.11.x | ✅ | ✅ until 0.7.16 | ✅ | ✅ |
| 2.12.x | ✅ | ✅ until 0.7.16 | ✅ | |
| 2.13.x | ✅ | ✅ until 0.7.16 | ✅ | |
| @SCALA3_PREVIOUS_VERSION@ | ✅ | n/a | ✅ | n/a |
| @SCALA3_STABLE_VERSION@ | ✅ | n/a | ✅ | n/a |

Next, write a test suite.

Expand Down
17 changes: 9 additions & 8 deletions munit/native/src/main/scala/munit/internal/PlatformCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package munit.internal
import sbt.testing.TaskDef
import munit.MUnitRunner
import scala.concurrent.Future
import scala.scalanative.testinterface.PreloadedClassLoader
import scala.scalanative.reflect.Reflect
import sbt.testing.Task
import sbt.testing.EventHandler
import sbt.testing.Logger
Expand Down Expand Up @@ -33,13 +33,14 @@ object PlatformCompat {
taskDef: TaskDef,
classLoader: ClassLoader
): Option[MUnitRunner] = {
scala.util.Try {
val suite = classLoader
.asInstanceOf[PreloadedClassLoader]
.loadPreloaded(taskDef.fullyQualifiedName)
.asInstanceOf[munit.Suite]
new MUnitRunner(suite.getClass, () => suite)
}.toOption
Reflect
.lookupInstantiatableClass(taskDef.fullyQualifiedName())
.map(cls =>
new MUnitRunner(
cls.runtimeClass.asInstanceOf[Class[_ <: munit.Suite]],
() => cls.newInstance().asInstanceOf[munit.Suite]
)
)
}
private var myClassLoader: ClassLoader = _
def setThisClassLoader(loader: ClassLoader): Unit = myClassLoader = loader
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.25")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.4.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")

Expand Down