Permalink
Browse files

support scala-native

  • Loading branch information...
xuwei-k committed Feb 25, 2017
1 parent b163d10 commit 6d7bfa87c32d570c132e681faf712c60eb1fd1be
View
@@ -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
View
@@ -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
@@ -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")
@@ -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",
@@ -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",
@@ -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",
@@ -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",
@@ -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)
@@ -0,0 +1,4 @@
package scalaz
package std
trait FutureInstances
@@ -0,0 +1,4 @@
package scalaz
package std.java
trait TimeInstances
@@ -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))
}
}
View
@@ -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
@@ -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",
@@ -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
}),
@@ -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
@@ -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",
@@ -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",
@@ -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/"
View
@@ -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")

0 comments on commit 6d7bfa8

Please sign in to comment.