Support interop modularity
* Add list of included headers into the manifest * Implement importing "foreign" type declarations * Implement forward declarations more natively in the compiler * Represent Objective-C categories as Kotlin extension methods and properties Also: * Do some refactoring in stub generation * Call bridges directly in stubs for Objective-C properties
This commit is contained in:
committed by
SvyatoslavScherbina
parent
82b2b76c09
commit
79455c5161
@@ -1,6 +1,9 @@
|
||||
package org.jetbrains.kotlin.cli.utilities
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.KonanLibrary
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.cli.bc.main as konancMain
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
||||
import org.jetbrains.kotlin.cli.klib.main as klibMain
|
||||
@@ -8,11 +11,16 @@ import org.jetbrains.kotlin.cli.klib.main as klibMain
|
||||
fun invokeCinterop(args: Array<String>) {
|
||||
var outputFileName = "nativelib"
|
||||
var target = "host"
|
||||
val libraries = mutableListOf<String>()
|
||||
for (i in args.indices) {
|
||||
if (args[i].startsWith("-o"))
|
||||
outputFileName = args.getOrElse(i+1){outputFileName}
|
||||
if (args[i] == "-target")
|
||||
target = args.getOrElse(i+1){target}
|
||||
val arg = args[i]
|
||||
val nextArg = args.getOrNull(i + 1)
|
||||
if (arg.startsWith("-o"))
|
||||
outputFileName = nextArg ?: outputFileName
|
||||
if (arg == "-target")
|
||||
target = nextArg ?: target
|
||||
if (arg == "-library")
|
||||
libraries.addIfNotNull(nextArg)
|
||||
}
|
||||
|
||||
val buildDir = File("$outputFileName-build")
|
||||
@@ -21,12 +29,23 @@ fun invokeCinterop(args: Array<String>) {
|
||||
val cstubsName ="cstubs"
|
||||
val manifest = File(buildDir, "manifest.properties")
|
||||
|
||||
val importArgs = libraries.flatMap {
|
||||
val library = KonanLibrary(File(it))
|
||||
val manifestProperties = library.manifestFile.loadProperties()
|
||||
// TODO: handle missing properties?
|
||||
val pkg = manifestProperties["pkg"] as String
|
||||
val headerIds = (manifestProperties["includedHeaders"] as String).split(' ')
|
||||
val arg = "$pkg:${headerIds.joinToString(",")}"
|
||||
listOf("-import", arg)
|
||||
}
|
||||
|
||||
val additionalArgs = listOf<String>(
|
||||
"-generated", generatedDir.path,
|
||||
"-natives", nativesDir.path,
|
||||
"-cstubsname", cstubsName,
|
||||
"-manifest", manifest.path,
|
||||
"-flavor", "native")
|
||||
"-flavor", "native"
|
||||
) + importArgs
|
||||
|
||||
val cinteropArgs = (additionalArgs + args.toList()).toTypedArray()
|
||||
val cinteropArgsToCompiler = mutableListOf<String>()
|
||||
@@ -39,7 +58,7 @@ fun invokeCinterop(args: Array<String>) {
|
||||
"-o", outputFileName,
|
||||
"-target", target,
|
||||
"-manifest", manifest.path
|
||||
) + cinteropArgsToCompiler
|
||||
) + cinteropArgsToCompiler + libraries.flatMap { listOf("-library", it) }
|
||||
konancMain(konancArgs)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user