Skip to content

Commit

Permalink
wip:add native build
Browse files Browse the repository at this point in the history
  • Loading branch information
i10416 committed Mar 20, 2022
1 parent b80fb21 commit bfdfdd0
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ jobs:
- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p target docs/target core/js/target core/jvm/target project/target
run: mkdir -p target core/native/target docs/target core/js/target core/jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar target docs/target core/js/target core/jvm/target project/target
run: tar cf targets.tar target core/native/target docs/target core/js/target core/jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ lazy val jvmVersionSettings = VersionNumber(sys.props("java.version")) match {

lazy val root = project
.in(file("."))
.aggregate(core.jvm, core.js, bench)
.aggregate(core.jvm, core.js, core.native, bench)
.enablePlugins(NoPublishPlugin)
.settings(scalaVersion := "2.13.8")

Expand Down Expand Up @@ -109,7 +109,7 @@ lazy val docs = project
)
.dependsOn(coreJVM, bench)

lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.settings(
name := "cats-parse",
Expand Down Expand Up @@ -156,6 +156,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)

lazy val coreJVM = core.jvm.settings(jvmVersionSettings)
lazy val coreJS = core.js
lazy val coreNative = core.native

lazy val bench = project
.enablePlugins(JmhPlugin, NoPublishPlugin)
Expand Down
1 change: 1 addition & 0 deletions core/js/src/main/scala/cats/parse/BitSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import scala.collection.mutable.BitSet
object BitSetUtil {
type Tpe = BitSet

@inline final val isScalaNative = false
@inline final val isScalaJs = true
@inline final val isScalaJvm = false

Expand Down
2 changes: 1 addition & 1 deletion core/jvm/src/main/scala/cats/parse/BitSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.BitSet

object BitSetUtil {
type Tpe = BitSet

@inline final val isScalaNative = false
@inline final val isScalaJs = false
@inline final val isScalaJvm = true

Expand Down
69 changes: 69 additions & 0 deletions core/native/src/main/scala/cats/parse/BitSet.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2021 Typelevel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cats.parse

import scala.collection.mutable.BitSet

object BitSetUtil {
type Tpe = BitSet
@inline final val isScalaNative = true
@inline final val isScalaJs = false
@inline final val isScalaJvm = false

@inline final def isSet(b: BitSet, idx: Int): Boolean =
(idx >= 0) && b(idx)

def bitSetFor(charArray: Array[Char]): BitSet = {
val min = charArray(0).toInt
val bs = new BitSet(charArray(charArray.length - 1).toInt + 1 - min)
var idx = 0
while (idx < charArray.length) {
bs += charArray(idx).toInt - min
idx += 1
}

bs
}

def isSingleton(t: Tpe): Boolean = t.size == 1

def union(bs: List[(Int, BitSet)]): Iterable[Char] =
union(bs.iterator)

// what are all the Chars in these bitsets
def union(bs: Iterator[(Int, BitSet)]): Iterable[Char] = {
def toIter(m: Int, bs: BitSet): Iterator[Char] =
bs.iterator.map { i => (i + m).toChar } ++ Iterator.single(m.toChar)

bs.flatMap { case (m, bs) => toIter(m, bs) }.toSet
}

def bitSetForRange(count: Int): BitSet = {
val bs = new BitSet(count)
var cur = 0
while (cur < count) {
bs += cur
cur += 1
}
bs
}
}
9 changes: 4 additions & 5 deletions core/shared/src/test/scala/cats/parse/BitSetTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ package cats.parse
import org.scalacheck.Prop.forAll

class BitSetTest extends munit.ScalaCheckSuite {
test("isScalaJs/isScalaJvm is consistent") {
// This will need to be updated if we ever add scala-native
assert(!(BitSetUtil.isScalaJs && BitSetUtil.isScalaJvm))
assert(BitSetUtil.isScalaJs || BitSetUtil.isScalaJvm)
assert(BitSetUtil.isScalaJs ^ BitSetUtil.isScalaJvm)
test("isScalaJs/isScalaJvm/isScalaNative is consistent") {
assert(!(BitSetUtil.isScalaJs && BitSetUtil.isScalaJvm && BitSetUtil.isScalaNative))
assert(BitSetUtil.isScalaJs || BitSetUtil.isScalaJvm || BitSetUtil.isScalaNative)
assert(BitSetUtil.isScalaJs ^ BitSetUtil.isScalaJvm ^ BitSetUtil.isScalaNative)
}

property("BitSetUtil union works") {
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.9.2")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.1.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.4")
Expand Down

0 comments on commit bfdfdd0

Please sign in to comment.