Skip to content

Add support for Scala Native #239

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 7 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ env:
# SONA_PASS
- secure: "m0Fw/eH7RXJJoBTfqV6CMd7kaIN2pRPnQPNXJGb546UjqYAlYTkfjvVrWpsgpisRBptI1FEHn24yGbgAHjIes/4un/O62K66I0BffL8PbdeHeNcDjSrTesKEqage2mQfGOiqccVsmkgiKeXNYL8tPZRmPQQ3XZ97mS1SXWlqAJSMW6HfNnvqW14Gdb/snR6I8lQ2o5tRnLerWPnI96pp+xjZca2lD4XDvH2wLJXXLmYY61e23ZYzZMepxBxhGa7js3YTYzCWNrOfBLjFJ5nwRxbjR0WMuz5z5Gdy715WtguKS4Fffd/GJHycLROBU9LCAQDMTxMFvqzFqVFpfq0BuTmmkXFXj+a7dO+ABG0RfoDfoMjn7pHwyHNCZyMMuR1HCjMkbGFwC+Zme2UAYNivtcsuWWeMuypwjyqjfFfNns4FHJ0SXFtC/6+OJkAuUdbEJKReYWKWEsP5SnCH/8PLlc+uUl3tjQkFLc1sOAyx9cTWyBErwuJXhgTrjT9AWvO+fvhcm8z/p5+aaF/U9GIrzPqziX4hGjzc/WC+rsFJSiBDlFQl7br+m8WWs7/wuXqPGXmhf0BNQViDi7fZndDHcY3p3T0An05d/IMKjCUrgLDlJi6VYs9XN7S8ay6MH+XTwIsJGSxtGjfEO4rHGIjtR2GRr8TqdNfnpsI3ucbia1Y="
matrix:
- SCALAJS_VERSION= ADOPTOPENJDK=8
- SCALAJS_VERSION=0.6.28 ADOPTOPENJDK=8
- SCALAJS_VERSION=1.0.0-M8 ADOPTOPENJDK=8
- SCALAJS_VERSION= ADOPTOPENJDK=11
- SCALAJS_VERSION=0.6.28 ADOPTOPENJDK=11
- SCALAJS_VERSION=1.0.0-M8 ADOPTOPENJDK=11
- SCALAJS_VERSION= ADOPTOPENJDK=8
- SCALAJS_VERSION=0.6.28 ADOPTOPENJDK=8
- SCALAJS_VERSION=1.0.0-M8 ADOPTOPENJDK=8
- SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=8
- SCALAJS_VERSION= ADOPTOPENJDK=11
- SCALAJS_VERSION=0.6.28 ADOPTOPENJDK=11
- SCALAJS_VERSION=1.0.0-M8 ADOPTOPENJDK=11
- SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=11

matrix:

Expand Down
37 changes: 24 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lazy val root = project
.aggregate(
compat211JVM,
compat211JS,
compat211Native,
compat212JVM,
compat212JS,
compat213JVM,
Expand Down Expand Up @@ -60,17 +61,17 @@ scalaVersionsByJvm in ThisBuild := {
}

/** Create an OSGi version range for standard Scala versioning
* schemes that describes binary compatible versions. */
* schemes that describes binary compatible versions. */
def osgiVersionRange(version: String, requireMicro: Boolean = false): String =
if(version contains '-') "${@}" // M, RC or SNAPSHOT -> exact version
else if(requireMicro) "${range;[===,=+)}" // At least the same micro version
if (version contains '-') "${@}" // M, RC or SNAPSHOT -> exact version
else if (requireMicro) "${range;[===,=+)}" // At least the same micro version
else "${range;[==,=+)}" // Any binary compatible version

/** Create an OSGi Import-Package version specification. */
def osgiImport(pattern: String, version: String, requireMicro: Boolean = false): String =
pattern + ";version=\"" + osgiVersionRange(version, requireMicro) + "\""

lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform)(
"compat",
_.settings(scalaModuleSettings)
.settings(commonSettings)
Expand All @@ -90,7 +91,8 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
if (scalaVersion.value.startsWith("2.13."))
Seq(s"scala.collection.compat.*;version=${version.value}")
else
Seq(s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}")
Seq(
s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}")
},
OsgiKeys.importPackage := Seq(osgiImport("*", scalaBinaryVersion.value)),
OsgiKeys.privatePackage := Nil,
Expand All @@ -109,18 +111,25 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.disablePlugins(ScalafixPlugin)
.nativeSettings(
crossScalaVersions := List(scala211),
scalaVersion := scala211, // allows to compile if scalaVersion set not 2.11
nativeLinkStubs := true,
Test / test := false
)
)

