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

Cross-build for Native #426

Merged
merged 3 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ jobs:
os: [ubuntu-latest]
scala: [3.1.3, 2.11.12, 2.12.16, 2.13.8]
java: [temurin@8]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
exclude:
- project: rootJS
scala: 2.11.12
- project: rootNative
scala: 2.11.12
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -77,6 +82,10 @@ jobs:
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/nativeLink

- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

Expand All @@ -90,11 +99,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 .js/target site/target core/js/target core/jvm/target .jvm/target .native/target project/target
run: mkdir -p target .js/target core/native/target site/target core/js/target core/jvm/target .jvm/target .native/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 .js/target site/target core/js/target core/jvm/target .jvm/target .native/target project/target
run: tar cf targets.tar target .js/target core/native/target site/target core/js/target core/jvm/target .jvm/target .native/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 Expand Up @@ -167,12 +176,12 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.11.12, rootJS)
- name: Download target directories (3.1.3, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.11.12-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootNative

- name: Inflate target directories (2.11.12, rootJS)
- name: Inflate target directories (3.1.3, rootNative)
run: |
tar xf targets.tar
rm targets.tar
Expand Down Expand Up @@ -207,6 +216,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.16, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.16-rootNative

- name: Inflate target directories (2.12.16, rootNative)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.8, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -227,6 +246,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.8, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootNative

- name: Inflate target directories (2.13.8, rootNative)
run: |
tar xf targets.tar
rm targets.tar

- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down Expand Up @@ -281,7 +310,7 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- run: sbt '++${{ matrix.scala }}' coverage test coverageAggregate
- run: sbt '++${{ matrix.scala }}' coverage rootJVM/test coverageAggregate

- run: 'bash <(curl -s https://codecov.io/bash)'

Expand Down
25 changes: 21 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import com.typesafe.tools.mima.core._
import Dependencies._
val scala211 = "2.11.12"
val scala212 = "2.12.16"
val scala213 = "2.13.8"
val scala3 = "3.1.3"

addCommandAlias("fmt", "; scalafmtAll; scalafmtSbt")
addCommandAlias("fmtCheck", "; scalafmtCheckAll; scalafmtSbtCheck")

Expand All @@ -9,19 +14,26 @@ ThisBuild / tlBaseVersion := "0.3"
ThisBuild / startYear := Some(2021)
ThisBuild / developers += tlGitHubDev("johnynek", "P. Oscar Boykin")

ThisBuild / crossScalaVersions := List("3.1.3", "2.11.12", "2.12.16", "2.13.8")
ThisBuild / crossScalaVersions := List(scala3, scala211, scala212, scala213)

ThisBuild / tlVersionIntroduced := Map("3" -> "0.3.4")
ThisBuild / tlSkipIrrelevantScalas := true

ThisBuild / githubWorkflowBuildMatrixExclusions ++=
Seq(
MatrixExclude(Map("project" -> "rootJS", "scala" -> scala211)),
MatrixExclude(Map("project" -> "rootNative", "scala" -> scala211))
)

ThisBuild / githubWorkflowAddedJobs ++= Seq(
WorkflowJob(
id = "coverage",
name = "Generate coverage report",
scalas = List("2.13.8"),
scalas = List(scala213),
steps = List(WorkflowStep.Checkout) ++ WorkflowStep.SetupJava(
githubWorkflowJavaVersions.value.toList
) ++ githubWorkflowGeneratedCacheSteps.value ++ List(
WorkflowStep.Sbt(List("coverage", "test", "coverageAggregate")),
WorkflowStep.Sbt(List("coverage", "rootJVM/test", "coverageAggregate")),
WorkflowStep.Run(List("bash <(curl -s https://codecov.io/bash)"))
)
)
Expand All @@ -38,7 +50,7 @@ lazy val isScala211 = Def.setting {
scalaBinaryVersion.value == "2.11"
}

lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.settings(
name := "cats-parse",
Expand Down Expand Up @@ -79,6 +91,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
crossScalaVersions := (ThisBuild / crossScalaVersions).value.filterNot(_.startsWith("2.11")),
coverageEnabled := false
)
.nativeSettings(
crossScalaVersions := (ThisBuild / crossScalaVersions).value.filterNot(_.startsWith("2.11")),
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.3.8").toMap,
coverageEnabled := false
)

lazy val bench = project
.enablePlugins(JmhPlugin, NoPublishPlugin)
Expand Down
24 changes: 24 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,24 @@
/*
* 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

object BitSetUtil extends BitSetUtilCompat(false, false)
8 changes: 4 additions & 4 deletions core/shared/src/test/scala/cats/parse/BitSetTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import org.scalacheck.Prop.forAll
class BitSetTest extends munit.ScalaCheckSuite {
// TODO: Remove isScalaJs/isScalaJvm in next minor version update. See https://github.com/typelevel/cats-parse/issues/391.
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)
if (BitSetUtil.isScalaJs || BitSetUtil.isScalaJvm) {
assert(!(BitSetUtil.isScalaJs && BitSetUtil.isScalaJvm))
assert(BitSetUtil.isScalaJs ^ BitSetUtil.isScalaJvm)
}
}

property("BitSetUtil union works") {
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/test/scala/cats/parse/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class ParserTest extends munit.ScalaCheckSuite {

import ParserGen.{arbParser0, arbParser, biasSmall, genString, arbString}

val tests: Int = if (BitSetUtil.isScalaJs) 50 else 2000
val tests: Int = if (BitSetUtil.isScalaJvm) 2000 else 50

override def scalaCheckTestParameters =
super.scalaCheckTestParameters
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/test/scala/cats/parse/RadixNodeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.scalacheck.{Gen, Prop}
import org.scalacheck.Prop.forAll

class RadixNodeTest extends munit.ScalaCheckSuite {
val tests: Int = if (BitSetUtil.isScalaJs) 50 else 20000
val tests: Int = if (BitSetUtil.isScalaJvm) 20000 else 50

override def scalaCheckTestParameters =
super.scalaCheckTestParameters
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
object Dependencies {
lazy val cats = Def.setting("org.typelevel" %%% "cats-core" % "2.8.0")
lazy val cats211 = Def.setting("org.typelevel" %%% "cats-core" % "2.0.0")
lazy val munit = Def.setting("org.scalameta" %%% "munit" % "0.7.29")
lazy val munitScalacheck = Def.setting("org.scalameta" %%% "munit-scalacheck" % "0.7.29")
lazy val munit = Def.setting("org.scalameta" %%% "munit" % "1.0.0-M6")
lazy val munitScalacheck = Def.setting("org.scalameta" %%% "munit-scalacheck" % "1.0.0-M6")
lazy val fastParse = "com.lihaoyi" %% "fastparse" % "2.3.3"
lazy val parsley = "org.http4s" %% "parsley" % "1.5.0-M3"
lazy val jawnAst = "org.typelevel" %% "jawn-ast" % "1.3.2"
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.4")

Choose a reason for hiding this comment

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

just FYI, 0.4.5 enables building Scala 3 Native on Java 17 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I forgot update this. No problem, there will be a steward update here shortly :)

Copy link
Member Author

Choose a reason for hiding this comment

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

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
Expand Down