Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating kotlin bindings #270

Closed
tandel-pratik opened this issue Jun 17, 2021 · 5 comments
Closed

Support generating kotlin bindings #270

tandel-pratik opened this issue Jun 17, 2021 · 5 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@tandel-pratik
Copy link

Now that protocolbuffers/protobuf#3742 is resolved and the protoc can generate some Kotlin bindings, can we support this in grpc-kotlin as well?

@lowasser
Copy link
Collaborator

The intent is that choosing to use gRPC-Kotlin and choosing to use Kotlin protos should be completely independent, and it is -- you can use one or the other, or both.

@tandel-pratik
Copy link
Author

tandel-pratik commented Jul 14, 2021

My understanding is that grpc-kotlin generates the proto bindings as well for bazel anyway. There's a PR that fails to use the new bindings in bazel for instance: #266

I think this PR should fix it: #271

FWIW, we tried updating rules_proto to use the newer version but the kotlin DSL don't seem to be generated either.

@SanjayVas
Copy link

SanjayVas commented Aug 6, 2021

The Kotlin proto generated code effectively just adds a type-safe builder DSL to the Java protos. The current code generated by grpc-kotlin can accept proto messages built using this.

In terms of the Bazel rule implementation, the rule requires the caller to pass in a java_proto_library, meaning it's up to the caller to define a proto library target for each service. What #266 appears to be trying to do is update the examples in this repo to use the Kotlin proto DSL. I don't believe this would have any effect on the API that grpc-koltin exposes. It currently fails in the Bazel path because the Kotlin protos aren't included there. There are currently no Bazel rules for generating Kotlin protos. See bazelbuild/rules_kotlin#546.

@wfhartford
Copy link

wfhartford commented Oct 4, 2023

I'm working on generating some Kotlin to integrate grpc-kotlin more closely with the protobuf generated Kotlin DSL. For every (non-streaming) RPC, I would generate a function like the following:

suspend fun rpcMethodName(
  headers: Metadata = Metadata(),
  builder: RequestMessageKt.Dsl.() -> Unit
): ResponseMessage =
  rpcMethodName(requestMessage(block), headers)

This function allows a client to call the RPC building the request message in a less verbose form:

serviceStub.rpcMethodName {
  fieldOne = valueOne
  fieldTwo = valueTwo
}

Rather than the current syntax:

serviceStub.rpcMethodName(
  requestMessage {
    fieldOne = valueOne
    fieldTwo = valueTwo
  }
)

I've been using functions like this in my projects for quite a while and appreciate the less verbose calls. Would a pull request that introduces these function overloads have a chance of being accepted? These functions introduce a dependency on the protobuf generated Kotlin DSL.

@lowasser
Copy link
Collaborator

lowasser commented Oct 4, 2023

It is specifically intended that we do not have a dependency from gRPC-Kotlin to Kotlin protos, which is why things are the way they are today.

@lowasser lowasser closed this as completed Oct 4, 2023
@lowasser lowasser added the wontfix This will not be worked on label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants