Skip to content

Commit

Permalink
Merge pull request #26 from ScorexFoundation/scala-js
Browse files Browse the repository at this point in the history
Cross-compilation with Scala.js
  • Loading branch information
aslesarenko authored Feb 26, 2023
2 parents 00827a0 + abae86a commit 5e99fe8
Show file tree
Hide file tree
Showing 36 changed files with 405 additions and 209 deletions.
54 changes: 46 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ env:

jobs:
build:
name: Test and publish a snapshot
name: JVM - Test and publish a snapshot
env:
HAS_SECRETS: ${{ secrets.SONATYPE_PASSWORD != '' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10, 2.11.12, 2.13.1]
scala: [2.13.8, 2.12.15, 2.11.12]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -47,17 +47,55 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Runs tests and collect coverage
run: sbt ++${{ matrix.scala }} coverage test coverageReport coverageAggregate
- name: Runs tests
run: sbt ++${{ matrix.scala }} coreJVM/test

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v1
- name: Publish a snapshot ${{ github.ref }}
if: env.HAS_SECRETS == 'true'
run: sbt ++${{ matrix.scala }} coreJVM/publish
env:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

buildJs:
name: JS - Test and publish a snapshot
env:
HAS_SECRETS: ${{ secrets.SONATYPE_PASSWORD != '' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8, 2.12.15]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fail_ci_if_error: true
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Runs tests
run: sbt ++${{ matrix.scala }} coreJS/test

- name: Publish a snapshot ${{ github.ref }}
if: env.HAS_SECRETS == 'true'
run: sbt ++${{ matrix.scala }} publish
run: sbt ++${{ matrix.scala }} coreJS/publish
env:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

- name: Publish release ${{ github.ref }}
run: sbt +publishSigned sonatypeBundleRelease
run: sbt +coreJVM/publishSigned +coreJS/publishSigned sonatypeBundleRelease
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand Down
221 changes: 179 additions & 42 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,66 +1,203 @@
import scala.util.Try

name := "scorex-util"
description := "Common tools for scorex projects"
lazy val scalac: Seq[String] = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
// "-Xfatal-warnings", // Fail the compilation if there are any warnings.
// "-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-numeric-widen" // Warn when numerics are widened.
//"-Xlog-free-terms",
)

organization := "org.scorexfoundation"
lazy val scalac211: Seq[String] = Seq(
"-optimize",
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Xfuture", // Turn on future language features.
)

lazy val scalac212: Seq[String] = Seq(
"-opt:simplify-jumps",
"-opt:compact-locals",
"-opt:copy-propagation",
"-opt:box-unbox",
"-opt:closure-invocations",
"-opt:unreachable-code",
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xfuture", // Turn on future language features.
)

lazy val scala212 = "2.12.10"
lazy val scalac213: Seq[String] = Seq(
"-opt:simplify-jumps",
"-opt:compact-locals",
"-opt:copy-propagation",
"-opt:box-unbox",
"-opt:closure-invocations",
"-opt:unreachable-code",
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
)


lazy val scala213 = "2.13.8"
lazy val scala212 = "2.12.15"
lazy val scala211 = "2.11.12"
lazy val scala213 = "2.13.1"
crossScalaVersions := Seq(scala212, scala211, scala213)

crossScalaVersions := Seq(scala211, scala212, scala213)
scalaVersion := scala212
organization := "org.scorexfoundation"

javacOptions ++=
"-source" :: "1.8" ::
"-target" :: "1.8" ::
Nil

resolvers ++= Seq("Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/",
"SonaType" at "https://oss.sonatype.org/content/groups/public",
"Typesafe maven releases" at "http://repo.typesafe.com/typesafe/maven-releases/",
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
lazy val utilSettings = Seq(
organization := "org.scorexfoundation",
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
homepage := Some(url("http://github.com/ScorexFoundation/scorex-util")),
description := "Common tools for scorex projects",

resolvers += Resolver.sonatypeRepo("public"),
libraryDependencies ++= Seq(
// scalaOrganization.value % "scala-reflect" % scalaVersion.value % "provided",
"org.rudogma" %%% "supertagged" % "2.0-RC2",
"org.scalatest" %%% "scalatest" % "3.3.0-SNAP3" % Test,
"org.scalatest" %%% "scalatest-propspec" % "3.3.0-SNAP3" % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % "3.3.0-SNAP3" % Test,
"org.scalatestplus" %%% "scalacheck-1-15" % "3.3.0.0-SNAP3" % Test,
"org.scalacheck" %%% "scalacheck" % "1.15.2" % Test
),

scalacOptions := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n == 13 =>
scalac ++ scalac213
case Some((2, n)) if n == 12 =>
scalac ++ scalac212
case Some((2, 11)) =>
scalac ++ scalac211
}
},
javacOptions ++= javacReleaseOption,
publishMavenStyle := true,
publishTo := sonatypePublishToBundle.value,
pomExtra := (
<developers>
<developer>
<id>kushti</id>
<name>Alexander Chepurnoy</name>
<url>http://chepurnoy.org/</url>
</developer>
<developer>
<id>aslesarenko</id>
<name>Alexander Slesarenko</name>
<url>https://github.com/aslesarenko/</url>
</developer>
</developers>
),
scmInfo := Some(
ScmInfo(
url("https://github.com/ScorexFoundation/scorex-util"),
"scm:[email protected]:ScorexFoundation/scorex-util.git"
)
)
)

libraryDependencies ++= Seq(
"org.rudogma" %% "supertagged" % "1.5",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
"org.scalatest" %% "scalatest" % "3.1.1" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.+" % Test,
// https://mvnrepository.com/artifact/org.scalatestplus/scalatestplus-scalacheck
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test
lazy val core = crossProject(JSPlatform, JVMPlatform)
.in(file("."))
.settings(moduleName := "scorex-util")
.settings(utilSettings)
.jvmSettings(
scalaVersion := scala213,
crossScalaVersions := Seq(scala211, scala212, scala213),
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %%% "scala-logging" % "3.9.2"
),
)
.jsSettings(
scalaVersion := scala213,
crossScalaVersions := Seq(scala212, scala213),
libraryDependencies ++= Seq(
),
Test / parallelExecution := false
)

def javacReleaseOption = {
if (System.getProperty("java.version").startsWith("1."))
// java <9 "--release" is not supported
Seq()
else
Seq("--release", "8")
}

)
// prefix version with "-SNAPSHOT" for builds without a git tag
ThisBuild / dynverSonatypeSnapshots := true
// use "-" instead of default "+"
ThisBuild / dynverSeparator := "-"

publishMavenStyle in ThisBuild := true
publishTo := sonatypePublishToBundle.value
publishArtifact in Test := true
Test / publishArtifact := true
pomIncludeRepository := { _ => false }

credentials ++= (for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq

fork in ThisBuild := true

pomIncludeRepository in ThisBuild := { _ => false }

licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode"))
homepage := Some(url("https://github.com/ScorexFoundation/scorex-util"))
pomExtra :=
<developers>
<developer>
<id>kushti</id>
<name>Alexander Chepurnoy</name>
<url>http://chepurnoy.org/</url>
</developer>
</developers>

// prefix version with "-SNAPSHOT" for builds without a git tag
dynverSonatypeSnapshots in ThisBuild := true
// use "-" instead of default "+"
dynverSeparator in ThisBuild := "-"


// PGP key for signing a release build published to sonatype
// signing is done by sbt-pgp plugin
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.4
sbt.version=1.5.4
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
Loading

0 comments on commit 5e99fe8

Please sign in to comment.