Skip to content

Commit

Permalink
support scala-native
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Mar 3, 2017
1 parent 20ab170 commit 38f90ff
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 20 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ addons:
apt:
packages:
- oracle-java8-installer

matrix:
include:
- scala: 2.11.8
jdk: oraclejdk8
sudo: required
before_install:
- sudo apt-get -qq update
- sudo sh -c "echo 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.7 main' >> /etc/apt/sources.list"
- sudo sh -c "echo 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise main' >> /etc/apt/sources.list"
- wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
- sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
- sudo apt-get -qq update
- sudo apt-get install -y libgc-dev clang++-3.7 llvm-3.7 llvm-3.7-dev llvm-3.7-runtime llvm-3.7-tool libunwind7-dev
script:
- sbt ++$TRAVIS_SCALA_VERSION nativeTest/run nativeTest/publishLocal
33 changes: 30 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import build._
import com.typesafe.sbt.osgi.OsgiKeys
import org.scalajs.sbtplugin.cross._
import sbtunidoc.Plugin.UnidocKeys._
import sbtcrossproject.CrossPlugin.autoImport.crossProject

lazy val jsProjects = Seq[ProjectReference](
coreJS, effectJS, iterateeJS, scalacheckBindingJS, testsJS
Expand All @@ -11,19 +12,31 @@ lazy val jvmProjects = Seq[ProjectReference](
coreJVM, effectJVM, iterateeJVM, scalacheckBindingJVM, testsJVM, concurrent, example
)

lazy val nativeProjects = Seq[ProjectReference](
coreNative, effectNative, iterateeNative, nativeTest
)

lazy val scalaz = Project(
id = "scalaz",
base = file("."),
settings = standardSettings ++ unidocSettings ++ Seq[Sett](
artifacts := Classpaths.artifactDefs(Seq(packageDoc in Compile)).value,
packagedArtifacts := Classpaths.packaged(Seq(packageDoc in Compile)).value,
unidocProjectFilter in (ScalaUnidoc, unidoc) := {
jsProjects.foldLeft(inAnyProject)((acc, a) => acc -- inProjects(a))
(jsProjects ++ nativeProjects).foldLeft(inAnyProject)((acc, a) => acc -- inProjects(a))
}
) ++ Defaults.packageTaskSettings(packageDoc in Compile, (unidoc in Compile).map(_.flatMap(Path.allSubpaths))),
aggregate = jvmProjects ++ jsProjects
)

lazy val rootNative = Project(
rootNativeId,
file("rootNative")
).settings(
standardSettings,
notPublish
).aggregate(nativeProjects: _*)

lazy val rootJS = Project(
"rootJS",
file("rootJS")
Expand All @@ -42,6 +55,7 @@ lazy val rootJVM = Project(

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native

lazy val concurrent = Project(
id = "concurrent",
Expand All @@ -57,9 +71,11 @@ lazy val concurrent = Project(

lazy val effectJVM = effect.jvm
lazy val effectJS = effect.js
lazy val effectNative = effect.native

lazy val iterateeJVM = iteratee.jvm
lazy val iterateeJS = iteratee.js
lazy val iterateeNative = iteratee.native

lazy val example = Project(
id = "example",
Expand All @@ -72,7 +88,8 @@ lazy val example = Project(
)

lazy val scalacheckBinding =
CrossProject("scalacheck-binding", file("scalacheck-binding"), ScalazCrossType)
crossProject(JVMPlatform, JSPlatform).crossType(ScalazCrossType)
.in(file("scalacheck-binding"))
.settings(standardSettings)
.settings(
name := "scalaz-scalacheck-binding",
Expand All @@ -85,7 +102,7 @@ lazy val scalacheckBinding =
lazy val scalacheckBindingJVM = scalacheckBinding.jvm
lazy val scalacheckBindingJS = scalacheckBinding.js

lazy val tests = crossProject.crossType(ScalazCrossType)
lazy val tests = crossProject(JSPlatform, JVMPlatform).crossType(ScalazCrossType)
.settings(standardSettings)
.settings(
name := "scalaz-tests",
Expand All @@ -100,3 +117,13 @@ lazy val tests = crossProject.crossType(ScalazCrossType)

lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js

// can't use "sbt test"
// https://github.com/scala-native/scala-native/issues/339
lazy val nativeTest = Project(nativeTestId, file("nativeTest")).enablePlugins(ScalaNativePlugin)
.settings(
standardSettings,
nativeSettings,
notPublish
)
.dependsOn(iterateeNative)
4 changes: 4 additions & 0 deletions core/native/src/main/scala/scalaz/std/FutureInstances.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scalaz
package std

trait FutureInstances
4 changes: 4 additions & 0 deletions core/native/src/main/scala/scalaz/std/java/time.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scalaz
package std.java

trait TimeInstances
20 changes: 20 additions & 0 deletions nativeTest/src/main/scala/scalaz/TestMain.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package scalaz

import scalaz.Scalaz._
import scalaz.iteratee.Iteratee._
import scalaz.effect._
import scalaz.Id.Id

object TestMain {
def main(args: Array[String]): Unit = {
val list1 = List[Option[Int]](Some(1), Some(2), Some(3), Some(4))
val res1 = Traverse[List].sequence(list1)
println(res1)
assert(res1 == Option(List(1, 2, 3, 4)))

val i = consume[Int, Id, List] &= enumStream(Stream(1, 2, 3))
val res2 = i.run
println(res2)
assert(res2 == Stream(1, 2, 3))
}
}
78 changes: 61 additions & 17 deletions project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ import com.typesafe.sbt.osgi.SbtOsgi._

import sbtbuildinfo.BuildInfoPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import org.scalajs.sbtplugin.cross._
import scalanative.sbtplugin.ScalaNativePlugin.autoImport._
import scalajscrossproject.ScalaJSCrossPlugin.autoImport.{toScalaJSGroupID => _, _}
import sbtcrossproject.CrossPlugin.autoImport._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.isScalaJSProject

object build {
type Sett = Def.Setting[_]

val rootNativeId = "rootNative"
val nativeTestId = "nativeTest"

lazy val publishSignedArtifacts = ReleaseStep(
action = st => {
val extracted = st.extract
Expand Down Expand Up @@ -73,25 +77,43 @@ object build {
)

// avoid move files
// https://github.com/scala-js/scala-js/blob/v0.6.7/sbt-plugin/src/main/scala/scala/scalajs/sbtplugin/cross/CrossProject.scala#L193-L206
object ScalazCrossType extends CrossType {
object ScalazCrossType extends sbtcrossproject.CrossType {
override def projectDir(crossBase: File, projectType: String) =
crossBase / projectType

override def projectDir(crossBase: File, projectType: sbtcrossproject.Platform) = {
val dir = projectType match {
case JVMPlatform => "jvm"
case JSPlatform => "js"
case NativePlatform => "native"
}
crossBase / dir
}

def shared(projectBase: File, conf: String) =
projectBase.getParentFile / "src" / conf / "scala"

override def sharedSrcDir(projectBase: File, conf: String) =
Some(shared(projectBase, conf))
}

private val Scala211_jvm_and_js_options = Seq(
"-Ybackend:GenBCode",
"-Ydelambdafy:method",
"-target:jvm-1.8"
)

private def Scala211 = "2.11.8"

private val SetScala211 = releaseStepCommand("++" + Scala211)

lazy val standardSettings: Seq[Sett] = Seq[Sett](
organization := "org.scalaz",
mappings in (Compile, packageSrc) ++= (managedSources in Compile).value.map{ f =>
(f, f.relativeTo((sourceManaged in Compile).value).get.getPath)
},
scalaVersion := "2.12.1",
crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.1"),
crossScalaVersions := Seq("2.10.6", Scala211, "2.12.1"),
resolvers ++= (if (scalaVersion.value.endsWith("-SNAPSHOT")) List(Opts.resolver.sonatypeSnapshots) else Nil),
fullResolvers ~= {_.filterNot(_.name == "jcenter")}, // https://github.com/sbt/sbt/issues/2217
scalaCheckVersion := "1.13.4",
Expand All @@ -105,11 +127,7 @@ object build {
"-unchecked"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2,10)) => scalac210Options
case Some((2,11)) => Seq(
"-Ybackend:GenBCode",
"-Ydelambdafy:method",
"-target:jvm-1.8"
)
case Some((2,11)) => Scala211_jvm_and_js_options
case _ => Nil
}),

Expand Down Expand Up @@ -173,10 +191,14 @@ object build {
checkSnapshotDependencies,
inquireVersions,
runTest,
SetScala211,
releaseStepCommand(s"${nativeTestId}/run"),
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishSignedArtifacts,
SetScala211,
releaseStepCommand(s"${rootNativeId}/publishSigned"),
setNextVersion,
commitNextVersion,
pushChanges
Expand Down Expand Up @@ -236,7 +258,19 @@ object build {
OsgiKeys.additionalHeaders := Map("-removeheaders" -> "Include-Resource,Private-Package")
)

lazy val core = crossProject.crossType(ScalazCrossType)
private[this] val jvm_js_settings = Seq(
unmanagedSourceDirectories in Compile += {
baseDirectory.value.getParentFile / "jvm_js/src/main/scala/"
}
)

val nativeSettings = Seq(
scalacOptions --= Scala211_jvm_and_js_options,
scalaVersion := Scala211,
crossScalaVersions := Scala211 :: Nil
)

lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings: _*)
.settings(
name := "scalaz-core",
Expand All @@ -250,20 +284,24 @@ object build {
OsgiKeys.importPackage := Seq("javax.swing;resolution:=optional", "*"))
.enablePlugins(sbtbuildinfo.BuildInfoPlugin)
.jsSettings(
scalajsProjectSettings ++ Seq(
libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "0.2.0"
) : _*
jvm_js_settings,
scalajsProjectSettings,
libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "0.2.0"
)
.jvmSettings(
jvm_js_settings,
libraryDependencies ++= PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)){
case Some((2, 11)) => "org.scala-lang.modules" %% "scala-java8-compat" % "0.7.0"
}.toList,
typeClasses := TypeClass.core
)
.nativeSettings(
nativeSettings
)

final val ConcurrentName = "scalaz-concurrent"

lazy val effect = crossProject.crossType(ScalazCrossType)
lazy val effect = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings: _*)
.settings(
name := "scalaz-effect",
Expand All @@ -273,14 +311,20 @@ object build {
.jvmSettings(
typeClasses := TypeClass.effect
)
.nativeSettings(
nativeSettings
)

lazy val iteratee = crossProject.crossType(ScalazCrossType)
lazy val iteratee = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings: _*)
.settings(
name := "scalaz-iteratee",
osgiExport("scalaz.iteratee"))
.dependsOn(core, effect)
.jsSettings(scalajsProjectSettings : _*)
.nativeSettings(
nativeSettings
)

lazy val publishSetting = publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand Down
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
scalacOptions += "-deprecation"

addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0")

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.1.0")

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

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
Expand Down

0 comments on commit 38f90ff

Please sign in to comment.