val compat211 = compat(scala211)
val compat212 = compat(scala212)
val compat213 = compat(scala213)

lazy val compat211JVM = compat211.jvm
lazy val compat211JS = compat211.js
lazy val compat212JVM = compat212.jvm
lazy val compat212JS = compat212.js
lazy val compat213JVM = compat213.jvm
lazy val compat213JS = compat213.js
lazy val compat211JVM = compat211.jvm
lazy val compat211JS = compat211.js
lazy val compat211Native = compat211.native
lazy val compat212JVM = compat212.jvm
lazy val compat212JS = compat212.js
lazy val compat213JVM = compat213.jvm
lazy val compat213JS = compat213.js

lazy val `binary-compat-old` = project
.in(file("binary-compat/old"))
Expand Down Expand Up @@ -285,6 +294,7 @@ val preRelease = "preRelease"
val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.parse)
val releaseVersion = sys.env.get("TRAVIS_TAG").flatMap(Version.parse)
val isScalaJs = sys.env.get("SCALAJS_VERSION").map(_.nonEmpty).getOrElse(false)
val isScalaNative = sys.env.get("SCALANATIVE_VERSION").map(_.nonEmpty).getOrElse(false)
val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty
val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty
val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty
Expand Down Expand Up @@ -342,13 +352,14 @@ inThisBuild(
"TRAVIS_SCALA_VERSION",
"TRAVIS_TAG",
"SCALAJS_VERSION",
"SCALANATIVE_VERSION",
"TEST_SCALAFIX",
"TEST_SCALAFMT",
"TEST_BINARY_COMPAT"
).foreach(k =>
println(k.padTo(20, " ").mkString("") + " -> " + sys.env.get(k).getOrElse("None")))

val platformSuffix = if (isScalaJs) "JS" else ""
val platformSuffix = if (isScalaJs) "JS" else if (isScalaNative) "Native" else ""

val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix
val binaryCompatProject = "binary-compat"
Expand Down Expand Up @@ -387,7 +398,7 @@ inThisBuild(
Seq(
setPublishVersion,
List(s"$projectPrefix/clean"),
List(s"$testProjectPrefix/test"),
if (isScalaNative) List() else List(s"$testProjectPrefix/test"),
List(s"$projectPrefix/publishLocal"),
publishTask
).flatten
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait BuildFrom[-From, -A, +C] extends Any {
def fromSpecific(from: From)(it: IterableOnce[A]): C

/** Get a Builder for the collection. For non-strict collection types this will use an intermediate buffer.
* Building collections with `fromSpecific` is preferred because it can be lazy for lazy collections. */
* Building collections with `fromSpecific` is preferred because it can be lazy for lazy collections. */
def newBuilder(from: From): mutable.Builder[A, C]

@deprecated("Use newBuilder() instead of apply()", "2.13.0")
Expand All @@ -40,7 +40,7 @@ object BuildFrom {
implicit cbf: CanBuildFrom[From, A, C]): BuildFrom[From, A, C] =
new BuildFrom[From, A, C] {
def fromSpecific(from: From)(it: IterableOnce[A]): C = (cbf(from) ++= it).result()
def newBuilder(from: From): mutable.Builder[A, C] = cbf(from)
def newBuilder(from: From): mutable.Builder[A, C] = cbf(from)
}

// Implicit conversion derived from an implicit conversion to CanBuildFrom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ private[compat] trait PackageShared {
type IterableOnce[+X] = c.TraversableOnce[X]
val IterableOnce = c.TraversableOnce

implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] =
implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] =
new MapViewExtensionMethods[K, V, C](self)
}

Expand Down Expand Up @@ -235,7 +236,10 @@ class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends
def iterableFactory: GenericCompanion[Traversable] = self.companion
}

