Skip to content

Commit eff9f2b

Browse files
authored
Merge pull request #239 from ekrich/topic/native
Add support for Scala Native
2 parents f03c313 + 486374a commit eff9f2b

File tree

9 files changed

+88
-54
lines changed

9 files changed

+88
-54
lines changed

.travis.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,28 @@ matrix:
2828

2929
# run migration test
3030
- scala: 2.12.8
31-
env: TEST_SCALAFIX=true ADOPTOPENJDK=11
31+
env: TEST_SCALAFIX=true ADOPTOPENJDK=11
3232

3333
# run binary compatibility test
3434
- scala: 2.12.8
35-
env: TEST_BINARY_COMPAT=true ADOPTOPENJDK=11
35+
env: TEST_BINARY_COMPAT=true ADOPTOPENJDK=11
3636

3737
# run scalafmt
3838
- scala: 2.12.8
39-
env: TEST_SCALAFMT=true ADOPTOPENJDK=11
39+
env: TEST_SCALAFMT=true ADOPTOPENJDK=11
40+
41+
# Scala Native includes
42+
- scala: 2.11.12
43+
env: SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=8
44+
45+
- scala: 2.11.12
46+
env: SCALANATIVE_VERSION=0.4.0-M2 ADOPTOPENJDK=8
47+
48+
- scala: 2.11.12
49+
env: SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=11
50+
51+
- scala: 2.11.12
52+
env: SCALANATIVE_VERSION=0.4.0-M2 ADOPTOPENJDK=11
4053

4154
before_install:
4255
# adding $HOME/.sdkman to cache would create an empty directory, which interferes with the initial installation

build.sbt

+24-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ lazy val root = project
2424
.aggregate(
2525
compat211JVM,
2626
compat211JS,
27+
compat211Native,
2728
compat212JVM,
2829
compat212JS,
2930
compat213JVM,
@@ -60,17 +61,17 @@ scalaVersionsByJvm in ThisBuild := {
6061
}
6162

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

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

73-
lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
74+
lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform)(
7475
"compat",
7576
_.settings(scalaModuleSettings)
7677
.settings(commonSettings)
@@ -90,7 +91,8 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
9091
if (scalaVersion.value.startsWith("2.13."))
9192
Seq(s"scala.collection.compat.*;version=${version.value}")
9293
else
93-
Seq(s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}")
94+
Seq(
95+
s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}")
9496
},
9597
OsgiKeys.importPackage := Seq(osgiImport("*", scalaBinaryVersion.value)),
9698
OsgiKeys.privatePackage := Nil,
@@ -109,18 +111,25 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
109111
)
110112
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
111113
.disablePlugins(ScalafixPlugin)
114+
.nativeSettings(
115+
crossScalaVersions := List(scala211),
116+
scalaVersion := scala211, // allows to compile if scalaVersion set not 2.11
117+
nativeLinkStubs := true,
118+
Test / test := {}
119+
)
112120
)
113121

114122
val compat211 = compat(scala211)
115123
val compat212 = compat(scala212)
116124
val compat213 = compat(scala213)
117125

118-
lazy val compat211JVM = compat211.jvm
119-
lazy val compat211JS = compat211.js
120-
lazy val compat212JVM = compat212.jvm
121-
lazy val compat212JS = compat212.js
122-
lazy val compat213JVM = compat213.jvm
123-
lazy val compat213JS = compat213.js
126+
lazy val compat211JVM = compat211.jvm
127+
lazy val compat211JS = compat211.js
128+
lazy val compat211Native = compat211.native
129+
lazy val compat212JVM = compat212.jvm
130+
lazy val compat212JS = compat212.js
131+
lazy val compat213JVM = compat213.jvm
132+
lazy val compat213JS = compat213.js
124133

