From 0d580a6ad27541a3a5e19027a009af9353411400 Mon Sep 17 00:00:00 2001 From: Mackenzie Starr Date: Fri, 23 Sep 2022 17:22:14 -0400 Subject: [PATCH] build: scala 2.13 compatibility for fs2-grpc-codegen --- .github/workflows/ci.yml | 4 +- build.sbt | 42 ++++++++++++------- .../fs2/grpc/codegen/Fs2CodeGenerator.scala | 4 +- project/plugins.sbt | 2 + 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27130e7d..67846250 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,11 +106,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 plugin/target target codegen/target runtime/target project/target + run: mkdir -p plugin/target target runtime/target/jvm-2.12 codegen/target/jvm-3 codegen/target/jvm-2.13 runtime/target/jvm-3 codegen/target/jvm-2.12 runtime/target/jvm-2.13 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 plugin/target target codegen/target runtime/target project/target + run: tar cf targets.tar plugin/target target runtime/target/jvm-2.12 codegen/target/jvm-3 codegen/target/jvm-2.13 runtime/target/jvm-3 codegen/target/jvm-2.12 runtime/target/jvm-2.13 project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') diff --git a/build.sbt b/build.sbt index 2f882bea..4283debe 100644 --- a/build.sbt +++ b/build.sbt @@ -6,6 +6,9 @@ lazy val Scala3 = "3.2.0" lazy val Scala213 = "2.13.10" lazy val Scala212 = "2.12.17" +lazy val axesDefault = + Seq(VirtualAxis.scalaABIVersion(Scala213), VirtualAxis.jvm) + Global / lintUnusedKeysOnLoad := false def dev(ghUser: String, name: String, email: String): Developer = @@ -44,21 +47,24 @@ inThisBuild( ) ) -// +lazy val projects = + runtime.projectRefs ++ codegen.projectRefs ++ e2e.projectRefs ++ List(plugin.project, protocGen.agg.project) -lazy val root = project - .in(file(".")) +lazy val root = (project in file(".")) .enablePlugins(BuildInfoPlugin, NoPublishPlugin) - .aggregate(runtime, codegen, plugin, e2e, protocGen.agg) + .aggregate(projects: _*) .dependsOn(protocGen.agg) -lazy val codegen = project +lazy val codegen = (projectMatrix in file("codegen")) + .defaultAxes(axesDefault: _*) .settings( name := "fs2-grpc-codegen", - scalaVersion := Scala212, - crossScalaVersions := List(Scala212), - libraryDependencies += scalaPbCompiler + libraryDependencies += scalaPbCompiler, + tlMimaPreviousVersions := { + if (scalaVersion == Scala212) tlMimaPreviousVersions.value else Set() // Temporary + } ) + .jvmPlatform(scalaVersions = Seq(Scala212, Scala213, Scala3)) lazy val codegenFullName = "fs2.grpc.codegen.Fs2CodeGenerator" @@ -78,22 +84,26 @@ lazy val plugin = project sbtVersion, organization, "grpcVersion" -> versions.grpc, - "codeGeneratorName" -> (codegen / name).value, + "codeGeneratorName" -> (codegen.jvm(Scala212) / name).value, "codeGeneratorFullName" -> codegenFullName, - "runtimeName" -> (runtime / name).value + "runtimeName" -> (runtime.jvm(Scala212) / name).value ), libraryDependencies += scalaPbCompiler, addSbtPlugin(sbtProtoc) ) -lazy val runtime = project +lazy val runtime = (projectMatrix in file("runtime")) + .defaultAxes(axesDefault: _*) .settings( name := "fs2-grpc-runtime", + crossScalaVersions := List(Scala212, Scala213), libraryDependencies ++= List(fs2, catsEffect, grpcApi) ++ List(grpcNetty, ceTestkit, ceMunit).map(_ % Test), Test / parallelExecution := false ) + .jvmPlatform(scalaVersions = Seq(Scala212, Scala213, Scala3)) -lazy val protocGen = protocGenProject("protoc-gen-fs2-grpc", codegen) +lazy val codeGenJVM212 = codegen.jvm(Scala212) +lazy val protocGen = protocGenProject("protoc-gen-fs2-grpc", codeGenJVM212) .settings( Compile / mainClass := Some(codegenFullName), githubWorkflowArtifactUpload := false, @@ -105,12 +115,13 @@ lazy val protocGen = protocGenProject("protoc-gen-fs2-grpc", codegen) mimaPreviousArtifacts := Set() ) -lazy val e2e = project - .in(file("e2e")) +lazy val e2e = (projectMatrix in file("e2e")) .dependsOn(runtime) + .defaultAxes(axesDefault: _*) .enablePlugins(LocalCodeGenPlugin, BuildInfoPlugin, NoPublishPlugin) .settings( - codeGenClasspath := (codegen / Compile / fullClasspath).value, + crossScalaVersions := Seq(Scala212, Scala213), + codeGenClasspath := (codeGenJVM212 / Compile / fullClasspath).value, libraryDependencies := Nil, libraryDependencies ++= List(scalaPbGrpcRuntime, scalaPbRuntime, scalaPbRuntime % "protobuf", ceMunit % Test), Compile / PB.targets := Seq( @@ -121,3 +132,4 @@ lazy val e2e = project buildInfoKeys := Seq[BuildInfoKey]("sourceManaged" -> (Compile / sourceManaged).value / "fs2-grpc"), githubWorkflowArtifactUpload := false ) + .jvmPlatform(scalaVersions = Seq(Scala212, Scala213, Scala3)) diff --git a/codegen/src/main/scala/fs2/grpc/codegen/Fs2CodeGenerator.scala b/codegen/src/main/scala/fs2/grpc/codegen/Fs2CodeGenerator.scala index e0f83aae..2d20f9c4 100644 --- a/codegen/src/main/scala/fs2/grpc/codegen/Fs2CodeGenerator.scala +++ b/codegen/src/main/scala/fs2/grpc/codegen/Fs2CodeGenerator.scala @@ -27,7 +27,7 @@ import com.google.protobuf.compiler.PluginProtos import protocgen.{CodeGenApp, CodeGenRequest, CodeGenResponse} import scalapb.compiler.{DescriptorImplicits, FunctionalPrinter, GeneratorParams} import scalapb.options.Scalapb -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ final case class Fs2Params(serviceSuffix: String = "Fs2Grpc") @@ -47,7 +47,7 @@ object Fs2CodeGenerator extends CodeGenApp { b.setName(file.scalaDirectory + "/" + service.name + s"${fs2params.serviceSuffix}.scala") b.setContent(code) b.build - } + }.toSeq } private def parseParameters(params: String): Either[String, (GeneratorParams, Fs2Params)] = diff --git a/project/plugins.sbt b/project/plugins.sbt index ed212de4..e847cfda 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,8 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.16") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0") + addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4") addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") // Because sbt-protoc-gen-project brings in 1.0.4