Pass the list of static libraries from the cinterop tool to the compiler.
This commit is contained in:
committed by
alexander-gorshenev
parent
eb0e584cb4
commit
820a009163
+17
-10
@@ -23,14 +23,16 @@ import java.lang.IllegalArgumentException
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.reflect.KFunction
|
import kotlin.reflect.KFunction
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) = interop(args, null)
|
||||||
|
|
||||||
|
fun interop(args: Array<String>, argsToCompiler: MutableList<String>? = null) {
|
||||||
val konanHome = File(System.getProperty("konan.home")).absolutePath
|
val konanHome = File(System.getProperty("konan.home")).absolutePath
|
||||||
|
|
||||||
val substitutions = mapOf(
|
val substitutions = mapOf(
|
||||||
"arch" to (System.getenv("TARGET_ARCH") ?: "x86-64"),
|
"arch" to (System.getenv("TARGET_ARCH") ?: "x86-64"),
|
||||||
"os" to (System.getenv("TARGET_OS") ?: host)
|
"os" to (System.getenv("TARGET_OS") ?: host)
|
||||||
)
|
)
|
||||||
processLib(konanHome, substitutions, parseArgs(args))
|
processLib(konanHome, substitutions, parseArgs(args), argsToCompiler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options, whose values are space-separated and can be escaped.
|
// Options, whose values are space-separated and can be escaped.
|
||||||
@@ -337,10 +339,8 @@ private fun selectNativeLanguage(config: Properties): Language {
|
|||||||
error("Unexpected language '$language'. Possible values are: ${languages.keys.joinToString { "'$it'" }}")
|
error("Unexpected language '$language'. Possible values are: ${languages.keys.joinToString { "'$it'" }}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveLibraries(staticLibraries: List<String>, libraryPaths: List<String>) {
|
private fun resolveLibraries(staticLibraries: List<String>, libraryPaths: List<String>): List<String> {
|
||||||
val result = mutableListOf<String>()
|
val result = mutableListOf<String>()
|
||||||
println("libs = $staticLibraries")
|
|
||||||
println("paths = $libraryPaths")
|
|
||||||
staticLibraries.forEach { library ->
|
staticLibraries.forEach { library ->
|
||||||
libraryPaths.forEach forEachPath@ { path ->
|
libraryPaths.forEach forEachPath@ { path ->
|
||||||
val combined = "$path/$library"
|
val combined = "$path/$library"
|
||||||
@@ -350,12 +350,19 @@ private fun resolveLibraries(staticLibraries: List<String>, libraryPaths: List<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("result = $result")
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun argsToCompiler(staticLibraries: List<String>, libraryPaths: List<String>): List<String> {
|
||||||
|
return resolveLibraries(staticLibraries, libraryPaths)
|
||||||
|
.map { it -> listOf("-includeBinary", it) } .flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processLib(konanHome: String,
|
private fun processLib(konanHome: String,
|
||||||
substitutions: Map<String, String>,
|
substitutions: Map<String, String>,
|
||||||
args: Map<String, List<String>>) {
|
args: Map<String, List<String>>,
|
||||||
|
argsToCompiler: MutableList<String>?) {
|
||||||
|
|
||||||
val userDir = System.getProperty("user.dir")
|
val userDir = System.getProperty("user.dir")
|
||||||
val ktGenRoot = args["-generated"]?.single() ?: userDir
|
val ktGenRoot = args["-generated"]?.single() ?: userDir
|
||||||
@@ -418,9 +425,9 @@ private fun processLib(konanHome: String,
|
|||||||
config.getSpaceSeparated("linkerOpts").toTypedArray() + defaultOpts + additionalLinkerOpts
|
config.getSpaceSeparated("linkerOpts").toTypedArray() + defaultOpts + additionalLinkerOpts
|
||||||
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
|
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
|
||||||
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
|
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
|
||||||
val staticLibraries = config.getSpaceSeparated("staticLibraries") + args["staticLibrary"].orEmpty()
|
val staticLibraries = config.getSpaceSeparated("staticLibraries") + args["-staticLibrary"].orEmpty()
|
||||||
val libraryPath = args["-libraryPath"]
|
val libraryPaths = args["-libraryPath"].orEmpty()
|
||||||
val resolvedStaticLibraries = resolveLibraries(staticLibraries, libraryPath.orEmpty())
|
argsToCompiler ?. let { it.addAll(argsToCompiler(staticLibraries, libraryPaths)) }
|
||||||
|
|
||||||
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
|
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
|
||||||
it.split('.')
|
it.split('.')
|
||||||
|
|||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
|
|
||||||
|
val String.isJavaScript
|
||||||
|
get() = this.endsWith(".js")
|
||||||
|
|
||||||
|
val String.isUnixStaticLib
|
||||||
|
get() = this.endsWith(".a")
|
||||||
|
|
||||||
|
val String.isWindowsStaticLib
|
||||||
|
get() = this.endsWith(".lib")
|
||||||
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.cli.utilities
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
import org.jetbrains.kotlin.cli.bc.main as konancMain
|
import org.jetbrains.kotlin.cli.bc.main as konancMain
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.main as cinteropMain
|
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
||||||
import org.jetbrains.kotlin.cli.klib.main as klibMain
|
import org.jetbrains.kotlin.cli.klib.main as klibMain
|
||||||
|
|
||||||
fun invokeCinterop(args: Array<String>) {
|
fun invokeCinterop(args: Array<String>) {
|
||||||
@@ -29,7 +29,8 @@ fun invokeCinterop(args: Array<String>) {
|
|||||||
"-flavor", "native")
|
"-flavor", "native")
|
||||||
|
|
||||||
val cinteropArgs = (additionalArgs + args.toList()).toTypedArray()
|
val cinteropArgs = (additionalArgs + args.toList()).toTypedArray()
|
||||||
cinteropMain(cinteropArgs)
|
val cinteropArgsToCompiler = mutableListOf<String>()
|
||||||
|
interop(cinteropArgs, cinteropArgsToCompiler)
|
||||||
|
|
||||||
val konancArgs = arrayOf(
|
val konancArgs = arrayOf(
|
||||||
generatedDir.path,
|
generatedDir.path,
|
||||||
@@ -38,7 +39,7 @@ fun invokeCinterop(args: Array<String>) {
|
|||||||
"-o", outputFileName,
|
"-o", outputFileName,
|
||||||
"-target", target,
|
"-target", target,
|
||||||
"-manifest", manifest.path
|
"-manifest", manifest.path
|
||||||
)
|
) + cinteropArgsToCompiler
|
||||||
konancMain(konancArgs)
|
konancMain(konancArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user