I'm developing a Kotlin multiplatform library and ...
# multiplatform
a
I'm developing a Kotlin multiplatform library and I'd like to use it from programming languages that aren't directly supported by Kotlin (e.g. Python, Rust, Go, etc). Could you help me out? (See thread for details.)
I know it's possible to compile my project as a native library, and then call its functions from another language (as long as the language supports calling external C functions). This works, but results in an API that is very impractical to use, due to the differences between C and Kotlin (my library exposes functions, objects, enums, etc). The only realistic way forward is, IMO, to "reconstruct" the original Kotlin API in the new language (i.e., building a wrapper around the native library). This is cumbersome to do manually, so I'm looking for a way to automatically generate such a wrapper.
My current solution is a self-built gradle plugin that analyzes my library (using
kotlinx-metadata-jvm
), collects information about public functions and classes, and spews out a Python wrapper around the FFI bindings (with proper Python classes, string conversion, etc). Would you say this is the way forward? Or am I missing a simpler solution?
If there's anything better out there, I'd rather hear it before implementing support in my plugin for other languages 😅
By the way, it looks like
kotlinx-metadata-jvm
is unable to retrieve the original code's documentation (after all, docs aren't present in the compiled java class). What would you recommend as a way to obtain the documentation of every class and function?
t
z
I found this, which seems pretty neat https://github.com/gobley/gobley
a
@zt it looks like that tool is meant to embed Rust in Kotlin, but I need something that goes the other way around
@tapchicoma a friendly LLM suggested having a look at that repo too, but as far as I can gather from the short readme, it's not meant to create wrappers around a native kotlin library.
t
cc @sergey.bogolepov