Hey team! I am trying to generate code to do a dir...
# kotlin-native
d
Hey team! I am trying to generate code to do a direct binding (without cinterop) on Kotlin/Native (in the spirit of what @Oleg Yukhnevich did in its Kotlin Interop Playground, https://github.com/whyoleg/kotlin-interop-playground/). I need to access to Konan executable path (similarly to what is done here: https://github.com/whyoleg/kotlin-interop-playground/blob/677a6c1145112f2249b57c9b[…]f2/build-logic/src/main/kotlin/kipbuild/clang/ClangKonanTask.kt) but its seems the APIs have changed. I cannot figure out how to get it. Anyone knows?
For now, I did:
Copy code
// `UsesKotlinNativeBundleBuildService` and `KotlinNativeProvider` are `internal` KGP APIs
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
abstract class ClangKonanTask<T : ClangKonanTask<T>>(
    @get:Input val konanTarget: KonanTarget,
    taskType: KClass<T>
) : AbstractExecTask<T>(taskType.java), UsesKotlinNativeBundleBuildService {

    @get:OutputDirectory
    val outputDirectory: DirectoryProperty = objectFactory.directoryProperty().convention(
        project.layout.dir(
            project.provider {
                temporaryDirFactory.create()!!
            }
        )
    )

    protected abstract fun setup()

    final override fun exec() {
        val bundleService = kotlinNativeBundleBuildService.get()

        // recreate output directory
        outputDirectory.get().asFile.apply {
            deleteRecursively()
            mkdirs()
        }

        // clang will produce output into the current working directory
        workingDir(outputDirectory.get())

        // run clang vis K/N toolchain
        executable(bundleService.bundleDirectory.map { "${it.asFile.absolutePath}/bin/run_konan" })
        args("clang", "clang", konanTarget.name)

        setup()

        super.exec()
    }
}
But
bundleService.bundleDirectory
is not defined and I cannot figure out what is the new equivalent.
b
Usually konan & its dependencies are kept on the user home folder under . konan folder. I saw it in Windows, Linux and macOS systems. I don't think the location of these binaries will change. You can inspect your home folder for clarification. Of course, the konan has a bin folder. But, what is the bin folder - I don't know.
d
Well, the goal of my question is to obtain the K/N bundled tooling through K/N build APIs.
b
Ya, I got it. One possibility is: First Obtain a working sample. Obtain the source code of its kotlin native plugin version. Deep dive. Understand how it works (not entirely, we need to identify from where
bundleService.bundleDirectory
comes). You can simply lock that version in your code. Then everything works. But, that is not recommended. Especially in the case of KMP. You can use git to identify the changes on that source file. Then you can identify where
bundleService.bundleDirectory
goes (or what replaces that). You can act according to that. This always works. In my case, I am using kotlin EAP & ktor EAP plugins in most of my KMP projects. And also configured Renovate for dependency updation & GitHub actions (or Azure DevOps Pipelines) to build Renovate PRs. So, Renovate makes PRs whenever a new version is available for any of the dependencies - and there will be no documentation (most of the time). If building pipelines are happy, I simply merge them, otherwise I will deep dive to fix migration problems.
d
Nvm, it seems I figured it out. Adding this to my task did it:
Copy code
@get:Internal
    private val kotlinNativeProvider = chooseKotlinNativeProvider(
        enabledOnCurrenHost = true,
        konanTarget = konanTarget,
        project = project,
    )
Now
kotlinNativeProvider
has the
bundleDirectory
property.
👍 1