From 11b97221831138bf3881a38a07ded03328c0f118 Mon Sep 17 00:00:00 2001 From: exoego Date: Sun, 12 May 2019 22:30:21 +0900 Subject: [PATCH] Add Scala Native support --- .travis.yml | 10 ++++-- README.markdown | 18 ++++++++++- src/main/scala/sbt/ProjectMatrix.scala | 31 ++++++++++++++++++- src/sbt-test/projectMatrix/native/build.sbt | 17 ++++++++++ .../native/core/src/main/scala/Core.scala | 6 ++++ .../projectMatrix/native/project/plugins.sbt | 6 ++++ src/sbt-test/projectMatrix/native/test | 5 +++ 7 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/sbt-test/projectMatrix/native/build.sbt create mode 100644 src/sbt-test/projectMatrix/native/core/src/main/scala/Core.scala create mode 100644 src/sbt-test/projectMatrix/native/project/plugins.sbt create mode 100644 src/sbt-test/projectMatrix/native/test diff --git a/.travis.yml b/.travis.yml index 475db2df4..d56744c46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,19 @@ -dist: trusty +dist: xenial group: stable language: scala -jdk: oraclejdk8 +jdk: openjdk11 before_script: - export JVM_OPTS="-Dfile.encoding=UTF-8 -Xmx1G -Xms1G -server -XX:ReservedCodeCacheSize=128M" - unset _JAVA_OPTIONS +addons: + apt: + packages: + - clang + - libunwind-dev + script: sbt scripted cache: diff --git a/README.markdown b/README.markdown index c21d25970..4e3158ecc 100644 --- a/README.markdown +++ b/README.markdown @@ -74,7 +74,7 @@ This is an example where `core` builds against Scala 2.11 and 2.12, but app only ### Scala.js support -Scala.js support was added in sbt-projectmatrix 0.2.0. +[Scala.js](http://scala-js.org/) support was added in sbt-projectmatrix 0.2.0. To use this, you need to setup sbt-scalajs as well: ```scala @@ -87,6 +87,22 @@ lazy val core = (projectMatrix in file("core")) This will create subprojects `coreJS2_11` and `coreJS2_12`. +### Scala Native support + +[Scala Native](http://scala-native.org) support will be added in upcoming release. +To use this, you need to setup sbt-scala-native` as well: + +```scala +lazy val core = (projectMatrix in file("core")) + .settings( + name := "core" + ) + .nativePlatform(scalaVersions = Seq("2.12.8", "2.11.12")) +``` + +This will create subprojects `coreJS2_11` and `coreJS2_12`. + + ### parallel cross-library building The rows can also be used for parallel cross-library building. diff --git a/src/main/scala/sbt/ProjectMatrix.scala b/src/main/scala/sbt/ProjectMatrix.scala index 6563457fe..3fb590c7e 100644 --- a/src/main/scala/sbt/ProjectMatrix.scala +++ b/src/main/scala/sbt/ProjectMatrix.scala @@ -69,6 +69,10 @@ sealed trait ProjectMatrix extends CompositeProject { def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix def js: ProjectFinder + def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix + def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix + def native: ProjectFinder + def crossLibrary(scalaVersions: Seq[String], suffix: String, settings: Seq[Setting[_]]): ProjectMatrix def crossLib(suffix: String): ProjectFinder @@ -93,6 +97,8 @@ object ProjectMatrix { val jvmDirectorySuffix: String = "-jvm" val jsIdSuffix: String = "JS" val jsDirectorySuffix: String = "-js" + val nativeIdSuffix: String = "NATIVE" + val nativeDirectorySuffix: String = "-native" /** A row in the project matrix, typically representing a platform. */ @@ -209,7 +215,7 @@ object ProjectMatrix { override def jsPlatform(scalaVersions: Seq[String]): ProjectMatrix = jsPlatform(scalaVersions, Nil) - + override def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = custom(jsIdSuffix, jsDirectorySuffix, scalaVersions, { _ @@ -228,6 +234,29 @@ object ProjectMatrix { } } + override def native: ProjectFinder = new SuffixBaseProjectFinder(nativeIdSuffix) + + override def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix = + nativePlatform(scalaVersions, Nil) + + override def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = + custom(nativeIdSuffix, nativeDirectorySuffix, scalaVersions, + { _ + .enablePlugins(nativePlugin(this.getClass.getClassLoader).getOrElse( + sys.error("""Scala Native plugin was not found. Add the sbt-scala-native plugin into project/plugins.sbt: + | addSbtPlugin("org.scala-native" % "sbt-scala-natiev" % "x.y.z") + |""".stripMargin) + )) + .settings(settings) + }) + + def nativePlugin(classLoader: ClassLoader): Try[AutoPlugin] = { + import sbtprojectmatrix.ReflectionUtil._ + withContextClassloader(classLoader) { loader => + getSingletonObject[AutoPlugin](loader, "scala.scalanative.sbtplugin.ScalaNativePlugin$") + } + } + override def js: ProjectFinder = new SuffixBaseProjectFinder(jsIdSuffix) override def crossLibrary(scalaVersions: Seq[String], suffix: String, settings: Seq[Setting[_]]): ProjectMatrix = diff --git a/src/sbt-test/projectMatrix/native/build.sbt b/src/sbt-test/projectMatrix/native/build.sbt new file mode 100644 index 000000000..83c4087ae --- /dev/null +++ b/src/sbt-test/projectMatrix/native/build.sbt @@ -0,0 +1,17 @@ +// lazy val root = (project in file(".")) +// .aggregate(core.projectRefs ++ app.projectRefs: _*) +// .settings( +// ) + +lazy val core = (projectMatrix in file("core")) + .settings( + name := "core" + ) + .nativePlatform(scalaVersions = Seq("2.11.12", "2.11.11")) + +lazy val app = (projectMatrix in file("app")) + .dependsOn(core) + .settings( + name := "app" + ) + .nativePlatform(scalaVersions = Seq("2.11.12")) diff --git a/src/sbt-test/projectMatrix/native/core/src/main/scala/Core.scala b/src/sbt-test/projectMatrix/native/core/src/main/scala/Core.scala new file mode 100644 index 000000000..274e01225 --- /dev/null +++ b/src/sbt-test/projectMatrix/native/core/src/main/scala/Core.scala @@ -0,0 +1,6 @@ +package a + +class Core { +} + +object Core extends Core diff --git a/src/sbt-test/projectMatrix/native/project/plugins.sbt b/src/sbt-test/projectMatrix/native/project/plugins.sbt new file mode 100644 index 000000000..2efd7a57d --- /dev/null +++ b/src/sbt-test/projectMatrix/native/project/plugins.sbt @@ -0,0 +1,6 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9") diff --git a/src/sbt-test/projectMatrix/native/test b/src/sbt-test/projectMatrix/native/test new file mode 100644 index 000000000..1bdaa1968 --- /dev/null +++ b/src/sbt-test/projectMatrix/native/test @@ -0,0 +1,5 @@ +> nativeLink + +$ exists app/target/native-2.12/app-out +$ exists core/target/native-2.12/core-out +$ exists core/target/native-2.11/core-out