Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile most modules with Scala Native #384

Merged
merged 14 commits into from
Oct 5, 2022
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.12.16, 2.13.8, 3.1.3]
scala: [2.12.17, 2.13.8, 3.2.0]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down
99 changes: 66 additions & 33 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
val scala212 = "2.12.16"
val scala212 = "2.12.17"
val scala213 = "2.13.8"
val scala3 = "3.1.3"
val fs2Version = "3.2.12"
val circeVersion = "0.14.2"
val circeExtrasVersion = "0.14.1"
val playVersion = "2.9.2"
val scala3 = "3.2.0"
val fs2Version = "3.3.0"
val circeVersion = "0.14.3"
val circeExtrasVersion = "0.14.2"
val playVersion = "2.10.0-RC6"
val shapeless2Version = "2.3.9"
val shapeless3Version = "3.1.0"
val shapeless3Version = "3.2.0"
val scalaJavaTimeVersion = "2.4.0"
val diffsonVersion = "4.1.1"
val diffsonVersion = "4.3.0"
val literallyVersion = "1.1.0"
val weaverVersion = "0.8.0"

val copyrightYears = "2019-2022"

ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")

val commonSettings = List(
scalaVersion := scala213,
crossScalaVersions := Seq(scala213, scala212, scala3),
Expand Down Expand Up @@ -64,11 +67,11 @@ val commonSettings = List(
"io.circe" %%% "circe-jawn" % circeVersion % "test",
"io.circe" %%% "circe-generic" % circeVersion % "test",
"co.fs2" %%% "fs2-io" % fs2Version % "test",
"com.disneystreaming" %%% "weaver-cats" % "0.7.15" % "test",
"com.disneystreaming" %%% "weaver-cats-core" % "0.7.15" % "test",
"com.disneystreaming" %%% "weaver-core" % "0.7.15" % "test",
"com.disneystreaming" %%% "weaver-framework" % "0.7.15" % "test",
"com.eed3si9n.expecty" %%% "expecty" % "0.15.4" % "test",
"com.disneystreaming" %%% "weaver-cats" % weaverVersion % "test",
"com.disneystreaming" %%% "weaver-cats-core" % weaverVersion % "test",
"com.disneystreaming" %%% "weaver-core" % weaverVersion % "test",
"com.disneystreaming" %%% "weaver-framework" % weaverVersion % "test",
"com.eed3si9n.expecty" %%% "expecty" % "0.16.0" % "test",
"org.portable-scala" %%% "portable-scala-reflect" % "1.1.2" cross CrossVersion.for3Use2_13
) ++ PartialFunction
.condOpt(CrossVersion.partialVersion(scalaVersion.value)) { case Some((2, _)) =>
Expand All @@ -92,12 +95,16 @@ val publishSettings = List(
Developer(id = "satabin",
name = "Lucas Satabin",
email = "[email protected]",
url = url("https://github.com/satabin"))
url = url("https://github.com/satabin")),
Developer(id = "ybasket",
name = "Yannick Heiber",
email = "[email protected]",
url = url("https://github.com/ybasket"))
),
pomExtra := (
<ciManagement>
<system>travis</system>
<url>https://travis-ci.org/#!/satabin/fs2-data</url>
<system>GitHub Actions</system>
<url>https://github.com/satabin/fs2-data/actions</url>
</ciManagement>
<issueManagement>
<system>github</system>
Expand All @@ -115,18 +122,31 @@ val root = (project in file("."))
publish / skip := true,
ScalaUnidoc / unidoc / unidocProjectFilter := inAnyProject -- inProjects(
cbor.js,
cbor.native,
cborJson.js,
cborJson.native,
csv.js,
csv.native,
csvGeneric.js,
csvGeneric.native,
json.js,
json.native,
jsonCirce.js,
jsonCirce.native,
jsonDiffson.js,
jsonDiffson.native,
jsonPlay.js,
jsonInterpolators.js,
jsonInterpolators.native,
text.js,
text.native,
xml.js,
xml.native,
scalaXml.js,
finiteState.js
scalaXml.native,
finiteState.js,
finiteState.native,
benchmarks.jvm
),
ScalaUnidoc / siteSubdirName := "api",
addMappingsToSiteDir(ScalaUnidoc / packageDoc / mappings, ScalaUnidoc / siteSubdirName),
Expand All @@ -137,31 +157,45 @@ val root = (project in file("."))
.aggregate(
text.jvm,
text.js,
text.native,
csv.jvm,
csv.js,
csv.native,
csvGeneric.jvm,
csvGeneric.js,
csvGeneric.native,
json.jvm,
json.js,
json.native,
jsonCirce.jvm,
jsonCirce.js,
jsonCirce.native,
jsonDiffson.jvm,
jsonDiffson.js,
jsonDiffson.native,
jsonInterpolators.jvm,
jsonInterpolators.js,
jsonInterpolators.native,
jsonPlay.jvm,
jsonPlay.js,
Comment on lines +179 to +180
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact they were missing didn't seem to bother anyone, the only published version was 1.3.0: https://mvnrepository.com/artifact/org.gnieh/fs2-data-json-play

Trying to fix this now within this PR by releasing full Diffson support.

I'm in favour of dropping support in v2, that library seems rather dead and the code we maintain is so small that it could easily be inlined in users' projects.

xml.jvm,
xml.js,
xml.native,
scalaXml.jvm,
scalaXml.js,
scalaXml.native,
cbor.jvm,
cbor.js,
cbor.native,
cborJson.jvm,
cborJson.js,
cborJson.native,
finiteState.jvm,
finiteState.js
finiteState.js,
finiteState.native
)

lazy val text = crossProject(JVMPlatform, JSPlatform)
lazy val text = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("text"))
.settings(commonSettings)
Expand All @@ -171,7 +205,7 @@ lazy val text = crossProject(JVMPlatform, JSPlatform)
description := "Utilities for textual data format"
)

