apache / pekko-grpc

Apache Pekko gRPC
https://pekko.apache.org/
Apache License 2.0
37 stars 16 forks source link

Generate scala code compliant with `-Xsource:3` #307

Closed Christewart closed 1 month ago

Christewart commented 1 month ago

I'm attempting to update my grpc project to use the -Xsource:3

https://docs.scala-lang.org/scala3/guides/migration/tooling-scala2-xsource3.html

I can use -quickfix:any to re-write the generated scala code, however if I don't constantly keep -quickfix:any in the scalacOptions, the code will revert back to the non compliant -Xsource:3 after a clean

In bitcoin-s, the project that uses grpc is lndRpc. You can reproduce this by running lndRpc/compile

https://github.com/bitcoin-s/bitcoin-s/pull/5595

You can see the failures on CI here: https://github.com/bitcoin-s/bitcoin-s/actions/runs/9097285380/job/25004754803

pjfanning commented 1 month ago

We still support scala 2.12 so we will not be making scala3 style source the default. If someone finds a way to make this configurable - then we can go that route.

Christewart commented 1 month ago

We still support scala 2.12 so we will not be making scala3 style source the default. If someone finds a way to make this configurable - then we can go that route.

I think in my case, its literally just adding type annotations to the generated scala code

The non compliant -Xsource:3 code

//does not compile with `-Xsource:3`
lazy val values = scala.collection.immutable.Seq(LEGACY, ANCHOR)

what -quickfix:any rewrites it to

//compiles with -Xsource:3 because `values` has the type annotation
lazy val values: Seq[wtclientrpc.PolicyType.Recognized] = scala.collection.immutable.Seq(LEGACY, ANCHOR)

Now if I re-compile, removing the -quickfix:any compiler flag, I revert back to the first version with no type annotation on values

I know collections were redone in 2.13.x, does this mean this can't safely be done while still supporting 2.12.x?

pjfanning commented 1 month ago

@Christewart this is a volunteer project. Noone works full time on it. If you would like to try a solution, we will review any PRs.

pjfanning commented 1 month ago

pekko-grpc codegen is built on top of https://github.com/scalapb/ScalaPB and it is ScalaPB that generates the source for the lazy val values as far as I can see.

pjfanning commented 1 month ago

ScalaPB recently added https://github.com/scalapb/ScalaPB/commit/83b849f59764f527c2ecda4905e4e48d75bbb4b2

In the next few weeks, we should be releasing a 1.1.0-M1 version of pekko-grpc that uses the latest ScalaPB release

pjfanning commented 1 month ago

closing - as we already have https://github.com/apache/pekko-grpc/pull/222

pjfanning commented 1 month ago

https://pekko.apache.org/docs/pekko-grpc/current/buildtools/sbt.html#generating-server-

With Pekko-GRPC 1.1 snapshots or releases, you should be able to add this to your sbt file.

pekkoGrpcCodeGeneratorSettings += "scala3_sources"