125134
lazy val `binary-compat-old` = project
126135
.in(file("binary-compat/old"))
@@ -285,6 +294,7 @@ val preRelease = "preRelease"
285294
val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.parse)
286295
val releaseVersion = sys.env.get("TRAVIS_TAG").flatMap(Version.parse)
287296
val isScalaJs = sys.env.get("SCALAJS_VERSION").map(_.nonEmpty).getOrElse(false)
297+
val isScalaNative = sys.env.get("SCALANATIVE_VERSION").map(_.nonEmpty).getOrElse(false)
288298
val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty
289299
val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty
290300
val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty
@@ -342,13 +352,14 @@ inThisBuild(
342352
"TRAVIS_SCALA_VERSION",
343353
"TRAVIS_TAG",
344354
"SCALAJS_VERSION",
355+
"SCALANATIVE_VERSION",
345356
"TEST_SCALAFIX",
346357
"TEST_SCALAFMT",
347358
"TEST_BINARY_COMPAT"
348359
).foreach(k =>
349360
println(k.padTo(20, " ").mkString("") + " -> " + sys.env.get(k).getOrElse("None")))
350361

351-
val platformSuffix = if (isScalaJs) "JS" else ""
362+
val platformSuffix = if (isScalaJs) "JS" else if (isScalaNative) "Native" else ""
352363

353364
val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix
354365
val binaryCompatProject = "binary-compat"
@@ -387,7 +398,7 @@ inThisBuild(
387398
Seq(
388399
setPublishVersion,
389400
List(s"$projectPrefix/clean"),
390-
List(s"$testProjectPrefix/test"),
401+
if (isScalaNative) List() else List(s"$testProjectPrefix/test"),
391402
List(s"$projectPrefix/publishLocal"),
392403
publishTask
393404
).flatten

compat/src/main/scala-2.11_2.12/scala/collection/compat/BuildFrom.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait BuildFrom[-From, -A, +C] extends Any {
2626
def fromSpecific(from: From)(it: IterableOnce[A]): C
2727

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

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

4646
// Implicit conversion derived from an implicit conversion to CanBuildFrom

compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ private[compat] trait PackageShared {
163163
type IterableOnce[+X] = c.TraversableOnce[X]
164164
val IterableOnce = c.TraversableOnce
165165

166-
implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] =
166+
implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
167+
self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] =
167168
new MapViewExtensionMethods[K, V, C](self)
168169
}
169170

@@ -242,7 +243,10 @@ class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends
242243
def iterableFactory: GenericCompanion[Traversable] = self.companion
243244
}
244245