class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](private val self: IterableView[(K, V), C]) extends AnyVal {
def mapValues[W, That](f: V => W)(implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That =
class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
private val self: IterableView[(K, V), C])
extends AnyVal {
def mapValues[W, That](f: V => W)(
implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That =
self.map[(K, W), That] { case (k, v) => (k, f(v)) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ object ArraySeq {
return false

val len = xs.length
var i = 0
var i = 0
while (i < len) {
if (xs(i) != ys(i))
return false
Expand Down
40 changes: 20 additions & 20 deletions compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,73 @@ class CollectionConvertersTest {
val it = "a b c".split(" ").iterator

{
val j = it.asJava
val j = it.asJava
val je = it.asJavaEnumeration
val s = (j: ju.Iterator[String]).asScala
val s = (j: ju.Iterator[String]).asScala
assert((s: Iterator[String]) eq it)
val es = (je: ju.Enumeration[String]).asScala
assert((es: Iterator[String]) eq it)
}

{
val i: c.Iterable[String] = it.to(Iterable)
val j = i.asJava
val jc = i.asJavaCollection
val s = (j: jl.Iterable[String]).asScala
val j = i.asJava
val jc = i.asJavaCollection
val s = (j: jl.Iterable[String]).asScala
assert((s: c.Iterable[String]) eq i)
val cs = (jc: ju.Collection[String]).asScala
assert((cs: c.Iterable[String]) eq i)
}

{
val b: m.Buffer[String] = it.to(m.Buffer)
val j = b.asJava
val s = (j: ju.List[String]).asScala
val j = b.asJava
val s = (j: ju.List[String]).asScala
assert((s: m.Buffer[String]) eq b)
}

{
val q: m.Seq[String] = it.to(m.Seq)
val j = q.asJava
val s = (j: ju.List[String]).asScala
val j = q.asJava
val s = (j: ju.List[String]).asScala
assert((s: m.Buffer[String]) == q) // not eq
}

{
val q: c.Seq[String] = it.to(c.Seq)
val j = q.asJava
val s = (j: ju.List[String]).asScala
val j = q.asJava
val s = (j: ju.List[String]).asScala
assert((s: m.Buffer[String]) == q) // not eq
}

{
val t: m.Set[String] = it.to(m.Set)
val j = t.asJava
val s = (j: ju.Set[String]).asScala
val j = t.asJava
val s = (j: ju.Set[String]).asScala
assert((s: m.Set[String]) eq t)
}

{
val t: c.Set[String] = it.to(c.Set)
val j = t.asJava
val s = (j: ju.Set[String]).asScala
val j = t.asJava
val s = (j: ju.Set[String]).asScala
assert((s: m.Set[String]) == t) // not eq
}

{
val p: m.Map[String, String] = m.Map(it.map(a => (a, a)).toSeq: _*)
val j = p.asJava
val jd = p.asJavaDictionary
val s = (j: ju.Map[String, String]).asScala
val j = p.asJava
val jd = p.asJavaDictionary
val s = (j: ju.Map[String, String]).asScala
assert((s: m.Map[String, String]) eq p)
val ds = (jd: ju.Dictionary[String, String]).asScala
assert((ds: m.Map[String, String]) eq p)
}

{
val p: c.Map[String, String] = c.Map(it.map(a => (a, a)).toSeq: _*)
val j = p.asJava
val s = (j: ju.Map[String, String]).asScala
val j = p.asJava
val s = (j: ju.Map[String, String]).asScala
assert((s: m.Map[String, String]) == p) // not eq
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ class BuildFromTest {
// Implement BuildFrom
class MyBuildFrom[From, A, C] extends BuildFrom[From, A, C] {
def fromSpecific(from: From)(it: IterableOnce[A]): C = ???
def newBuilder(from: From): Builder[A, C] = ???
def newBuilder(from: From): Builder[A, C] = ???
}
}
6 changes: 3 additions & 3 deletions compat/src/test/scala/test/scala/collection/ViewTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ViewTest {

@Test
def mapValues: Unit = {
val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
val oldStyle = m.mapValues(x => x*x)
val newStyle = m.view.mapValues(x => x*x)
val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
val oldStyle = m.mapValues(x => x * x)
val newStyle = m.view.mapValues(x => x * x)
assertEquals(oldStyle.toMap, newStyle.toMap)
}

Expand Down
23 changes: 15 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28")
val crossVer = "0.6.1"
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28")
val scalaNativeVersion =
Option(System.getenv("SCALANATIVE_VERSION")).filter(_.nonEmpty).getOrElse("0.3.9")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % crossVer)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")