Skip to content

Latest commit

 

History

History
116 lines (86 loc) · 3.64 KB

README.md

File metadata and controls

116 lines (86 loc) · 3.64 KB

sbt-cross

Build Status

Cross-platform compilation support for sbt.

Installation

Cross-Compiling Scala.js, JVM and Native

In project/plugins.sbt:

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")

resolvers += Resolver.sonatypeRepo("snapshots")                           // (1)
addSbtPlugin("org.scala-native" % "sbt-cross"         % "0.1.0-SNAPSHOT") // (2)
addSbtPlugin("org.scala-native" % "sbt-scalajs-cross" % "0.1.0-SNAPSHOT") // (3)
addSbtPlugin("org.scala-native" % "sbt-scala-native"  % "0.1.0-SNAPSHOT") // (4)

In build.sbt:

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

val sharedSettings = Seq(scalaVersion := "2.11.8") // Scala Native only supports 2.11

lazy val bar =
  // (6) select supported platforms
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
    .settings(sharedSettings)
    .jsSettings(/* ... */) // defined in sbt-scalajs-cross
    .jvmSettings(/* ... */)
    // (7) configure Scala-Native settings
    .nativeSettings(/* ... */) // defined in sbt-scala-native
    .nativeSettings(resolvers += Resolver.sonatypeRepo("snapshots")) // until we have a stable scala-native releases

lazy val barJS     = bar.js
lazy val barJVM    = bar.jvm
lazy val barNative = bar.native

lazy val foo =
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .settings(
      // %%% now include Scala Native. It applies to all selected platforms
      libraryDependencies += "org.example" %%% "foo" % "1.2.3"
    )

lazy val fooJS = foo.js
lazy val fooJVM = foo.jvm
lazy val fooNative = foo.native

Cross-Compiling JVM and Native

In project/plugins.sbt:

resolvers += Resolver.sonatypeRepo("snapshots")
addSbtPlugin("org.scala-native" % "sbt-cross" % "0.1.0-SNAPSHOT")        // (1)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.1.0-SNAPSHOT") // (2)

In build.sbt:

val sharedSettings = Seq(scalaVersion := "2.11.8") // Scala Native only supports 2.11

lazy val bar =
  // (4) select supported platforms
  crossProject(JVMPlatform, NativePlatform)
    .settings(sharedSettings)
    // (5) configure JVM settings
    .jvmSettings(/* ... */)
    // (6) configure Scala-Native settings
    .nativeSettings(/* ... */) // defined in sbt-scala-native
    .nativeSettings(resolvers += Resolver.sonatypeRepo("snapshots")) // until we have a stable scala-native releases

lazy val barJVM    = bar.jvm
lazy val barNative = bar.native

Migration from Scala.js' default crossProject

We carefully implemented sbt-cross to be mostly source compatible with Scala.js crossProject

In project/plugins.sbt:

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")

resolvers += Resolver.sonatypeRepo("snapshots")                           // (1)
addSbtPlugin("org.scala-native" % "sbt-cross"         % "0.1.0-SNAPSHOT") // (2)
addSbtPlugin("org.scala-native" % "sbt-scalajs-cross" % "0.1.0-SNAPSHOT") // (3)

In build.sbt:

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

lazy val bar =
  // (4) select supported platforms
  crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
    .settings(/* ... */)
    .jsSettings(/* ... */) // defined in sbt-scalajs-cross
    .jvmSettings(/* ... */)

lazy val barJS = bar.js
lazy val barJVM = bar.jvm