Is Kotlin native able to injest JVM class files at...
# kotlin-native
d
Is Kotlin native able to injest JVM class files at any level? For example so long as they only access specific packages and specific classes. Is there a .class file transformer that can rewrite into kotlin IR. Maybe kotlinc can compile java too? Is GraalVM the only option in the arena, where inclusion of JVM bytecode is a requirement, I have my command line tool building cross platform here and wanted to now get a Kotlin/native and then WASM/WASI edition of the same. There are however a number of options for class to WASM to explore but only one for kotlin native. Thanks
e
1. no. 2. there have been other projects such as GCJ and https://github.com/SimonKagstrom/cibyl from the distant past. have you considered just linking with a JVM if you need to load Java classes?
d
I'm familiar with GCJ and GNU classpath. So even a pure method in a .class can not have its bytecode transformed into kotlin IR ? To be clear my native binary does not need to process .class files at runtime, I want kotlin code to link with .class files at build time and interoperable. It would be better if LLVM can ingest the .class file and turn into LLVM IR in this case I think. Are we sure that it not already possible.
Kotlin native can only interop with C language linkage? Any other languages? Is there a way to write kotlin IR that knows how to manage C++ ? If I generate all the management code and annotate ownership and lifetimes, how to export kotlin IR so it cam be just linked ? I assume I also generate linkage stubs as well, for naming and signatures
I am familiar with JNI but am trying to breakdown the interop border. Is there an ASM library for kotlin IR ?
e
K/N only has C (and Objective-C on Apple platforms) interop. to use C++, you'll need C wrappers, same as most other languages
I don't think there's any API to work with Kotlin IR outside of the compiler
d
Thanks for your replies. Well JNI provides a DSO/DLL as entrypoint (its not really a C wrapper), with JVM linking directly, I am after the equivalent for kotlin IR happy to learn the syntax etc... maybe reverse engineer it
e
https://kotlinlang.org/docs/native-libraries.html note that (as usual with LLVM) bitcode is specific to each target
and also that the format is not stabilized and will definitely change in the future, although the compiler is backwards-compatible https://youtrack.jetbrains.com/issue/KT-52600
d
Thanks these links I shall research some more