Skip to content

Commit

Permalink
Introduce sbt-scala-native-crossproject (#89)
Browse files Browse the repository at this point in the history
* Introduce sbt-scala-native-crossproject

This PR introduces sbt-scala-native-crossproject with identical functionality to sbt-scalajs-crossproject. It's a blocker for 0.3.7 release as it doesn't depend on old sbt-crossproject any longer, and requires platforms-deps based cross projects instead.

* Bump to sbt 0.13.17
  • Loading branch information
densh authored Mar 29, 2018
1 parent b2cb6f8 commit 9860679
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ before_script:
script:
- java -version
- scripts/scalafmt --test && sbt sbt-crossproject-test/scripted
- sbt "++ 2.12.3" "^^ 1.0.0" sbt-crossproject/publishLocal sbt-scalajs-crossproject/publishLocal
- sbt "++ 2.12.3" "^^ 1.0.0" sbt-crossproject/publishLocal sbt-scalajs-crossproject/publishLocal sbt-scala-native-crossproject/publishLocal

cache:
directories:
Expand Down
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ Cross-platform compilation support for sbt.
In `project/plugins.sbt`:

```scala
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21")
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.1") // (1)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.3.1") // (2)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.6") // (3)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.4.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.22")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7")
```

In `build.sbt`:

```scala
// (5) shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
// shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
import sbtcrossproject.{crossProject, CrossType}

val sharedSettings = Seq(scalaVersion := "2.11.12")

lazy val bar =
// (6) select supported platforms
// select supported platforms
crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
.settings(sharedSettings)
.jsSettings(/* ... */) // defined in sbt-scalajs-crossproject
.jvmSettings(/* ... */)
// (7) configure Scala-Native settings
// configure Scala-Native settings
.nativeSettings(/* ... */) // defined in sbt-scala-native

lazy val barJS = bar.js
Expand Down Expand Up @@ -90,8 +90,8 @@ Note that *inside the build*, you still need to use `barJVM` to the JVM `Project
In `project/plugins.sbt`:

```scala
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.1") // (1)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.6") // (2)
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.4.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7")
```

In `build.sbt`:
Expand All @@ -100,12 +100,12 @@ In `build.sbt`:
val sharedSettings = Seq(scalaVersion := "2.11.12")

lazy val bar =
// (4) select supported platforms
// select supported platforms
crossProject(JVMPlatform, NativePlatform)
.settings(sharedSettings)
// (5) configure JVM settings
// configure JVM settings
.jvmSettings(/* ... */)
// (6) configure Scala-Native settings
// configure Scala-Native settings
.nativeSettings(/* ... */) // defined in sbt-scala-native

lazy val barJVM = bar.jvm
Expand All @@ -119,19 +119,18 @@ We carefully implemented sbt-crossproject to be mostly source compatible with Sc
In `project/plugins.sbt`:

```scala
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21")
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.1") // (1)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.3.1") // (2)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.22")
```

In `build.sbt`:

```scala
// (5) shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
// shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
import sbtcrossproject.{crossProject, CrossType}

lazy val bar =
// (4) select supported platforms
// select supported platforms
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
.settings(/* ... */)
Expand All @@ -146,11 +145,10 @@ lazy val barJVM = bar.jvm

```
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import scala.scalanative.sbtplugin.ScalaNativePlugin.autoImport._
import sbtcrossproject.{crossProject, CrossType}
import sbtcrossproject.CrossPlugin.autoImport._
import scalajscrossproject.ScalaJSCrossPlugin.autoImport.{toScalaJSGroupID => _, _}
import scalajscrossproject.ScalaJSCrossPlugin.autoImport.JSPlatform
import sbtcrossproject.{crossProject, CrossType}
import scalanativecrossproject.ScalaNativeCrossPlugin.autoImport._
```

<h2>Configuration</h2>
Expand Down
20 changes: 18 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ lazy val `sbt-crossproject-root` =
project
.in(file("."))
.aggregate(`sbt-scalajs-crossproject`,
`sbt-scala-native-crossproject`,
`sbt-crossproject`,
`sbt-crossproject-test`)
.dependsOn(`sbt-scalajs-crossproject`,
`sbt-scala-native-crossproject`,
`sbt-crossproject`,
`sbt-crossproject-test`)
.settings(noPublishSettings)
Expand All @@ -31,7 +33,20 @@ lazy val `sbt-scalajs-crossproject` =
moduleName := "sbt-scalajs-crossproject",
addSbtPluginWorkaround(
"org.portable-scala" % "sbt-platform-deps" % "1.0.0-M2"),
addSbtPluginWorkaround("org.scala-js" % "sbt-scalajs" % "0.6.19")
addSbtPluginWorkaround("org.scala-js" % "sbt-scalajs" % "0.6.22")
)
.settings(publishSettings)
.dependsOn(`sbt-crossproject`)

lazy val `sbt-scala-native-crossproject` =
project
.in(file("sbt-scala-native-crossproject"))
.settings(sbtPluginSettings)
.settings(
moduleName := "sbt-scala-native-crossproject",
addSbtPluginWorkaround(
"org.portable-scala" % "sbt-platform-deps" % "1.0.0-M2"),
addSbtPluginWorkaround("org.scala-native" % "sbt-scala-native" % "0.3.7")
)
.settings(publishSettings)
.dependsOn(`sbt-crossproject`)
Expand All @@ -57,7 +72,8 @@ lazy val `sbt-crossproject-test` =
scripted := scripted
.dependsOn(
publishLocal in `sbt-crossproject`,
publishLocal in `sbt-scalajs-crossproject`
publishLocal in `sbt-scalajs-crossproject`,
publishLocal in `sbt-scala-native-crossproject`
)
.evaluated
)
Expand Down
4 changes: 2 additions & 2 deletions project/Extra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ object Extra {
sbtPlugin := true,
scriptedLaunchOpts ++= Seq(
"-Dplugin.version=" + version.value,
"-Dplugin.sn-version=0.3.3",
"-Dplugin.sjs-version=0.6.19"
"-Dplugin.sn-version=0.3.7",
"-Dplugin.sjs-version=0.6.22"
),
scalacOptions ++= Seq(
"-deprecation",
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.16
sbt.version=0.13.17
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
val snVersion = sys.props.get("plugin.sn-version").get
val pluginVersion = sys.props.get("plugin.version").get
val snVersion = sys.props.get("plugin.sn-version").get

addSbtPlugin("org.scala-native" % "sbt-scala-native" % snVersion)
addSbtPlugin(
"org.portable-scala" % "sbt-scala-native-crossproject" % pluginVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % snVersion)

scalacOptions ++= Seq(
"-deprecation",
Expand Down
9 changes: 5 additions & 4 deletions sbt-crossproject-test/src/sbt-test/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// COPIED FROM sbt-crossproject-test/src/sbt-test/plugins.sbt
val pluginVersion = sys.props.get("plugin.version").get
val snVersion = sys.props.get("plugin.sn-version").get
val sjsVersion = sys.props.get("plugin.sjs-version").get
val snVersion = sys.props.get("plugin.sn-version").get

addSbtPlugin("org.scala-js" % "sbt-scalajs" % sjsVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % pluginVersion)
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % pluginVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % snVersion)
addSbtPlugin(
"org.portable-scala" % "sbt-scala-native-crossproject" % pluginVersion)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sjsVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % snVersion)

scalacOptions ++= Seq(
"-deprecation",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scalanativecrossproject

import sbt._
import sbtcrossproject._
import scalanative.sbtplugin._

case object NativePlatform extends Platform {
def identifier: String = "native"
def sbtSuffix: String = "Native"
def enable(project: Project): Project =
project.enablePlugins(ScalaNativePlugin)

@deprecated("Will be removed", "0.3.0")
val crossBinary: CrossVersion = ScalaNativeCrossVersion.binary

@deprecated("Will be removed", "0.3.0")
val crossFull: CrossVersion = ScalaNativeCrossVersion.full
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package scalanativecrossproject

import sbt._
import sbtcrossproject._
import scalanative.sbtplugin._

import scala.language.implicitConversions

trait ScalaNativeCross {
val NativePlatform = scalanativecrossproject.NativePlatform

implicit def NativeCrossProjectBuilderOps(
builder: CrossProject.Builder): NativeCrossProjectOps =
new NativeCrossProjectOps(builder.crossType(CrossType.Full))

implicit class NativeCrossProjectOps(project: CrossProject) {
def native: Project = project.projects(NativePlatform)

def nativeSettings(ss: Def.SettingsDefinition*): CrossProject =
nativeConfigure(_.settings(ss: _*))

def nativeConfigure(transformer: Project => Project): CrossProject =
project.configurePlatform(NativePlatform)(transformer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scalanativecrossproject

object ScalaNativeCrossPlugin extends sbt.AutoPlugin {
object autoImport extends ScalaNativeCross
}

0 comments on commit 9860679

Please sign in to comment.