Skip to content

Commit

Permalink
Cross compile to Scala Native (#301)
Browse files Browse the repository at this point in the history
Cross compile to Scala Native
  • Loading branch information
fthomas committed Feb 5, 2018
1 parent e1b5f1d commit bbb92f7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
language: scala
scala:
- 2.10.7
- 2.11.12
- 2.12.4
jdk:
- oraclejdk8
sudo: false
Expand All @@ -27,3 +23,13 @@ notifications:
on_success: change
on_failure: always
on_start: false
matrix:
include:
- scala: 2.10.7
- scala: 2.11.12
sudo: required
before_install:
- curl https://raw.githubusercontent.com/scala-native/scala-native/v0.3.6/bin/travis_setup.sh | bash -x
script:
- sbt ++$TRAVIS_SCALA_VERSION coreNative/compile validate
- scala: 2.12.4
22 changes: 18 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ val scodecVersion = "1.10.3"

val macroParadise =
"org.scalamacros" % "paradise" % macroParadiseVersion cross CrossVersion.patch
val scalaCheckDep =
Def.setting("org.scalacheck" %%% "scalacheck" % scalaCheckVersion)

val allSubprojects =
Seq("cats", "core", "eval", "jsonpath", "pureconfig", "scalacheck", "scalaz", "scodec")
Expand All @@ -32,6 +34,8 @@ val allSubprojectsJS = {
(allSubprojects diff jvmOnlySubprojects).map(_ + "JS")
}

val Scala211 = Def.setting(crossScalaVersions.value.find(_.startsWith("2.11")).get)

/// projects

lazy val root = project
Expand Down Expand Up @@ -82,7 +86,7 @@ lazy val cats = crossProject(JSPlatform, JVMPlatform)
lazy val catsJVM = cats.jvm
lazy val catsJS = cats.js

lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.configureCross(moduleCrossConfig("core"))
.enablePlugins(BuildInfoPlugin)
.settings(moduleName := projectName)
Expand All @@ -91,9 +95,9 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
compilerPlugin(macroParadise),
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
scalaOrganization.value % "scala-compiler" % scalaVersion.value,
"org.typelevel" %%% "macro-compat" % macroCompatVersion,
"org.typelevel" %% "macro-compat" % macroCompatVersion,
"com.chuusai" %%% "shapeless" % shapelessVersion,
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test
scalaCheckDep.value % Test
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand All @@ -108,9 +112,17 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := s"$rootPkg.internal"
)
.nativeSettings(
libraryDependencies -= scalaCheckDep.value % Test,
// Disable Scaladoc generation because of:
// [error] dropping dependency on node with no phase object: mixin
publishArtifact in packageDoc := false,
sources in (Compile, doc) := Seq.empty
)

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

lazy val docs = project
.configure(moduleConfig("docs"))
Expand Down Expand Up @@ -164,7 +176,7 @@ lazy val scalacheck = crossProject(JSPlatform, JVMPlatform)
.configureCross(moduleCrossConfig("scalacheck"))
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
libraryDependencies += scalaCheckDep.value,
initialCommands += s"""
import org.scalacheck.Arbitrary
"""
Expand Down Expand Up @@ -416,6 +428,8 @@ lazy val releaseSettings = {
commitReleaseVersion,
tagRelease,
publishArtifacts,
releaseStepCommand(s"++${Scala211.value}"),
releaseStepCommand("coreNative/publishSigned"),
setLatestVersion,
setNextVersion,
commitNextVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ trait RefType[F[_, _]] extends Serializable {
def unsafeRewrap[T, A, B](ta: F[T, A]): F[T, B]

def unsafeWrapM[T: c.WeakTypeTag, P: c.WeakTypeTag](c: blackbox.Context)(
t: c.Expr[T]): c.Expr[F[T, P]]
t: c.Expr[T]): c.Expr[F[T, P]] =
c.universe.reify(unsafeWrap(t.splice))

def unsafeRewrapM[T: c.WeakTypeTag, A: c.WeakTypeTag, B: c.WeakTypeTag](c: blackbox.Context)(
ta: c.Expr[F[T, A]]): c.Expr[F[T, B]]
ta: c.Expr[F[T, A]]): c.Expr[F[T, B]] =
c.universe.reify(unsafeRewrap(ta.splice))

/**
* Returns a value of type `T` refined as `F[T, P]` on the right if
Expand Down
2 changes: 2 additions & 0 deletions notes/0.9.0.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Add `predicates` package which allows to import all predicates
with a single `import eu.timepit.refined.predicates.all._`.
([#433][#433])
* Cross build the core module for Scala Native. ([#301][#301])

### Changes

Expand All @@ -29,6 +30,7 @@

* Update `refined-scalaz` to Scalaz 7.2.19. ([#434][#434])

[#301]: https://github.com/fthomas/refined/pull/301
[#415]: https://github.com/fthomas/refined/pull/415
[#416]: https://github.com/fthomas/refined/issues/416
[#425]: https://github.com/fthomas/refined/pull/425
Expand Down
5 changes: 5 additions & 0 deletions project/plugin-scala-native.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Remember to update the version number in .travis.yml too.
addSbtPlugin(
"org.scala-native" % "sbt-scala-native" % "0.3.6"
exclude ("org.scala-native", "sbt-crossproject") // https://github.com/portable-scala/sbt-crossproject/issues/72
)

0 comments on commit bbb92f7

Please sign in to comment.