Hi folks. Do you know if there's a way to commoniz...
# multiplatform
t
Hi folks. Do you know if there's a way to commonize a JVM library and a native one? Consider two KMP libraries, one is targeting
jvm()
and one is targeting all the iOS targets. Most of the classes in these two libraries have the same declarations, but weren't made as a single KMP library so there's no
commonMain
with
expect
declarations. We need to use these two from
commonMain
and I'm wondering if there's a way to commonize them without having to do it manually?
m
My understanding is the commonizer finds all declarations that are the same in all targets using a source set. So you don't need expect actual handling.
t
IIRC commonizer isn't run on different libraries between JVM and native, is it?
m
I'm not actually sure, but I believe it is.
r
I think JVM and Native commonization generally works. Compose uses it to share non-Android skiko code, and I've written helper functions that commonized as expected in a similar source-set. I don't know if it's officially supported or not (and I can remember a time a couple years back where it explicitly wasn't)
t
So I spent time digging through the Kotlin compiler and I don't think there's commonization for JVM at all. The
NativeKlibCommonize
commonizer task which is the one used for cinterop commonization for example works with
KonanTarget
type and that's only for Kotlin/Native targets.
r
oh I think I was missing the piece around having separate libraries on the platforms. Yeah I that only works across native afaik
Though maybe poke around compose and see if they're using any useful tricks for sharing stuff across the skia targets
t
I think they're using skiko, I'll check that
From a quick check they just implement different platforms separately. The main problem I'm trying to workaround is https://youtrack.jetbrains.com/issue/KT-73998/Enum-classes-generated-by-cinterop-dont-have-static-entries-property