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

Kotlin Multiplatform support #140

Open
kirillzh opened this issue Nov 1, 2023 · 5 comments
Open

Kotlin Multiplatform support #140

kirillzh opened this issue Nov 1, 2023 · 5 comments

Comments

@kirillzh
Copy link

kirillzh commented Nov 1, 2023

Are there any plans to make Connect a KMP friendly library? Personally interested in JVM, Android and iOS targets.

@pkwarren
Copy link
Contributor

pkwarren commented Nov 1, 2023

There are no current plans to migrate connect-kotlin to support other platforms but it sounds like a good idea.

If you have interest, perhaps starting with a proposal of how we'd migrate to KMP would help to understand the scope of work and also the long term maintenance impacts.

@kansson
Copy link

kansson commented Jan 23, 2025

Hi @pkwarren!
We could use kotlinx.serialization for serialization and Ktor for the network layer.

@jhump
Copy link
Member

jhump commented Jan 23, 2025

We could likely use Ktor as the network layer, either as an option alongside the existing OkHttp implementation or instead of it (since Ktor has its own OkHttp-based implementation for when the application is targeting Android or JVM).

But serialization is currently a tricky part. While the kotlinx.serialization stuff has some support for Protobuf, there is no official code generator that generates Kotlin classes with the relevant annotations. You'd have to hand-write the message types or use some other 3rd-party plugin, like https://github.com/Dogacel/kotlinx-protobuf-gen. I'm skeptical that we'd want to tie this repo to that 3rd-party one since we don't have much knowledge on the quality of that package and how well it will be maintained and supported in the future. But we certainly wouldn't want to prevent people from using it.

I've heard rumors that Google may be investigating a Kotlin solution that leverages KMP (vs the current code gen, which leans on the not-KMP-compliant JVM implementation of Protobuf). If that comes to pass, we would definitely make moves to support it.

For now, the serialization for Connect is actually pluggable: when you create a ProtocolClientConfig, you must give it a SerializationStrategy. So you could actually implement a custom strategy that uses kotlinx.serialization under the hood. The only trick might be to see what issues you encounter when trying to combine the connect-kotlin generated RPC stubs with the base message and enum types generated by the above-mentioned 3rd party kotlinx.serializable-compatible plugin.

In any event, a more near-term task could be to make sure that the "core" module in this repo is KMP-compatible. Ideally, it would not have anything that is JVM-specific -- anything JVM-specific belongs in concrete serialization and networking implementations (like the protobuf extensions and the okhttp networking client in this repo). That at least ensures that we could integrate with KMP-compatible serialization and networking implementations in the future.

@Dogacel
Copy link

Dogacel commented Feb 9, 2025

I'm skeptical that we'd want to tie this repo to that 3rd-party one since we don't have much knowledge on the quality of that package and how well it will be maintained and supported in the future. But we certainly wouldn't want to prevent people from using it.

Hi @jhump,

I am the writer of that library. I haven't been doing active development recently, however I welcome anyone to contribute and I am pretty open to keep working on it. I haven't focused on building new features such as editions support, because I haven't got any feedback regarding it. If there is a project/community that needs it, I can help with that.

I have well-documented the working and non-working features of the library. While developing this library I even found some bugs in kotlinx.serialization and documented them all, unfortunately they aren't all resolved yet.

Here is the limitations of the generator:

https://github.com/Dogacel/kotlinx-protobuf-gen?tab=readme-ov-file#known-issues

Almost all of them are related to the kotlinx.serialization bugs, here is the tracker for that,

Kotlin/kotlinx.serialization#2401 (comment)

For the stability of the library, you can check all the conformance tests I have created and decide yourself 🙂 : https://github.com/Dogacel/kotlinx-protobuf-gen/tree/main/testProtos

@jhump
Copy link
Member

jhump commented Feb 10, 2025

@Dogacel, thank you for chiming and providing all of that information! As I previously mentioned, this repo would ideally be usable with your code generator and kotlinx.serialization via providing an alternate extension module that provides an implementation of SerializationStrategy. Before we could even consider making such an extension a part of this repo, we first need to tackle any other non-KMP-client in the core module of this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants