mirror of https://github.com/sbt/sbt.git
Add Scala Native support
This commit is contained in:
parent
ec80aff4c0
commit
11b9722183
10
.travis.yml
10
.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:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package a
|
||||
|
||||
class Core {
|
||||
}
|
||||
|
||||
object Core extends Core
|
||||
|
|
@ -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")
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue