For the latter I looked at skiko, but the only nat...
# kotlin-native
m
For the latter I looked at skiko, but the only native bindings available seem to be for macOS and not common native code.
g
So the Skiko thing is kind of weird, I also looked. Reached same conclusion. The only bit of Kotlin Native functionality available right now is hard-coded stuff for Mac OS. Also, the way it works, it calls the Jetbrains
skija
library which is Java, bound to some JNI code in C++. I didn't know Kotlin Native could even do this (import Java code that used JNI -- thought you could only use direct C bindings) EG,
class Canvas
,
Canvas.drawPicture()
https://github.com/JetBrains/skija/blob/64b715ceb0764e366eb98ff852d3c42fe30328ab/platform/cc/Canvas.cc#L147-L154https://github.com/JetBrains/skija/blob/64b715ceb0764e366eb98ff852d3c42fe30328ab/shared/java/Canvas.java#L448-L461 Then the
skiko
Kotlin Native code for drawing on canvas: • https://github.com/JetBrains/skiko/blob/023a169556129b0f68d236eac1c38d08d9741039/s[…]nativeMain/kotlin/org/jetbrains/skiko/context/ContextHandler.kt
Generally if you wanted to use something like Skia, you would: • Check if it has a C ABI (Skia does, but it's "experimental" and not meant for production use) ◦ https://github.com/google/skia/blob/main/experimental/c-api-example/c.md • If it doesn't, let's say it's C++ or Rust or whatnot, then you need to expose a C ABI for it ◦ (I mean, technically you don't -- you could use some naughty linker tricks and directly call mangled symbol names but let's pretend you can't do that, because you shouldn't) ◦ You can use something like
CPPBind
to generate a C ABI for C++, or
rust-bindgen
for generating a C ABI for Rust, etc ▪︎ https://github.com/Time0o/CPPBind ▪︎ https://github.com/rust-lang/rust-bindgen • Then you follow the
c-interop
guide for consuming the C ABI from Kotlin Native ◦ https://kotlinlang.org/docs/native-c-interop.html ◦ This amounts to basically linking in the static/shared library that exposes the C ABI, and running a tool to auto-generate the Kotlin type signatures for the C ABI headers
If you want to get Skia working with KN today, you can use the guide they have there on building the C ABI and use that, rather than the C++ API. But it would be stripped down.
The final step is to wait for the day when Kotlin gets direct C++ interop, the way that Swift does, as it has on it's native roadmap And then you can just consume symbols from C++ objects natively, courtesy of LLVM and a bunch of magic. None of this ABI nonsense \o/