Kotlin / kotlinx-rpc

Add asynchronous RPC services to your multiplatform applications.
https://kotlin.github.io/kotlinx-rpc/
Apache License 2.0
514 stars 7 forks source link

Duplicate generation of code #121

Closed ShayOinif closed 3 days ago

ShayOinif commented 3 days ago

Hello. One thing I noticed only recently is that you generate in a kmp, shared module, which uses only, let's say - krpc-core, the client for each target. Is this code really specific to each target? Couldn't it be generated in common source set and some expect/actual for platform specific in platform specific source set? I feel like this is a bit redundant and results in a bigger and longer build. For your notice, Thanks.

Mr3zee commented 3 days ago

Hello! This is how compiler plugins work now, they don't have a common target, and compilation runs for each final target only. So also no Native compilation, but rather iosX64, iosArm64, etc. It is the same for every other compiler plugin, like serialization

This may change in the future with universal klibs, there was a good talk at kotlin conf about it: https://kotlinconf.com/talks/582224/

ShayOinif commented 3 days ago

OK, cool, good to know. So just for further knowledge: If I write a plugin that compiles from external sources/input like proto - which is usually in predefined path or given as an input for the plugin - I can check the current project and if it is kmp then add to common source set (which I do in a side project of mine). But if I create a compiler plugin then it automatically puts generated code for each declared target in its own source set?

Mr3zee commented 2 days ago

Yeah, that is mostly true. The only note - the reason this happens with the compiler plugins is because a compiler itself compiles code right to a target platform, so a compiler plugin just able to transform some intermediate representation of this code, it doesn't choose where to put the result, the compiler does

ShayOinif commented 22 hours ago

Hope it will change, or maybe there are some other considerations I am not aware of. Anyhow, played a bit with ksp and as you said they automatically put code for each target in right source set. But I don't like it, seems like a workaround of putting it in common main meta data and linking the src dir myself might do the trick for me. Or am I missing something with the generated/ksp/metadata/commonMain folder?