From 332474adf9d65941684aeb9d6ee997c7dc17c549 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 10 Apr 2020 11:32:07 +0100 Subject: [PATCH] Add support for scala-native and scalajs 1.0 --- .gitignore | 1 + build.sbt | 23 ++++++++++++----- .../macros/NonNativeNewTypeMacrosTest.scala | 25 +++++++++++++++++++ .../macros/NonNativeNewTypeMacrosTest.scala | 25 +++++++++++++++++++ project/plugins.sbt | 7 ++++-- .../newtype/macros/NewTypeMacrosTest.scala | 3 --- 6 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 js/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala create mode 100644 jvm/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala diff --git a/.gitignore b/.gitignore index 92322c4..87d2284 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ target/ +*.hnir diff --git a/build.sbt b/build.sbt index 350f894..635b678 100644 --- a/build.sbt +++ b/build.sbt @@ -4,15 +4,22 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject organization in ThisBuild := "io.estatico" lazy val root = project.in(file(".")) - .aggregate(newtypeJS, newtypeJVM, catsTestsJVM) + .aggregate(newtypeJS, newtypeJVM, newtypeNative, catsTestsJVM) .settings(noPublishSettings) -lazy val newtype = crossProject(JSPlatform, JVMPlatform).in(file(".")) +lazy val newtype = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file(".")) .settings(defaultSettings) .settings(releasePublishSettings) .settings(name := "newtype") + .nativeSettings( + crossScalaVersions := List("2.11.12"), + scalaVersion := "2.11.12", + nativeLinkStubs := true, + Compile / scalacOptions += "-Yno-predef" // needed to ensure users can use -Yno-predef + ) lazy val newtypeJVM = newtype.jvm +lazy val newtypeNative = newtype.native lazy val newtypeJS = newtype.js lazy val catsTests = crossProject(JVMPlatform).in(file("cats-tests")) @@ -116,7 +123,6 @@ lazy val defaultSettings = Seq( lazy val defaultScalacOptions = scalacOptions ++= Seq( "-Xfatal-warnings", - "-Yno-predef", // needed to ensure users can use -Yno-predef "-unchecked", "-feature", "-deprecation", @@ -129,12 +135,17 @@ lazy val defaultScalacOptions = scalacOptions ++= Seq( case _ => // on scala 2.12+ some spurious unused warnings get triggered Seq("-Xlint:-unused,_") -}) +}) ++ (if (crossProjectPlatform.value == NativePlatform) + Seq() // Removing the 'predef' on scala native-tests, breaks the test integration with sbt + else + Seq("-Yno-predef")) // needed to ensure users can use -Yno-predef lazy val defaultLibraryDependencies = libraryDependencies ++= Seq( scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided, scalaOrganization.value % "scala-compiler" % scalaVersion.value % Provided, "org.scalacheck" %%% "scalacheck" % "1.14.3" % Test, - "org.scalatest" %%% "scalatest" % "3.1.1" % Test, - "org.scalatestplus" %%% "scalacheck-1-14" % "3.1.1.1" % Test, + "org.scalatest" %%% "scalatest" % "3.2.0-M4" % Test, + "org.scalatestplus" %%% "scalacheck-1-14" % "3.2.0.0-M4" % Test ) + + diff --git a/js/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala b/js/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala new file mode 100644 index 0000000..7b2f3eb --- /dev/null +++ b/js/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala @@ -0,0 +1,25 @@ +package io.estatico.newtype.macros + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers +import io.estatico.newtype.ops._ +import org.scalacheck.Arbitrary + +class NonNativeNewTypeMacrosTest extends AnyFlatSpec with Matchers { + + import NewTypeMacrosTest._ + + behavior of "@newtype with type bounds" + + it should "enforce type bounds" in { + val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]] + val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int]) + + assertCompiles("x: Sub[java.util.HashMap[String, Int]]") + assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") + + assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") + assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]") + } + +} diff --git a/jvm/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala b/jvm/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala new file mode 100644 index 0000000..7b2f3eb --- /dev/null +++ b/jvm/src/test/scala/io/estatico/newtype/macros/NonNativeNewTypeMacrosTest.scala @@ -0,0 +1,25 @@ +package io.estatico.newtype.macros + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers +import io.estatico.newtype.ops._ +import org.scalacheck.Arbitrary + +class NonNativeNewTypeMacrosTest extends AnyFlatSpec with Matchers { + + import NewTypeMacrosTest._ + + behavior of "@newtype with type bounds" + + it should "enforce type bounds" in { + val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]] + val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int]) + + assertCompiles("x: Sub[java.util.HashMap[String, Int]]") + assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") + + assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") + assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]") + } + +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 33ef698..f069cc4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,5 +2,8 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") + +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2") diff --git a/shared/src/test/scala/io/estatico/newtype/macros/NewTypeMacrosTest.scala b/shared/src/test/scala/io/estatico/newtype/macros/NewTypeMacrosTest.scala index 8a9a3a1..009e89a 100644 --- a/shared/src/test/scala/io/estatico/newtype/macros/NewTypeMacrosTest.scala +++ b/shared/src/test/scala/io/estatico/newtype/macros/NewTypeMacrosTest.scala @@ -112,12 +112,9 @@ class NewTypeMacrosTest extends AnyFlatSpec with Matchers { it should "enforce type bounds" in { val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]] - val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int]) assertCompiles("x: Sub[java.util.HashMap[String, Int]]") - assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") - assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]") assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]") }