scalapb / zio-grpc

ScalaPB meets ZIO: write purely functional gRPC services and clients using ZIO
Apache License 2.0
259 stars 82 forks source link

Is it possible to generate both Akka and ZIO grpcs at the same time? #541

Closed omidb closed 1 year ago

omidb commented 1 year ago

I have a single project that contains all the protos and I want to generate both Akka and ZIO grpc codes:

    Compile / akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Scala, AkkaGrpc.Java),
    akkaGrpcCodeGeneratorSettings := akkaGrpcCodeGeneratorSettings.value.filterNot(_ == "flat_package"),
    akkaGrpcCodeGeneratorSettings += "server_power_apis",
    akkaGrpcCodeGeneratorSettings += "java_conversions",
    Compile / PB.targets := Seq(
      scalapb.gen(grpc = true, javaConversions = true) -> (Compile / sourceManaged).value,
      scalapb.zio_grpc.ZioCodeGenerator -> (Compile / sourceManaged).value,
      PB.gens.java -> (Compile / sourceManaged).value,
    ),
    Compile / PB.protoSources := Seq(
      (ThisBuild / baseDirectory).value / "protos" / "src" / "main" / "protobuf" / "mystuff",

The plugins are not generating the Akka codes anymore. What's the workaround?

thesamet commented 1 year ago

Try changing to Compile / PB.targets ++= to prevent overriding Akka grpc putting.

On Mon, Aug 14, 2023, 11:57 AM Omid Bakhshandeh @.***> wrote:

I have a single project that contains all the protos and I want to generate both Akka and ZIO grpc codes:

Compile / akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Scala, AkkaGrpc.Java),
akkaGrpcCodeGeneratorSettings := akkaGrpcCodeGeneratorSettings.value.filterNot(_ == "flat_package"),
akkaGrpcCodeGeneratorSettings += "server_power_apis",
akkaGrpcCodeGeneratorSettings += "java_conversions",
Compile / PB.targets := Seq(
  scalapb.gen(grpc = true, javaConversions = true) -> (Compile / sourceManaged).value,
  scalapb.zio_grpc.ZioCodeGenerator -> (Compile / sourceManaged).value,
  PB.gens.java -> (Compile / sourceManaged).value,
),
Compile / PB.protoSources := Seq(
  (ThisBuild / baseDirectory).value / "protos" / "src" / "main" / "protobuf" / "mystuff",

The plugins are not generating the Akka codes anymore. What's the workaround?

— Reply to this email directly, view it on GitHub https://github.com/scalapb/zio-grpc/issues/541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLBLIA4RLTH5ABCNKW26DXVJYJFANCNFSM6AAAAAA3QC5G2Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

omidb commented 1 year ago

@thesamet

xxxx/build.sbt:87: error: No Append.Values[Seq[protocbridge.Target], Seq[(Object, java.io.File)]] found, so Seq[(Object, java.io.File)] cannot be appended to Seq[protocbridge.Target]
    Compile / PB.targets ++= Seq(
omidb commented 1 year ago

Adding type parameters seems solve the issue but creates different issues:

++= Seq[Target](

Now we have duplications

X is already defined as case class X
thesamet commented 1 year ago

Can you try removing the scalapb.gen line? Sounds like the case classes are generated twice.

On Mon, Aug 14, 2023 at 12:33 PM Omid Bakhshandeh @.***> wrote:

Adding type parameters seems solve the issue but creates different issues:

++= Seq[Target](

Now we have duplications

X is already defined as case class X

— Reply to this email directly, view it on GitHub https://github.com/scalapb/zio-grpc/issues/541#issuecomment-1677942836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLBLPMHQ5EPKGLDMVDXM3XVJ4PPANCNFSM6AAAAAA3QC5G2Q . You are receiving this because you were mentioned.Message ID: @.***>

-- -Nadav

omidb commented 1 year ago

If I remove that then ZIO gRPC will be unhappy:

ZioXService.scala:317:105: object XServiceGrpc is not a member of package com.Y.X_service
[error]           }(scalapb.zio_grpc.ClientCallContext(com.Y.X_sServiceGrpc.METHOD_Z, io.grpc.CallOptions.DEFAULT, metadata))
thesamet commented 1 year ago

Got it. Can you prepare a minimal repo on github reproducing this problem and post it here?

On Mon, Aug 14, 2023 at 12:49 PM Omid Bakhshandeh @.***> wrote:

If I remove that then ZIO gRPC will be unhappy:

ZioXService.scala:317:105: object XServiceGrpc is not a member of package com.Y.X_service [error] }(scalapb.zio_grpc.ClientCallContext(com.Y.X_sServiceGrpc.METHOD_Z, io.grpc.CallOptions.DEFAULT, metadata))

— Reply to this email directly, view it on GitHub https://github.com/scalapb/zio-grpc/issues/541#issuecomment-1677963788, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLBLINNRRHK2XSRRY2JW3XVJ6L5ANCNFSM6AAAAAA3QC5G2Q . You are receiving this because you were mentioned.Message ID: @.***>

-- -Nadav

omidb commented 1 year ago

@thesamet https://github.com/omidb/testgrpc

thesamet commented 1 year ago

Thanks for posting. Can you ensure the example in the repo is minimal - there are a lot of dependencies there that may or may not be part of the problem - please leave only the dependencies necessary to demonstrate the problem. Also, it looks like the project directory is missing.

On Mon, Aug 14, 2023 at 1:41 PM Omid Bakhshandeh @.***> wrote:

@thesamet https://github.com/thesamet https://github.com/omidb/testgrpc

— Reply to this email directly, view it on GitHub https://github.com/scalapb/zio-grpc/issues/541#issuecomment-1678029268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLBLJGW3CKA4RFY5L4S5DXVKEQHANCNFSM6AAAAAA3QC5G2Q . You are receiving this because you were mentioned.Message ID: @.***>

-- -Nadav

omidb commented 1 year ago

@thesamet oops missed that. Cleaned it, it just have the Akka dependencies. let me know if you need any other changes

thesamet commented 1 year ago

It looks like the Akka plugin doesn't invoke scalapb.gen with the grpc option so the method descriptors needed by zio-grpc are not there. This can be fixed by adding the following settings to the protos project in build.sbt:

akkaGrpcCodeGeneratorSettings += "grpc",
omidb commented 1 year ago

@thesamet thanks, it solves it.