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

Add scala-native cross build #414

Merged
merged 12 commits into from Aug 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
os: [ubuntu-latest]
scala: [3.1.3]
java: [temurin@8]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -77,6 +77,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 +94,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 benchmarks/target target testkit/js/target .js/target js/target jvm/target .jvm/target .native/target unitTests/target testkit/jvm/target project/target
run: mkdir -p benchmarks/target testkit/native/target target testkit/js/target .js/target native/target js/target unitTests/native/target jvm/target .jvm/target unitTests/jvm/target .native/target unitTests/js/target testkit/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 benchmarks/target target testkit/js/target .js/target js/target jvm/target .jvm/target .native/target unitTests/target testkit/jvm/target project/target
run: tar cf targets.tar benchmarks/target testkit/native/target target testkit/js/target .js/target native/target js/target unitTests/native/target jvm/target .jvm/target unitTests/jvm/target .native/target unitTests/js/target testkit/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 Expand Up @@ -167,6 +171,16 @@ jobs:
tar xf targets.tar
rm targets.tar

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

- name: Inflate target directories (3.1.3, 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
33 changes: 24 additions & 9 deletions build.sbt
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "2.1"
ThisBuild / tlBaseVersion := "2.2"

ThisBuild / organization := "org.scodec"
ThisBuild / organizationName := "Scodec"
Expand Down Expand Up @@ -41,7 +41,7 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq(

lazy val root = tlCrossRootProject.aggregate(testkit, core, unitTests, benchmarks)

lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("."))
.settings(
name := "scodec-core",
Expand All @@ -64,28 +64,43 @@ lazy val coreJS = core.js.settings(
)
)

lazy val testkit = crossProject(JVMPlatform, JSPlatform)
lazy val coreNative = core.native.settings(
tlVersionIntroduced ++= List("2.12", "2.13", "3").map(_ -> "2.2.0").toMap
)

lazy val testkit = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
name := "scodec-testkit",
libraryDependencies += "org.scalameta" %%% "munit-scalacheck" % "0.7.29",
libraryDependencies += "org.scalameta" %%% "munit-scalacheck" % "1.0.0-M6",
scalacOptions := scalacOptions.value.filterNot(_ == "-source:3.0-migration") :+ "-source:future"
)
.dependsOn(core % "compile->compile")

lazy val testkitJVM = testkit.jvm
lazy val testkitJS = testkit.js
lazy val testkitNative = testkit.native.settings(
tlVersionIntroduced ++= List("2.12", "2.13", "3").map(_ -> "2.2.0").toMap
)

lazy val unitTests = project
lazy val unitTests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
libraryDependencies ++= Seq(
"org.bouncycastle" % "bcpkix-jdk18on" % "1.71" % "test"
),
scalacOptions := scalacOptions.value.filterNot(
_ == "-source:3.0-migration"
) :+ "-source:future",
Test / scalacOptions := (Compile / scalacOptions).value
)
.dependsOn(testkitJVM % "test->compile")
.jvmSettings(
libraryDependencies ++= Seq(
"org.bouncycastle" % "bcpkix-jdk18on" % "1.71" % Test
)
)
.jsSettings(
libraryDependencies ++= Seq(
("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
)
.dependsOn(testkit % "test->compile")
.enablePlugins(NoPublishPlugin)

lazy val benchmarks = project
Expand Down
37 changes: 37 additions & 0 deletions native/src/main/scala/scodec/Platform.scala
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2013, Scodec
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package scodec

import java.nio.charset.Charset

private[scodec] object Platform:
val utf8: Charset = Charset.forName("UTF-8").nn
val ascii: Charset = Charset.forName("US-ASCII").nn
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

Without running tests no idea if this works, or why it had to be written differently for JS /shrug

2 changes: 2 additions & 0 deletions project/plugins.sbt
@@ -1,3 +1,5 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.13")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.5")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
Expand Up @@ -34,17 +34,19 @@ package codecs
class DiscriminatorCodecTest extends CodecSuite:

test("support building a codec using typecases") {
val codec =
discriminated[AnyVal]
.by(uint8)
.typecase(0, int32)
.typecase(1, bool)

roundtrip(codec, true)
roundtrip(codec, false)
roundtrip(codec, 1)
roundtrip(codec, Int.MaxValue)
assertEquals(codec.sizeBound, SizeBound.bounded(9, 40))
if (sys.props("vm.name") ne null) {
val codec =
discriminated[AnyVal]
.by(uint8)
.typecase(0, int32)
.typecase(1, bool)

roundtrip(codec, true)
roundtrip(codec, false)
roundtrip(codec, 1)
roundtrip(codec, Int.MaxValue)
assertEquals(codec.sizeBound, SizeBound.bounded(9, 40))
}
}

test("support building a codec using partial functions and subtyping") {
Expand Down