akka / akka-grpc

Akka gRPC
https://doc.akka.io/docs/akka-grpc/
Other
432 stars 123 forks source link

Play ball with other generators #1454

Open regiskuckaertz opened 2 years ago

regiskuckaertz commented 2 years ago

Short description

Let the akka-grpc SBT plugin co-exist with other protobuf generators.

Details

Hello. For some reason we need to generate both the akka- and zio-based prototypes for a project. It is currently not possible (or I should say we did not find a way) to do both in the same sbt project; I think the akka plugin disables the default scalaPB gRPC generator and changes the output directory.

Ideally we would like all generators to co-exist in peace and harmony with each other, as if brothers and sisters :-)

raboof commented 2 years ago

I agree it would be good to allow different generators to exist side-by-side - after all in the end the Akka gRPC sbt plugin mainly provides a convenient way to configure the Akka gRPC generators.

I thought we already mostly 'played nice' here, for example we only append to PB.targets, not replace it (https://github.com/akka/akka-grpc/blob/main/sbt-plugin/src/main/scala/akka/grpc/sbt/AkkaGrpcPlugin.scala#L123). Similarly, we add the akka-grpc managed code directory (https://github.com/akka/akka-grpc/blob/main/sbt-plugin/src/main/scala/akka/grpc/sbt/AkkaGrpcPlugin.scala#L111), AFAIK this shouldn't impact other generators.

On the sbt prompt, does protocTargets show both akka- and zio-based generators?

Anyway, this first step should definitely solvable. The might be some further challenges ahead, though: there could be naming clashes between the akka- and zio-generated code, or you might have .proto files that you want to be processed by one but not the other. Those might be more tricky to resolve - but let's tackle those as we encounter them!

jtjeferreira commented 2 years ago

Recently I was seting up the scalapb-validate processor and also had an hard time making it work because the target folder used by akka-grpc was not obviuos. The solution was

PB.targets in Compile ++= Seq(
  scalapb.validate.gen(scalapb.GeneratorOption.FlatPackage) -> (Compile / akkaGrpcCodeGeneratorSettings / target).value
)

PS: better integration of akka-grpc and the validation would also be nice (having automatic validation of the messages in server and client), but that's a different issue...