Allow linking static libraries from klibs.
Resolve static libraries in cinterop tool.
This commit is contained in:
committed by
alexander-gorshenev
parent
eb0d02715c
commit
eb0e584cb4
+18
@@ -337,6 +337,21 @@ private fun selectNativeLanguage(config: Properties): Language {
|
||||
error("Unexpected language '$language'. Possible values are: ${languages.keys.joinToString { "'$it'" }}")
|
||||
}
|
||||
|
||||
private fun resolveLibraries(staticLibraries: List<String>, libraryPaths: List<String>) {
|
||||
val result = mutableListOf<String>()
|
||||
println("libs = $staticLibraries")
|
||||
println("paths = $libraryPaths")
|
||||
staticLibraries.forEach { library ->
|
||||
libraryPaths.forEach forEachPath@ { path ->
|
||||
val combined = "$path/$library"
|
||||
if (File(combined).exists()) {
|
||||
result.add(combined)
|
||||
return@forEachPath
|
||||
}
|
||||
}
|
||||
}
|
||||
println("result = $result")
|
||||
}
|
||||
|
||||
private fun processLib(konanHome: String,
|
||||
substitutions: Map<String, String>,
|
||||
@@ -403,6 +418,9 @@ private fun processLib(konanHome: String,
|
||||
config.getSpaceSeparated("linkerOpts").toTypedArray() + defaultOpts + additionalLinkerOpts
|
||||
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
|
||||
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
|
||||
val staticLibraries = config.getSpaceSeparated("staticLibraries") + args["staticLibrary"].orEmpty()
|
||||
val libraryPath = args["-libraryPath"]
|
||||
val resolvedStaticLibraries = resolveLibraries(staticLibraries, libraryPath.orEmpty())
|
||||
|
||||
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
|
||||
it.split('.')
|
||||
|
||||
+25
-3
@@ -54,6 +54,15 @@ internal abstract class PlatformFlags(val properties: KonanProperties) {
|
||||
= properties.targetString(name)!!
|
||||
protected fun propertyTargetList(name: String)
|
||||
= properties.targetList(name)
|
||||
|
||||
abstract fun filterStaticLibraries(binaries: List<String>): List<String>
|
||||
|
||||
open fun linkStaticLibraries(binaries: List<String>): List<String> {
|
||||
val libraries = filterStaticLibraries(binaries)
|
||||
// Let's just pass them as absolute paths
|
||||
return libraries
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +74,9 @@ internal open class AndroidPlatform(distribution: Distribution)
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = true
|
||||
|
||||
override fun filterStaticLibraries(binaries: List<String>)
|
||||
= binaries.filter { it.isUnixStaticLib }
|
||||
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
return mutableListOf(clang).apply{
|
||||
add("-o")
|
||||
@@ -93,6 +105,9 @@ internal open class MacOSBasedPlatform(distribution: Distribution)
|
||||
propertyTargetString("osVersionMin") + ".0")
|
||||
}
|
||||
|
||||
override fun filterStaticLibraries(binaries: List<String>)
|
||||
= binaries.filter { it.isUnixStaticLib }
|
||||
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
return mutableListOf(linker).apply {
|
||||
add("-demangle")
|
||||
@@ -124,6 +139,9 @@ internal open class LinuxBasedPlatform(distribution: Distribution)
|
||||
private val specificLibs
|
||||
= propertyTargetList("abiSpecificLibraries").map{it -> "-L${targetSysRoot}/$it"}
|
||||
|
||||
override fun filterStaticLibraries(binaries: List<String>)
|
||||
= binaries.filter { it.isUnixStaticLib }
|
||||
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
// TODO: Can we extract more to the konan.properties?
|
||||
return mutableListOf(linker).apply {
|
||||
@@ -157,6 +175,9 @@ internal open class MingwPlatform(distribution: Distribution)
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = true
|
||||
|
||||
override fun filterStaticLibraries(binaries: List<String>)
|
||||
= binaries.filter { it.isWindowsStaticLib || it.isUnixStaticLib }
|
||||
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
return mutableListOf(linker).apply {
|
||||
addAll(listOf("-o", executable))
|
||||
@@ -176,6 +197,9 @@ internal open class WasmPlatform(distribution: Distribution)
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = false
|
||||
|
||||
override fun filterStaticLibraries(binaries: List<String>)
|
||||
= emptyList<String>()
|
||||
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
|
||||
//No link stage for WASM yet, just give '.wasm' as output.
|
||||
@@ -300,6 +324,7 @@ internal class LinkStage(val context: Context) {
|
||||
asLinkerArgs(config.getNotNull(KonanConfigKeys.LINKER_ARGS)) +
|
||||
entryPointSelector +
|
||||
platform.linkCommandSuffix() +
|
||||
platform.linkStaticLibraries(includedBinaries) +
|
||||
libraryProvidedLinkerFlags
|
||||
|
||||
try {
|
||||
@@ -319,9 +344,6 @@ internal class LinkStage(val context: Context) {
|
||||
return executable
|
||||
}
|
||||
|
||||
private val String.isJavaScript
|
||||
get() = this.endsWith(".js")
|
||||
|
||||
private fun JavaScriptLinker(jsFiles: List<String>, executable: String): String {
|
||||
val linkedJavaScript = File("$executable.js")
|
||||
linkedJavaScript.writeBytes(ByteArray(0));
|
||||
|
||||
-1
@@ -85,7 +85,6 @@ class LibraryWriterImpl(override val libDir: File, currentAbiVersion: Int,
|
||||
override fun addManifestAddend(path: String) {
|
||||
val properties = File(path).loadProperties()
|
||||
manifestProperties.putAll(properties)
|
||||
println("manifest addend: ${properties.stringPropertyNames().joinToString(" ")}")
|
||||
}
|
||||
|
||||
override fun addEscapeAnalysis(escapeAnalysis: ByteArray) {
|
||||
|
||||
Reference in New Issue
Block a user