lazy val csv = crossProject(JVMPlatform, JSPlatform)
lazy val csv = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("csv"))
.settings(commonSettings)
Expand All @@ -186,7 +220,7 @@ lazy val csv = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(text)

lazy val csvGeneric = crossProject(JVMPlatform, JSPlatform)
lazy val csvGeneric = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("csv/generic"))
.settings(commonSettings)
Expand Down Expand Up @@ -227,7 +261,7 @@ lazy val csvGeneric = crossProject(JVMPlatform, JSPlatform)
.jsSettings(libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test)
.dependsOn(csv)

lazy val json = crossProject(JVMPlatform, JSPlatform)
lazy val json = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("json"))
.settings(commonSettings)
Expand All @@ -245,7 +279,7 @@ lazy val json = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(text, finiteState)

lazy val jsonCirce = crossProject(JVMPlatform, JSPlatform)
lazy val jsonCirce = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("json/circe"))
.settings(commonSettings)
Expand All @@ -269,22 +303,21 @@ lazy val jsonCirce = crossProject(JVMPlatform, JSPlatform)
.dependsOn(json % "compile->compile;test->test", jsonDiffson % "test->test")

lazy val jsonPlay = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.crossType(CrossType.Pure)
.in(file("json/play"))
.settings(commonSettings)
.settings(publishSettings)
.settings(
name := "fs2-data-json-play",
description := "Streaming JSON library with support for Play! JSON ASTs",
crossScalaVersions := Seq(scala212, scala213),
libraryDependencies ++= List(
"com.typesafe.play" %%% "play-json" % playVersion,
"org.gnieh" %%% "diffson-play-json" % diffsonVersion % "test"
)
)
.dependsOn(json % "compile->compile;test->test", jsonDiffson % "test->test")

lazy val jsonDiffson = crossProject(JVMPlatform, JSPlatform)
lazy val jsonDiffson = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("json/diffson"))
.settings(commonSettings)
Expand All @@ -298,7 +331,7 @@ lazy val jsonDiffson = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(json % "compile->compile;test->test")

lazy val jsonInterpolators = crossProject(JVMPlatform, JSPlatform)
lazy val jsonInterpolators = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("json/interpolators"))
.settings(commonSettings)
Expand All @@ -316,7 +349,7 @@ lazy val jsonInterpolators = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(json % "compile->compile;test->test")

