Skip to content

Commit

Permalink
Crossbuild for Scala3 (#430)
Browse files Browse the repository at this point in the history
Co-authored-by: Dejan Mijić <[email protected]>
  • Loading branch information
KadekM and mijicd authored Sep 15, 2021
1 parent 24ae957 commit 42c239e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
fail-fast: false
matrix:
java: ['[email protected]', '[email protected]']
scala: ['2.12.14', '2.13.6']
scala: ['2.12.15', '2.13.6', '3.0.2']
steps:
- name: Checkout current branch
uses: actions/[email protected]
Expand All @@ -64,6 +64,9 @@ jobs:
uses: coursier/cache-action@v6
- name: Run tests
run: sbt ++${{ matrix.scala }}! test
- name: Compile examples
if: ${{ startsWith(matrix.scala, '2') }}
run: ./sbt ++${{ matrix.scala }}! compileExamples

ci:
runs-on: ubuntu-20.04
Expand Down
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ Global / testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramew

addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")
addCommandAlias("compileExamples", "opentracingExample/compile;opentelemetryExample/compile")

lazy val root =
project
.in(file("."))
.settings(publish / skip := true)
.aggregate(opentracing, opentelemetry, opencensus, opentracingExample, opentelemetryExample)
.aggregate(opentracing, opentelemetry, opencensus)

lazy val opentracing =
project
Expand All @@ -65,6 +66,7 @@ lazy val opentracingExample =
.in(file("opentracing-example"))
.settings(stdSettings("opentracing-example"))
.settings(publish / skip := true)
.settings(onlyWithScala2)
.settings(libraryDependencies := Dependencies.opentracingExample)
.dependsOn(opentracing)

Expand All @@ -73,6 +75,7 @@ lazy val opentelemetryExample =
.in(file("opentelemetry-example"))
.settings(stdSettings("opentelemetry-example"))
.settings(publish / skip := true)
.settings(onlyWithScala2)
.settings(libraryDependencies := Dependencies.opentelemetryExample)
.dependsOn(opentelemetry)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object OpenTracingTest extends DefaultRunnableSpec {
ZLayer.fromEffect(UIO(new MockTracer))

val testService: URLayer[HasMockTracer with Clock, OpenTracing] =
ZLayer.fromServiceManaged(tracer => OpenTracing.managed(tracer, "ROOT"))
ZLayer.fromServiceManaged((tracer: MockTracer) => OpenTracing.managed(tracer, "ROOT"))

val customLayer = mockTracer ++ ((mockTracer ++ Clock.any) >>> testService)

Expand Down
27 changes: 21 additions & 6 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ object BuildHelper {

def stdSettings(prjName: String) = Seq(
name := s"$prjName",
crossScalaVersions := Seq(Scala212, Scala213),
crossScalaVersions := Seq(Scala212, Scala213, Scala3),
ThisBuild / scalaVersion := Scala212,
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value),
libraryDependencies += compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
incOptions ~= (_.withLogRecompileOnMacro(false))
)

val onlyWithScala2 = Seq(
crossScalaVersions := Seq(Scala212, Scala213)
)

private val versions: Map[String, String] = {
import org.snakeyaml.engine.v2.api.{ Load, LoadSettings }

Expand All @@ -27,15 +31,21 @@ object BuildHelper {

private val Scala212: String = versions("2.12")
private val Scala213: String = versions("2.13")
private val Scala3: String = versions("3.0")

private val stdOptions = Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-unchecked",
"-Xfatal-warnings"
)
"-unchecked"
) ++ {
if (sys.env.contains("CI")) {
Seq("-Xfatal-warnings")
} else {
Nil // to enable Scalafix locally
}
}

private val std2xOptions = Seq(
"-language:higherKinds",
Expand All @@ -52,6 +62,12 @@ object BuildHelper {

private def extraOptions(scalaVersion: String, optimize: Boolean) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((3, _)) =>
Seq(
"-language:implicitConversions",
"-Xignore-scala2-macros"
)

case Some((2, 13)) =>
Seq("-Ywarn-unused:params,-implicits", "-Xlint:-byname-implicit") ++ std2xOptions ++ optimizerOptions(optimize)

Expand All @@ -74,7 +90,6 @@ object BuildHelper {
"242"
) ++ std2xOptions ++ optimizerOptions(optimize)

case _ =>
Seq.empty
case _ => Seq.empty
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Dependencies {
"io.opentracing" % "opentracing-api" % Versions.opentracing,
"io.opentracing" % "opentracing-noop" % Versions.opentracing,
"io.opentracing" % "opentracing-mock" % Versions.opentracing % Test,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.3.1"
"org.scala-lang.modules" %% "scala-collection-compat" % "2.5.0"
)

lazy val opentelemetry = zio ++ Seq(
Expand Down

0 comments on commit 42c239e

Please sign in to comment.