cinterop configuration (?) problem I think This c...
# kotlin-native
r
cinterop configuration (?) problem I think This commit broke my build https://github.com/bugsnag/bugsnag-cocoa/commit/82fee49fdeb0b46a9855e1fd8f2344f8c03fc0f4 It basically changes all imports from something like
#import "BugsnagApp.h"
to something like
#import <Bugsnag/BugsnagApp.h>
Error:
Copy code
Exception in thread "main" java.lang.Error: /[…]/Carthage/Build/iOS/Bugsnag.framework/Headers/Bugsnag.h:28:9: fatal error: 'Bugsnag/BugsnagApp.h' file not found
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:1003)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:992)
	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:267)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
	at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
My def file:
Copy code
depends = Foundation
package = framework.Bugsnag
language = Objective-C
headers = Bugsnag.h

compilerOpts = -framework Bugsnag
linkerOpts = -framework Bugsnag
Gradle cinterop configuration:
Copy code
compilations.getByName("main").cinterops.create("Bugsnag") {
            defFile("src/iosMain/cinterop/Bugsnag.def")
            includeDirs.allHeaders("$projectDir/Carthage/Build/iOS/Bugsnag.framework/Headers")
        }
What can I do to make cinterop work with that commit’s change?
@Artyom Degtyarev [JB] any idea?
🙏 1
a
Currently looking at it. How do the
Headers
folder contents look like, the same as at the https://github.com/bugsnag/bugsnag-cocoa/tree/master/Bugsnag/include/Bugsnag?
r
It looks like it
message has been deleted
a
As far as I can see, one should go with
modules
instead of
headers
here. Can’t construct working example on my own, but I would guess it should look somehow similar to K/N platform libraries .defs(e.g. https://github.com/JetBrains/kotlin-native/blob/master/platformLibs/src/platform/osx/AppKit.def)
r
I changed my cinterop configuration to this:
Copy code
targets.withType<KotlinNativeTarget> {
        compilations.getByName("main").cinterops.create("Bugsnag") {
            defFile("src/iosMain/cinterop/Bugsnag.def")
            includeDirs.allHeaders(
                "${project.carthageBuildDir}/Bugsnag.framework/Headers",
                "${project.carthageBuildDir}/Bugsnag.framework/Modules"
            )
        }
    }
And my def file to this:
Copy code
depends = Foundation
package = framework.Bugsnag
language = Objective-C
modules = Bugsnag

compilerOpts = -framework Bugsnag
linkerOpts = -framework Bugsnag
And I get this error:
Copy code
Exception in thread "main" java.lang.Error: /var/folders/6l/fxc2038542q1pfrjs6br35pw0000gn/T/7677652267403620526.m:1:9: fatal error: could not build module 'Bugsnag'
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
	at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
	at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
	at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
🙏 1
a
I got stuck with
Task :compileKotlinIos FAILED
, but on a simpler example everything worked fine. I’ve made the following: 1. added path to the framework, set as a compiler option under -F flag 2. changed include path to point onto the framework too. For the example you shared, I’ve tried to do it as
Copy code
compilations.getByName("main").cinterops.create("Bugsnag") {
            defFile("src/iosMain/cinterop/Bugsnag.def")
            //includeDirs(
             //   "$projectDir/carthage/Carthage/Build/iOS/Bugsnag.framework/Headers",
               // "$projectDir/carthage/Carthage/Build/iOS/Bugsnag.framework/Modules"
            //)
            compilerOpts("-F$projectDir/carthage/Carthage/Build/iOS/","-I$projectDir/carthage/Carthage/Build/iOS/")
        }
Please give it a try, and tell if this would work any better.
r
Thanks, it seem to work in the real project!
🎉 1