Interoperability between kotlin-native and kotlin-jvm


In one of my current projects I have to implement two-sided interaction between JVM and native code. Basically, I have to use JNI or JNA and it requires a lot of work. Now, we have Kotlin native which have some great tools for interop with native code, so it would seem reasonable to create a kotlin-native bridge which will work as a wrapper for native library. The problem is that there seem to be no way to directly interface kotlin-native code with kotlin-jvm without explicit use of JNI. Such interface probably could be generated automatically since both kotlin-native and kotlin-jvm share the same type system. Also it would be good to have such mechanism for multi-platform support, since the situation when part of the code is native and part of the code is JVM is quite frequent.

Are there any plans to create such an interface?


Try cinterop -flavor=jvm


Sorry, but I do not understand, what should I try. I have not found any documentation for the option you mentioned.

While searching, I found another similar question on this forum.


There is no documentation - it used internally in K/N compiler for building stubs to interact with LLVM.
Compiler is in Kotlin/JVM, LLVM is native. Exactly what you want, if I understood correctly.


Indeed. But it will be very hard to do anything without at least a bit documentation. I will try to look through the sources. Thanks for suggestion.