Hi again.. Perhaps more importantly... it seems li...
# ksp
r
Hi again.. Perhaps more importantly... it seems like KSP cannot generate common code. My library ideally works mostly on common code since it depends on compose multiplatform. The workaround would be for users of the library to have tons of manual expect actual declarations just to point to the generated classes/functions, because they need to reference to generated stuff from the common code. Isn't this a huge blocker for lots of use cases? What are my real options? I found https://github.com/google/ksp/issues/567 but it doesn't really help much, unless I'm missing something.
r
It can.
e
It could generate common code. You just need to set it up correctly. I'm not at computer so I can't describe it, but you can follow this to see how to set it up https://github.com/eygraber/gradle-conventions/blob/master/conventions-plugin/src/main/kotlin/ksp.kt#L32
r
r
Oh that’s really good news. Thanks guys! I’ll check these as soon as I can.
Hey @Robert Jaros and @eygraber 👋 I was still not able to check this, however, I was wondering.. while trying to compile the sample CMP app yesterday, I did find that I’d want to generate slightly different code depending on the target being compiled. For example, on Jvm targets, I’d want to use Keep annotations, and on native HideFromObjC. But if I’m generating to common, I assume that’s not possible? 🤔 Maybe I can add the HiddenFromObjC to common code, and the Keep I found some other way, like having users add some pro guard rules. But still, I’m curious how this works exactly..
r
In general you can use KSP to generate any kind of code you want, including different code for different targets. But first, you need to know, what code you need. To achieve what you ask, you can use common interfaces with platform dependent implementations, you can also use expect/actual functions or classes.
r
Yeah that makes sense. The answer to my thoughts is basically using other KMP patterns to have slightly different code in the end, while keeping common code the same. So yes, thinking more about it, my concern was not really valid, as long as I can have full control of what code is generated where, that will be awesome! Thank you again 👍
r
You might be also interested in reading this: https://github.com/google/ksp/issues/965