Is there any place I can learn how to use `depends...
# kotlin-native
r
Is there any place I can learn how to use
depends
directive of
.def
file? I was skimming through the repo but didn't find any usage outside of default platform libs generation. Reasoning for the question: I'm trying to consume from Kotlin/Native two C libraries which depend on each other. Bindings for the first one are generated trivially, but I'm unable to inform
cinterop
that for types and functions from the first library there should be imports with first lib wrapper's namespace instead of duplicated bridges.
s
depends
property value should contain space-separated list of library names. This names are resolved as described in the documentation: https://github.com/JetBrains/kotlin-native/blob/master/LIBRARIES.md#library-search-sequence
r
And
cinterop
uses this property only to add these to final
.klib
dependencies, but not to actually emit any stubs code? For example,
platform.linux
depends on
platform.posix
and there is, for example, the following function:
kfun:platform.linux.inet_makeaddr(<http://kotlin.Int;kotlin.Int|kotlin.Int;kotlin.Int>)kotlinx.cinterop.CValue<platform.posix.in_addr>
. So function from
platform.linux
contains reference to type from
platform.posix
. I'm trying to achieve the same thing, but for me
cinterop
for the second library generates all the types for the second time under new package instead of referencing them from the first
klib
. I've enumerated all the headers of the second library in
headerFilter
and mentioned the first one in
depends
, but it's not working for me, unfortunately.
Here's what I'm trying to do in a nutshell. https://gist.github.com/r4zzz4k/3d3ac8b6ace1743fb2bc1db23785e0a2 Prerequisites: Linux,
apt install libglib2.0-dev libgirepository1.0-dev
. Resulting `gir_interop-build/manifest.properties`contains proper
depends=
field, everything else seems okay there, but both
gobj_interop-build/kotlin/sample/gobj/cinterop/cinterop.kt
and
gir_interop-build/kotlin/sample/gir/cinterop/cinterop.kt
contain their own definition of
class _GObject(rawPtr: NativePtr) : CStructVar(rawPtr) {
under corresponding packages, when I'm trying to achieve one class as
sample.gobj.cinterop._GObject
and for second library
import sample.gir.cinterop.*
or something along those lines instead.
m
Maybe something like
-library gobj
option needed for second
cinterop
r
@msink, you're life saver. I don't even know why I didn't try that as
platformLibs/build.gradle
clearly does take
depends
from
DefFile
and passes it as
libraries
to
interop
configuration. Thank you, it works!
Though it seems kind of logical to do that by cinterop itself than by external Gradle task -- I'm not sure I see any use-cases when klib should depend on another one but shouldn't use it's contents. Should I file an issue against kotlin-native repo for you to consider this, @svyatoslav.scherbina?
s
@msink yes, you are right. @r4zzz4k sorry for giving you wrong advice. With passing
-library
options to
cinterop
it doesn’t seem necessary to add
depends =
to
.def
file.
Though it seems kind of logical to do that by cinterop itself than by external Gradle task
What do you mean?
cinterop
itself supports dependencies between C libraries through
-library
option.
r
Oh, I didn't check if
depends
is necessary in presence of
-library
. So let me ask another question: what are use cases for having
depends
field without
-library
flag? If I understand correctly, it would create dependency without providing any actual communication between libraries.
Giving another thought, this can probably be useful for having some plugin system. E.g., there are: •
plugin-base
with registration and plugin API functions •
plugin-a
with
-library plugin-base
app
with
-library plugin-base
and
depends plugin-a
for statically embedding it into the final artifact. This way
app
does use actual plugin, but via common dependency. So disregard that, it's perfectly fine to have it the way you do, it was just my misunderstanding.
s
what are use cases for having
depends
field without
-library
flag?
Currently
depends
is for internal use only, e.g. to prepare platform libs.
r
I see, thanks.