Skip to content

Commit

Permalink
Merge pull request #580 from typelevel/use-project-matrix
Browse files Browse the repository at this point in the history
build: scala 2.13 compatibility for fs2-grpc-codegen
  • Loading branch information
ahjohannessen authored Nov 4, 2022
2 parents 3d7d5ff + 0d580a6 commit 969ed9b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
42 changes: 27 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)] =
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 969ed9b

Please sign in to comment.