clikt icon indicating copy to clipboard operation
clikt copied to clipboard

Kotlin Native build cache not working witch Clikt

Open Jeansen opened this issue 6 months ago • 9 comments

I cannot build t without setting kotlin.native.cacheKind.linuxX64=none. Otherwise I get errors like the following:

e: /home/marcel/.konan/dependencies/llvm-16.0.0-x86_64-linux-essentials-80/bin/ld.lld invocation reported errors Please try to disable compiler caches and rerun the build. To disable compiler caches, add the following line to the gradle.properties file in the project's root directory:

kotlin.native.cacheKind.linuxX64=none
Also, consider filing an issue with full Gradle log here: https://kotl.in/issue
The /home/marcel/.konan/dependencies/llvm-16.0.0-x86_64-linux-essentials-80/bin/ld.lld command returned non-zero exit code: 1.
output:
ld.lld: error: duplicate symbol: kfun:com.github.ajalt.clikt.core#selfAndAncestors__at__com.github.ajalt.clikt.core.Context(){}kotlin.sequences.Sequence<com.github.ajalt.clikt.core.Context>
>>> defined at Context.kt:0 (/home/runner/work/clikt/clikt/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/Context.kt:0)
>>>            libclikt:clikt-cache.a.o:(kfun:com.github.ajalt.clikt.core#selfAndAncestors__at__com.github.ajalt.clikt.core.Context(){}kotlin.sequences.Sequence<com.github.ajalt.clikt.core.Context>) in archive /home/marcel/.konan/kotlin-native-prebuilt-linux-x86_64-2.1.21/klib/cache/linux_x64-gSTATIC-pl/clikt:clikt/2kl1yhs57l8hi.27dt4c2kmz6t1/clikt:clikt-cache/bin/libclikt:clikt-cache.a
>>> defined at MordantContext.kt:0 (/home/runner/work/clikt/clikt/clikt-mordant/src/commonMain/kotlin/com/github/ajalt/clikt/core/MordantContext.kt:0)
>>>            libclikt:clikt-mordant-cache.a.o:(.text.kfun:com.github.ajalt.clikt.core#selfAndAncestors__at__com.github.ajalt.clikt.core.Context(){}kotlin.sequences.Sequence<com.github.ajalt.clikt.core.Context>+0x0) in archive /home/marcel/.konan/kotlin-native-prebuilt-linux-x86_64-2.1.21/klib/cache/linux_x64-gSTATIC-pl/clikt:clikt-mordant/1t87yb9uusrck.2i5cj6zx0ov5n/clikt:clikt-mordant-cache/bin/libclikt:clikt-mordant-cache.a

So I wonder, if there is anything additional/special I have to set in the build configuration with Gradle? The above directive makes re-compiling ultra slow ;-(

Jeansen avatar Jun 08 '25 17:06 Jeansen

Well, this is a bug in Kotlin/Native, so you might want to file a YouTrack issue. But I imagine we can work around it by renaming one of those functions.

ajalt avatar Jun 09 '25 16:06 ajalt

@ajalt Oh..I see. Well, I'll file an issue then but I would appreciate the workaround, anyway.

Jeansen avatar Jun 09 '25 17:06 Jeansen

https://youtrack.jetbrains.com/issue/KMT-1222/Clikt-only-works-with-kotlin.native.cacheKind.linuxX64none

Jeansen avatar Jun 09 '25 18:06 Jeansen

I just want to start with KMP and Clikt, but recompiling takes so long... Is it problem with only one function? Could you please rename it? 🥺 As I see it is internal :)

sirekanian avatar Aug 03 '25 00:08 sirekanian

I've found a workaround that works for me, I just using clikt-core instead of clikt:

commonMainImplementation("com.github.ajalt.clikt:clikt-core:5.0.3")

And changed CliktCommand to CoreCliktCommand in my code. Hope it helps to someone.

sirekanian avatar Aug 03 '25 00:08 sirekanian

Oh, great! That works for me, too. At least for the debug builds. Release Builds take a lot longer, but that is expected since they are heavily optimized. But be aware, that you miss-out some functionalities with this, should you need them https://ajalt.github.io/clikt/advanced/#core-module .

Jeansen avatar Aug 03 '25 12:08 Jeansen

I wonder if there is any workaround this other than opting for the Core module only. For my use cases, I can't really give up on the features provided by Mordant.

gfreitash avatar Sep 04 '25 19:09 gfreitash

I wonder if there is any workaround this other than opting for the Core module only. For my use cases, I can't really give up on the features provided by Mordant.

Adding the --allow-multiple-definition flag to linkerOpts fixes the build with cache. This will pick the first definition the linker finds. This likely cause issues, but can be handy during development

gfreitash avatar Sep 08 '25 18:09 gfreitash

@gfreitash: Awsome! Works like a charm, even with other dependencies I have, like custom build Kubernetes lib, SSL etc ... Cannot find any issues, so far :-) Thanks for charing your find!

Jeansen avatar Sep 09 '25 19:09 Jeansen