Compiler daemon (#3442)

This commit is contained in:
Nikolay Igotti
2019-10-14 18:44:27 +03:00
committed by GitHub
parent bb67a21df9
commit f578ce88f5
24 changed files with 246 additions and 140 deletions
@@ -4723,4 +4723,4 @@ private external fun kniBridge335(p0: NativePtr, p1: Int, p2: NativePtr): Unit
private external fun kniBridge336(p0: NativePtr): Int
private external fun kniBridge337(p0: NativePtr): Int
private external fun kniBridge338(p0: NativePtr): Int
private val loadLibrary = System.loadLibrary("clangstubs")
private val loadLibrary = loadKonanLibrary("clangstubs")
@@ -371,11 +371,7 @@ private class CEnumType(private val rawValueCType: CType<Any>) : CType<CEnum>(ra
private typealias FfiClosureImpl = LongConsumer
private typealias UserData = FfiClosureImpl
private fun loadCallbacksLibrary() {
System.loadLibrary("callbacks")
}
private val topLevelInitializer = loadCallbacksLibrary()
private val topLevelInitializer = loadKonanLibrary("callbacks")
/**
@@ -16,6 +16,10 @@
package kotlinx.cinterop
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
internal fun decodeFromUtf8(bytes: ByteArray) = String(bytes)
internal fun encodeToUtf8(str: String) = str.toByteArray()
@@ -82,4 +86,23 @@ inline fun <reified R : Number> Long.narrow(): R = when (R::class.java) {
inline fun <reified R : Number> Number.invalidNarrowing(): R {
throw Error("unable to narrow ${this.javaClass.simpleName} \"${this}\" to ${R::class.java.simpleName}")
}
fun loadKonanLibrary(name: String) {
try {
System.loadLibrary(name)
} catch (e: UnsatisfiedLinkError) {
val fullLibraryName = System.mapLibraryName(name)
val dir = "${System.getProperty("konan.home")}/konan/nativelib"
try {
System.load("$dir/$fullLibraryName")
} catch (e: UnsatisfiedLinkError) {
val tempDir = createTempDir(directory = File(dir)).absolutePath
Files.createLink(Paths.get(tempDir, fullLibraryName), Paths.get(dir, fullLibraryName))
// TODO: Does not work on Windows. May be use FILE_FLAG_DELETE_ON_CLOSE?
File(tempDir).deleteOnExit()
File("$tempDir/$fullLibraryName").deleteOnExit()
System.load("$tempDir/$fullLibraryName")
}
}
}
@@ -180,9 +180,8 @@ class StubIrTextEmitter(
emitKotlinFileHeader()
stubLines.forEach(out)
nativeBridges.kotlinLines.forEach(out)
if (context.platform == KotlinPlatform.JVM) {
out("private val loadLibrary = System.loadLibrary(\"${context.libName}\")")
}
if (context.platform == KotlinPlatform.JVM)
out("private val loadLibrary = loadKonanLibrary(\"${context.libName}\")")
}
}
private val printer = object : StubIrVisitor<StubContainer?, Unit> {