My cinterop task fails with: ```e: Could not find...
# kotlin-native
n
My cinterop task fails with:
Copy code
e: Could not find "library" in [/Users/natario/Projects/project/project-name, /Users/natario/.konan/klib, /Users/natario/.konan/kotlin-native-macos-1.3.72/klib/common, /Users/natario/.konan/kotlin-native-macos-1.3.72/klib/platform/android_arm64].
But nothing I have is called "library", does anyone have any hints? If I run the task with --info I can see the command that is failing (it's huge, but this should be the core part...
...kotlin-native.jar org.jetbrains.kotlin.cli.utilities.MainKt cinterop -o...
). None of the arguments to this is called "library", I just see some
-library <http://path.to|path.to>.klib
which are the libraries that are being cinterop-ed.
a
Hello! Can you please tell if the path to KLIB or it’s name contains something less trivial than latin letters and digits?
n
I wouldn't say so.
Copy code
-library /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend.klib -library /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend-cinterop-gles31.klib -library /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend-cinterop-nativewindowjni.klib -library /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend-cinterop-deepinference.klib
I have deleted these klibs and tried again. I get a different error of a
Cyclic dependency in library graph
which I can't figure out either. Anyway I have saved the old, broken klib files, in case you want me to inspect something about this "library" issue.
Trying to debug this circular dependency by trial and error (since the error does not help), I have removed one of the cinterop dependencies (let's say
foo
) to see what happens. Now I get the original error, but about
foo
instead of
library
.
Copy code
e: Could not find "foo" in [/Users/natario/Projects/project/project-name, /Users/natario/.konan/klib, /Users/natario/.konan/kotlin-native-macos-1.3.72/klib/common, /Users/natario/.konan/kotlin-native-macos-1.3.72/klib/platform/android_arm64].
I wouldn't want to clean the whole gradle project anytime I add or remove cinterop libs, it's a big project. Any help?
I think the two issues (Could not find + circular dependency) are related and due to something wrong in the plugin, especially because all of this used to work last week (in the mean time, I have gone from 1.3.71 to 1.3.72 and probably some other small changes).
Focusing on the single cinterop library called Gles31 case for simplicity... 1. Clean environment, run task cinteropGles31. klib/manifest is:
Copy code
unique_name=effects-backend-cinterop-gles31
depends=stdlib posix glesCommon
headers=GLES3/gl31.h
includedHeaders=7fb6d736b3e2a4036f279e654230f6cd04ddfb564f5505c39036316fe40c9e94 74bd108264d655196d60c0b35c37eed44f840a026a09bd71cb22f91547133505
metadata_version=1.0.0
interop=true
linkerOpts=-lGLESv3
compiler_version=1.3.71
abi_version=22
exportForwardDeclarations=cnames.structs.__GLsync
package=platform.gles31
ir_version=1.0.0
2. Run task cinteropGles31 again Note that this task should not even run! It should be UP-TO-DATE. However gradle says
Copy code
Task ':effects-backend:cinteropGles31AndroidNativeArm64' is not up-to-date because:
  Input property 'libraries' file /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend-cinterop-gles31.klib has been added.
So the klib file of this lib, which should be the output of the cinterop task I guess, is also marked as its input. I really don't know how this could happen. At this point klib/manifest has become:
Copy code
unique_name=effects-backend-cinterop-gles31
depends=stdlib posix glesCommon effects-backend-cinterop-gles31
headers=GLES3/gl31.h
includedHeaders=
metadata_version=1.0.0
interop=true
linkerOpts=-lGLESv3
compiler_version=1.3.71
abi_version=22
exportForwardDeclarations=
package=platform.gles31
ir_version=1.0.0
Note changes in
depends
and also
includeHeaders
and
exportForwardDeclarations
. 3. Run the cinteropGles31 task again Again the task should not run, but gradle notices that the klib files has changed, and since it's somehow an input of this task, it runs again. The outcome is a (legit) cyclic dependency error.
Copy code
java.lang.IllegalStateException: Cyclic dependency in library graph for: /Users/natario/Projects/DM/dm-effects/effects-backend/build/classes/kotlin/androidNativeArm64/main/effects-backend-cinterop-gles31
a
Thank you for the investigation, could you share a minimal repro with a YouTrack ticket? It seems I cannot reproduce it with an arbitrary .def & gradle script 🙁
n
Neither can I in a new project 😄 I must be doing something wrong, but nothing wrong wrt cinterop I think, It's just 1 line .def files. So cinterop is hiding the real error. Looking at 1.3.71 plugin source code that's not surprising, it has convoluted logic. For example filterOutPublishableInteropLibs, filterKlibsPassedToCompiler in
KotlinNativeTasks
.... Look suspicious, they might work for the general case but somehow broken for me. I can only tell you that I can workaround the problem by setting
cinterop.dependencyFiles = project("xyz")
, so that it is resolved to an empty collection. I don't know if I'm breaking something else though.
It's hard to share anything because project is large, and uses a custom gradle plugin in another repo, ... Also I have already spent a lot of time on this, so I'll go with the workaround for now. Thanks