Is there something like JavaCPP for Kotlin/Native?...
# kotlin-native
b
Is there something like JavaCPP for Kotlin/Native? i.e. a zero-configuration Gradle plugin or library which ships with prebuilt binaries for common libraries on common target architectures? What I'm thinking is something like this:
Copy code
plugins {
      kotlin("multiplatform")
      id("org.kotlin.commonlibs")
}

commonLibs {
     compile("opencv2")
}
And it downloads the appropriate
klib
containing all the dependencies, which can be linked against the generated stubs and called from Kotlin/Native code without any further configuration. With JavaCPP this is dead simple, you just add the Maven coordinates and can immediately call native libraries (bundled in the JAR) on any target architecture. https://github.com/bytedeco/javacpp-presets
n
Kotlin Native doesn't have anything similar to what your'e describing (zero configuration for third party libraries). Some common platform libraries are already built into Kotlin Native depending on the target platform, and just require importing the parts of the API that you want to use in a Kotlin Native library/program.
As a example these libraries are built in when using the linux_x64 target: - Iconv - Linux (yes Linux has its own standard API simple smile - https://en.wikipedia.org/wiki/Linux_kernel_interfaces#Linux_API ) - Posix - Zlib - Builtin (what is this library 😕)
👍 1
Tree view of external libraries in a Kotlin Native project.
b
I saw that Kotlin/Native had some presets, which made me wonder if it wouldn’t be possible to build and include other common native libraries. How difficult would it be to write a Gradle plugin which fetched prebuilt binaries for various targets and included them as external libraries in the manner described? Seems like it would simplify multiplatform development quite a bit.
g
You can publish such library now, just as MPP dependency to maven and use standard gradle dependencies
m
Currently it works only for C or ObjectiveC, and static linking. opencv is C++.
g
Ah, sorry, I missed that it’s C++
Isn’t you can prebuild C++ binaries and use C binding for interop?
m
AFAIK opencv C bindings were deprecated in 2010. But - it works in Python, and Python too supports only C - so should be possible somehow.
g
Yeah, not really in opencv, I’m talking about general approach, it’s fine to have prebuild C++ and C binding as dependency for K/N published to Maven. Right?
m
Well, yes - if interface is in C, implementation can use C++ But I don't see C interface to opencv.
And opencv too have dependencies - libjpeg, freetype, openblas, ... They should be packaged in same way. But in general - yes, nothing prevents someone from creating community-driven repository of that wrapper packages, and publish them to jcenter or maven central.
But I don't understand why
javacpp
didn't it in the same way - there should be reason for creating plugin?
b
I guess adding a dependency is even better. Only reason I proposed a Gradle Plugin was because if it were as easy as adding a dependency, I thought people would have already done so. Or maybe there are some platform-specific (e.g. 64/32-bit) steps required to statically link to the compiled binary that requires a Gradle plugin? But since it is possible in Java and Python, it should also be possible in K/N, right?
n
Copy code
"Currently it works only for C or ObjectiveC, and static linking."
Also works with Kotlin Native libraries that are packaged as a KLib, and published via the maven-publish Gradle plugin.
g
if it were as easy as adding a dependency
@breandan It’a already supported using Gradle dependencies management. So consume dependencies is ease, the hardest part is publishing, essentially configure build process and cinterop, but by itself is supported
👍 2
n
Breandan - Are you referring to cross-platform or multi-platform builds?