Skip to content

Commit

Permalink
Cross compile with Scala JS and Scala Native
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Sep 24, 2022
1 parent 26277c1 commit de95087
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 93 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ on:

jobs:
build:
name: Build pipez${{matrix.scalaPlatform}}${{matrix.scalaVersion}} pipezDsl${{matrix.scalaPlatform}}${{matrix.scalaVersion}}

runs-on: ubuntu-latest

strategy:
matrix:
scala: [2.13.8, 3.2.0]
jvm: [adopt@1.8.0-292, openjdk@1.17.0]
jvm: [openjdk@1.17.0]
scalaVersion: ["", 3]
scalaPlatform: ["", JS, Native]
fail-fast: false

env:
SUFFIX: ${{matrix.scalaPlatform}}${{matrix.scalaVersion}}

steps:
- uses: actions/checkout@v2
- uses: coursier/cache-action@v6
- uses: olafurpg/setup-scala@v11
with:
java-version: ${{ matrix.jvm }}
- name: Clean, Check code formatting, compile, test
run: sbt ++${{ matrix.scala }} clean scalafmtCheck test:scalafmtCheck compile test
run: sbt clean scalafmtCheck test:scalafmtCheck pipez$SUFFIX/Test/compile pipezDsl$SUFFIX/Test/compile pipez$SUFFIX/test pipezDsl$SUFFIX/test
131 changes: 41 additions & 90 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,110 +1,61 @@
val scala2version = "2.13.8"
val scala3version = "3.2.0"

// compiling

val commonSettings = Seq(
scalaVersion := scala3version,
crossScalaVersions := Seq(scala2version, scala3version),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-deprecation", "-feature", "-Xsource:3", "-P:kind-projector:underscore-placeholders")
case Some((3, 2)) => Seq("-explain", "-rewrite", "-source", "3.2-migration", "-Ykind-projector:underscores")
case _ => Seq.empty
}
},
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq(
compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full)
)
case _ => Seq.empty
}
},
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
scalafmtOnCompile := true
)

// publishing

val publishSettings = Seq(
organization := "com.kubuszok",
homepage := Some(url("https://kubuszok.com")),
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(
ScmInfo(url("https://github.com/MateuszKubuszok/pipez"), "scm:git@github.com/MateuszKubuszok/pipez.git")
),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
Test / publishArtifact := false,
pomIncludeRepository := { _ =>
false
},
pomExtra :=
<developers>
<developer>
<id>MateuszKubuszok</id>
<name>Mateusz Kubuszok</name>
<url>https://github.com/MateuszKubuszok</url>
</developer>
</developers>
)
val noPublishSettings = Seq(
publish / skip := true,
publishArtifact := false
)
import commandmatrix.extra._
import Settings._

// 2.13 only since apparently my way of doing Java Beans (@BeanProperty) have slightly different behavior in 3.x
val testCases = project
val testCases = projectMatrix
.in(file("testcases"))
.settings(
name := "testcases",
scalaVersion := scala2version,
crossScalaVersions := Seq(scala2version),
scalacOptions ++= Seq("-deprecation", "-feature", "-Xsource:3")
.allVariations(
List(scala2_13version),
List(VirtualAxis.jvm, VirtualAxis.js, VirtualAxis.native)
)
.settings(name := "testcases")
.settings(commonSettings)
.settings(publishSettings)
.settings(noPublishSettings)

val pipez = project
val pipez = projectMatrix
.in(file("pipez"))
.allVariations(
List(scala2_13version, scala3version),
List(VirtualAxis.jvm, VirtualAxis.js, VirtualAxis.native)
)
.enablePlugins(GitVersioning)
.settings(name := "pipez")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.dependsOn(testCases % "test->compile")
.settings(
name := "pipez",
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
case _ => Seq.empty
}
}
excludeDependencies ++= Seq(
ExclusionRule().withName("testcases_3"),
ExclusionRule().withName("testcases_sjs1_3"),
ExclusionRule().withName("testcases_native0.4_3")
)
)
.settings(commonSettings)
.settings(publishSettings)
.dependsOn(testCases % "test->compile")

val pipezDsl = project
val pipezDsl = projectMatrix
.in(file("pipez-dsl"))
.allVariations(
List(scala2_13version, scala3version),
List(VirtualAxis.jvm, VirtualAxis.js, VirtualAxis.native)
)
.enablePlugins(GitVersioning)
.settings(name := "pipez-dsl")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.dependsOn(testCases % "compile->test", pipez)
.settings(
name := "pipez-dsl"
excludeDependencies ++= Seq(
ExclusionRule().withName("testcases_3"),
ExclusionRule().withName("testcases_sjs1_3"),
ExclusionRule().withName("testcases_native0.4_3")
)
)
.settings(commonSettings)
.dependsOn(testCases % "test->compile", pipez)

val root = project
.in(file("."))
.enablePlugins(GitVersioning)
.settings(
name := "pipez-build",
)
.settings(commonSettings)
.settings(publishSettings)
.settings(noPublishSettings)
.aggregate(pipez, pipezDsl)

addCommandAlias("use-213", s"++ $scala2version")
addCommandAlias("use-3", s"++ $scala3version")
.settings(name := "pipez-build")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(noPublishSettings: _*)
.aggregate(pipez.projectRefs ++ pipezDsl.projectRefs: _*)
68 changes: 68 additions & 0 deletions project/Settings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import sbt._
import sbt.Keys._
import org.scalafmt.sbt.ScalafmtPlugin.autoImport._
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import commandmatrix.extra._

object Settings {

val scala2_13version = "2.13.8"
val scala3version = "3.2.0"

// compiling

val commonSettings = Seq(
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-deprecation", "-feature", "-Xsource:3", "-P:kind-projector:underscore-placeholders")
case Some((3, 2)) => Seq("-explain", "-rewrite", "-source", "3.2-migration", "-Ykind-projector:underscores")
case _ => Seq.empty
}
},
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full)
)
case _ => Seq.empty
}
},
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.0-M6" % Test,
scalafmtOnCompile := true
)

// publishing

val publishSettings = Seq(
organization := "com.kubuszok",
homepage := Some(url("https://kubuszok.com")),
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(
ScmInfo(url("https://github.com/MateuszKubuszok/pipez"), "scm:git@github.com/MateuszKubuszok/pipez.git")
),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
Test / publishArtifact := false,
pomIncludeRepository := { _ =>
false
},
pomExtra :=
<developers>
<developer>
<id>MateuszKubuszok</id>
<name>Mateusz Kubuszok</name>
<url>https://github.com/MateuszKubuszok</url>
</developer>
</developers>
)

val noPublishSettings = Seq(
publish / skip := true,
publishArtifact := false
)
}
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.0")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0")
addSbtPlugin("com.indoorvivants" % "sbt-commandmatrix" % "0.0.5")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")

0 comments on commit de95087

Please sign in to comment.