245-
class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](private val self: IterableView[(K, V), C]) extends AnyVal {
246-
def mapValues[W, That](f: V => W)(implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That =
246+
class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
247+
private val self: IterableView[(K, V), C])
248+
extends AnyVal {
249+
def mapValues[W, That](f: V => W)(
250+
implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That =
247251
self.map[(K, W), That] { case (k, v) => (k, f(v)) }
248252
}

compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ object ArraySeq {
256256
return false
257257

258258
val len = xs.length
259-
var i = 0
259+
var i = 0
260260
while (i < len) {
261261
if (xs(i) != ys(i))
262262
return false

compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,73 @@ class CollectionConvertersTest {
1515
val it = "a b c".split(" ").iterator
1616

1717
{
18-
val j = it.asJava
18+
val j = it.asJava
1919
val je = it.asJavaEnumeration
20-
val s = (j: ju.Iterator[String]).asScala
20+
val s = (j: ju.Iterator[String]).asScala
2121
assert((s: Iterator[String]) eq it)
2222
val es = (je: ju.Enumeration[String]).asScala
2323
assert((es: Iterator[String]) eq it)
2424
}
2525

2626
{
2727
val i: c.Iterable[String] = it.to(Iterable)
28-
val j = i.asJava
29-
val jc = i.asJavaCollection
30-
val s = (j: jl.Iterable[String]).asScala
28+
val j = i.asJava
29+
val jc = i.asJavaCollection
30+
val s = (j: jl.Iterable[String]).asScala
3131
assert((s: c.Iterable[String]) eq i)
3232
val cs = (jc: ju.Collection[String]).asScala
3333
assert((cs: c.Iterable[String]) eq i)
3434
}
3535

3636
{
3737
val b: m.Buffer[String] = it.to(m.Buffer)
38-
val j = b.asJava
39-
val s = (j: ju.List[String]).asScala
38+
val j = b.asJava
39+
val s = (j: ju.List[String]).asScala
4040
assert((s: m.Buffer[String]) eq b)
4141
}
4242

4343
{
4444
val q: m.Seq[String] = it.to(m.Seq)
45-
val j = q.asJava
46-
val s = (j: ju.List[String]).asScala
45+
val j = q.asJava
46+
val s = (j: ju.List[String]).asScala
4747
assert((s: m.Buffer[String]) == q) // not eq
4848
}
4949

5050
{
5151
val q: c.Seq[String] = it.to(c.Seq)
52-
val j = q.asJava
53-
val s = (j: ju.List[String]).asScala
52+
val j = q.asJava
53+
val s = (j: ju.List[String]).asScala
5454
assert((s: m.Buffer[String]) == q) // not eq
5555
}
5656

5757
{
5858
val t: m.Set[String] = it.to(m.Set)
59-
val j = t.asJava
60-
val s = (j: ju.Set[String]).asScala
59+
val j = t.asJava
60+
val s = (j: ju.Set[String]).asScala
6161
assert((s: m.Set[String]) eq t)
6262
}
6363

6464
{
6565
val t: c.Set[String] = it.to(c.Set)
66-
val j = t.asJava
67-
val s = (j: ju.Set[String]).asScala
66+
val j = t.asJava
67+
val s = (j: ju.Set[String]).asScala
6868
assert((s: m.Set[String]) == t) // not eq
6969
}
7070

7171
{
7272
val p: m.Map[String, String] = m.Map(it.map(a => (a, a)).toSeq: _*)
73-
val j = p.asJava
74-
val jd = p.asJavaDictionary
75-
val s = (j: ju.Map[String, String]).asScala
73+
val j = p.asJava
74+
val jd = p.asJavaDictionary
75+
val s = (j: ju.Map[String, String]).asScala
7676
assert((s: m.Map[String, String]) eq p)
7777
val ds = (jd: ju.Dictionary[String, String]).asScala
7878
assert((ds: m.Map[String, String]) eq p)
7979
}
8080

8181
{
8282
val p: c.Map[String, String] = c.Map(it.map(a => (a, a)).toSeq: _*)
83-
val j = p.asJava
84-
val s = (j: ju.Map[String, String]).asScala
83+
val j = p.asJava
84+
val s = (j: ju.Map[String, String]).asScala
8585
assert((s: m.Map[String, String]) == p) // not eq
8686
}
8787

compat/src/test/scala/test/scala/collection/BuildFromTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ class BuildFromTest {
162162
// Implement BuildFrom
163163
class MyBuildFrom[From, A, C] extends BuildFrom[From, A, C] {
164164
def fromSpecific(from: From)(it: IterableOnce[A]): C = ???
165-
def newBuilder(from: From): Builder[A, C] = ???
165+
def newBuilder(from: From): Builder[A, C] = ???
166166
}
167167
}

compat/src/test/scala/test/scala/collection/ViewTest.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class ViewTest {
2121

2222
@Test
2323
def mapValues: Unit = {
24-
val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
25-
val oldStyle = m.mapValues(x => x*x)
26-
val newStyle = m.view.mapValues(x => x*x)
24+
val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
25+
val oldStyle = m.mapValues(x => x * x)
26+
val newStyle = m.view.mapValues(x => x * x)
2727
assertEquals(oldStyle.toMap, newStyle.toMap)
2828
}
2929

project/plugins.sbt

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28")
1+
val crossVer = "0.6.1"
2+
val scalaJSVersion =
3+
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28")
4+
val scalaNativeVersion =
5+
Option(System.getenv("SCALANATIVE_VERSION")).filter(_.nonEmpty).getOrElse("0.3.9")
26

3-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
4-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
5-
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0")
6-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5")
7-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
8-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
9-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
7+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
8+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer)
9+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
10+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % crossVer)
11+
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0")
12+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5")
13+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
14+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
15+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")

0 commit comments

Comments
 (0)