what the recommended way is to integrate C++ (or o...
# kotlin-toolchain
v
what the recommended way is to integrate C++ (or other native code, such as Rust) into a project using Kotlin Toolchain
a
Hi, I don't think there is anything like the recommended way yet formed, meanwhile, take a look at local plugins
Meanwhile, could you please describe what you're doing and how exactly you want to integrate native code into Kotlin code (or vice versa)? maybe we could help you there
v
I want to create my own version of this library but use the C++ backend, currently it uses gradle for building, I want to use Kotlin Toolchain.
a
Thanks for the repo link, I'll take a look But after my glance overview, I'd say the recommendation is the same, take a look at local plugins
v
I’ll try local plugins.
I explored local plugins, but it looks like there’s currently no way to register C++ sources or native libraries as generated outputs and integrate them into the build. While a local plugin might be able to invoke a C++ compiler, I don’t see a way to make its outputs first-class build artifacts that can be consumed by the Kotlin JVM/Android targets. Is there any template or example approach for integrating native code?
a
I don’t see a way to make its outputs first-class build artifacts that can be consumed by the Kotlin JVM/Android targets
You’re right, it’s impossible so far cc @Fedor Ihnatkevich
f
So, yeah, writing a plugin that invokes the native compiler and ultimately produces a native library is possible, but currently there is no dedicated extension point (e.g.
generated.*
) to plug it back to the build. One could mention just adding it as a
generated.resources
but that would only really work on desktop JVM given runtime extraction extra step. I guess we could explore adding proper support to contribute a native library to the build in a plugin, yes. There are similar requests like Android-specific solution youtrack.jetbrains.com/issue/KTC-5937. I think right here we are talking about the KMP-library with platform-specific native libraries, let’s create a tracking issue for that.
👍 1