lazy val xml = crossProject(JVMPlatform, JSPlatform)
lazy val xml = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("xml"))
.settings(commonSettings)
Expand All @@ -337,7 +370,7 @@ lazy val xml = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(text, finiteState)

lazy val scalaXml = crossProject(JVMPlatform, JSPlatform)
lazy val scalaXml = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("xml/scala-xml"))
.settings(commonSettings)
Expand All @@ -352,7 +385,7 @@ lazy val scalaXml = crossProject(JVMPlatform, JSPlatform)
)
.dependsOn(xml % "compile->compile;test->test")

lazy val cbor = crossProject(JVMPlatform, JSPlatform)
lazy val cbor = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("cbor"))
.settings(commonSettings)
Expand All @@ -371,7 +404,7 @@ lazy val cbor = crossProject(JVMPlatform, JSPlatform)
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
)

lazy val finiteState = crossProject(JVMPlatform, JSPlatform)
lazy val finiteState = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("finite-state"))
.settings(commonSettings)
Expand All @@ -381,7 +414,7 @@ lazy val finiteState = crossProject(JVMPlatform, JSPlatform)
description := "Streaming finite state machines"
)

lazy val cborJson = crossProject(JVMPlatform, JSPlatform)
lazy val cborJson = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("cbor-json"))
.settings(commonSettings)
Expand All @@ -405,7 +438,7 @@ lazy val documentation = project
mdocIn := file("documentation/docs"),
mdocOut := file("site/content/documentation"),
libraryDependencies ++= List(
"com.beachape" %% "enumeratum" % "1.5.15",
"com.beachape" %% "enumeratum" % "1.7.0",
"org.gnieh" %% "diffson-circe" % diffsonVersion,
"io.circe" %% "circe-generic-extras" % circeExtrasVersion,
"co.fs2" %% "fs2-io" % fs2Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ package fs2.data.csv

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to fix compiler warnings from 3.2.0.

trait LiteralCellDecoders {

private[this] abstract class LiteralCellDecoder[A, L <: A](decodeA: CellDecoder[A], L: ValueOf[L])
extends CellDecoder[L] {
protected[this] def check(a: A): Boolean
protected[this] def message: String
private abstract class LiteralCellDecoder[A, L <: A](decodeA: CellDecoder[A], L: ValueOf[L]) extends CellDecoder[L] {
protected[csv] def check(a: A): Boolean
protected[csv] def message: String

final def apply(s: String): DecoderResult[L] = decodeA(s) match {
case r @ Right(value) if check(value) => r.asInstanceOf[DecoderResult[L]]
Expand All @@ -31,56 +30,56 @@ trait LiteralCellDecoders {

implicit final def literalStringDecoder[L <: String](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[String, L](CellDecoder.stringDecoder, L) {
protected[this] final def check(a: String): Boolean = a == L.value
protected[this] final def message: String = s"""String("${L.value}")"""
protected[csv] final def check(a: String): Boolean = a == L.value
protected[csv] final def message: String = s"""String("${L.value}")"""
}

implicit final def literalCharDecoder[L <: Char](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Char, L](CellDecoder.charDecoder, L) {
protected[this] final def check(a: Char): Boolean = a == L.value
protected[this] final def message: String = s"""Char("${L.value}")"""
protected[csv] final def check(a: Char): Boolean = a == L.value
protected[csv] final def message: String = s"""Char("${L.value}")"""
}

implicit final def literalByteDecoder[L <: Byte](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Byte, L](CellDecoder.byteDecoder, L) {
protected[this] final def check(a: Byte): Boolean = a == L.value
protected[this] final def message: String = s"""Byte("${L.value}")"""
protected[csv] final def check(a: Byte): Boolean = a == L.value
protected[csv] final def message: String = s"""Byte("${L.value}")"""
}

implicit final def literalShortDecoder[L <: Short](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Short, L](CellDecoder.shortDecoder, L) {
protected[this] final def check(a: Short): Boolean = a == L.value
protected[this] final def message: String = s"""Short("${L.value}")"""
protected[csv] final def check(a: Short): Boolean = a == L.value
protected[csv] final def message: String = s"""Short("${L.value}")"""
}

implicit final def literalIntDecoder[L <: Int](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Int, L](CellDecoder.intDecoder, L) {
protected[this] final def check(a: Int): Boolean = a == L.value
protected[this] final def message: String = s"""Int("${L.value}")"""
protected[csv] final def check(a: Int): Boolean = a == L.value
protected[csv] final def message: String = s"""Int("${L.value}")"""
}

implicit final def literalLongDecoder[L <: Long](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Long, L](CellDecoder.longDecoder, L) {
protected[this] final def check(a: Long): Boolean = a == L.value
protected[this] final def message: String = s"""Long("${L.value}")"""
protected[csv] final def check(a: Long): Boolean = a == L.value
protected[csv] final def message: String = s"""Long("${L.value}")"""
}

implicit final def literalFloatDecoder[L <: Float](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Float, L](CellDecoder.floatDecoder, L) {
protected[this] final def check(a: Float): Boolean = java.lang.Float.compare(L.value, a) == 0
protected[this] final def message: String = s"""Float("${L.value}")"""
protected[csv] final def check(a: Float): Boolean = java.lang.Float.compare(L.value, a) == 0
protected[csv] final def message: String = s"""Float("${L.value}")"""
}

implicit final def literalDoubleDecoder[L <: Double](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Double, L](CellDecoder.doubleDecoder, L) {
protected[this] final def check(a: Double): Boolean = java.lang.Double.compare(L.value, a) == 0
protected[this] final def message: String = s"""Double("${L.value}")"""
protected[csv] final def check(a: Double): Boolean = java.lang.Double.compare(L.value, a) == 0
protected[csv] final def message: String = s"""Double("${L.value}")"""
}

implicit final def literalBooleanDecoder[L <: Boolean](implicit L: ValueOf[L]): CellDecoder[L] =
new LiteralCellDecoder[Boolean, L](CellDecoder.booleanDecoder, L) {
protected[this] final def check(a: Boolean): Boolean = a == L.value
protected[this] final def message: String = s"""Boolean("${L.value}")"""
protected[csv] final def check(a: Boolean): Boolean = a == L.value
protected[csv] final def message: String = s"""Boolean("${L.value}")"""
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object JavaTimeRoundTripTest extends SimpleIOSuite {
}

pureTest("it should round trip java time classes with default fmts") {
val expectedZonedDateTime: ZonedDateTime = ZonedDateTime.of(2021, 3, 8, 13, 4, 29, 6, ZoneId.of("America/New_York"))
val expectedZonedDateTime: ZonedDateTime = ZonedDateTime.of(2021, 3, 8, 13, 4, 29, 6, ZoneId.systemDefault())
val expectedInstant: Instant = expectedZonedDateTime.toInstant
val expectedPeriod: Period = Period.ofDays(10)
val expectedLocalDate: LocalDate = expectedZonedDateTime.toLocalDate
Expand Down Expand Up @@ -65,8 +65,8 @@ object JavaTimeRoundTripTest extends SimpleIOSuite {

pureTest("it should round trip with overridden formats") {
val expectedZonedDateTime: ZonedDateTime =
ZonedDateTime.of(LocalDateTime.of(2021, 3, 8, 13, 4, 29), ZoneId.of("America/New_York"))
val expectedString: String = "3/8/2021 13:04:29-0500"
ZonedDateTime.of(LocalDateTime.of(2021, 3, 8, 13, 4, 29), ZoneOffset.UTC)
val expectedString: String = "3/8/2021 13:04:29+0000"
val encoded: String = enc(expectedZonedDateTime)
val decoded: DecoderResult[ZonedDateTime] = dec(encoded)
expect(encoded == expectedString) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import cats.syntax.all._

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuilder

import scala.collection.compat._

private[data] class PNFA[P, T](val init: Int, val finals: Set[Int], val transitions: Map[Int, List[(Option[P], Int)]])(
Expand Down
Loading