[kotlin-native-plugin] Two fixes:
* Added property to select the cache kind (none, dynamic, static) * Fixed the check if the cache needs to be rebuilt
This commit is contained in:
+3
-2
@@ -20,6 +20,7 @@ import org.gradle.api.Named
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.KOTLIN_NATIVE_HOME
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
@@ -51,8 +52,8 @@ internal val Project.konanVersion: CompilerVersion
|
||||
internal val Project.disableKonanDaemon: Boolean
|
||||
get() = PropertiesProvider(this).nativeDisableCompilerDaemon == true
|
||||
|
||||
internal val Project.disableKonanCache: Boolean
|
||||
get() = PropertiesProvider(this).nativeDisableCompilerCache == true
|
||||
internal val Project.konanCacheKind: NativeCacheKind
|
||||
get() = PropertiesProvider(this).nativeCacheKind
|
||||
|
||||
internal interface KonanToolRunner : Named {
|
||||
val mainClass: String
|
||||
|
||||
+13
-4
@@ -24,11 +24,9 @@ import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
private const val KOTLIN_PROJECT_EXTENSION_NAME = "kotlin"
|
||||
@@ -129,3 +127,14 @@ enum class Coroutines {
|
||||
Coroutines.values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
|
||||
enum class NativeCacheKind(val produce: String?, val outputKind: CompilerOutputKind?) {
|
||||
NONE(null, null),
|
||||
DYNAMIC("dynamic_cache", CompilerOutputKind.DYNAMIC_CACHE),
|
||||
STATIC("static_cache", CompilerOutputKind.STATIC_CACHE);
|
||||
|
||||
companion object {
|
||||
fun byCompilerArgument(argument: String): NativeCacheKind? =
|
||||
NativeCacheKind.values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
@@ -147,10 +148,10 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
get() = booleanProperty("kotlin.native.disableCompilerDaemon")
|
||||
|
||||
/**
|
||||
* Forbids dependencies precompilation to dynamic/static libraries.
|
||||
* Dependencies caching strategy. The default is static.
|
||||
*/
|
||||
val nativeDisableCompilerCache: Boolean?
|
||||
get() = booleanProperty("kotlin.native.disableCompilerCache")
|
||||
val nativeCacheKind: NativeCacheKind
|
||||
get() = property("kotlin.native.cacheKind")?.let { NativeCacheKind.byCompilerArgument(it) } ?: NativeCacheKind.STATIC
|
||||
|
||||
/**
|
||||
* Generate kotlin/js external declarations from all .d.ts files found in npm modules
|
||||
|
||||
+17
-9
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.compilerRunner.konanVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
@@ -426,8 +427,8 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
get() = binary.baseName
|
||||
|
||||
@get:Input
|
||||
protected val disableKonanCache: Boolean
|
||||
get() = project.disableKonanCache
|
||||
protected val konanCacheKind: NativeCacheKind
|
||||
get() = project.konanCacheKind
|
||||
|
||||
inner class NativeLinkOptions: KotlinCommonToolOptions {
|
||||
override var allWarningsAsErrors: Boolean = false
|
||||
@@ -628,8 +629,8 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
private val debuggable: Boolean
|
||||
get() = binary.debuggable
|
||||
|
||||
private val disableKonanCache: Boolean
|
||||
get() = project.disableKonanCache
|
||||
private val konanCacheKind: NativeCacheKind
|
||||
get() = project.konanCacheKind
|
||||
|
||||
// Inputs and outputs
|
||||
private val libraries: FileCollection
|
||||
@@ -638,7 +639,7 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
private val target: String
|
||||
get() = compilation.konanTarget.name
|
||||
|
||||
private val optionsAwareCacheName get() = "$target${if (debuggable) "-g" else ""}"
|
||||
private val optionsAwareCacheName get() = "$target${if (debuggable) "-g" else ""}$konanCacheKind"
|
||||
|
||||
private val rootCacheDirectory
|
||||
get() = File(project.konanHome).resolve("klib/cache/$optionsAwareCacheName")
|
||||
@@ -726,9 +727,11 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
dfs(library)
|
||||
|
||||
for (library in sortedLibraries) {
|
||||
if (File(cacheDirectory, library.uniqueName.cachedName).exists())
|
||||
continue
|
||||
project.logger.info("Compiling ${library.uniqueName} to cache")
|
||||
val args = mutableListOf(
|
||||
"-p", "static_cache",
|
||||
"-p", konanCacheKind.produce!!,
|
||||
"-target", target
|
||||
)
|
||||
if (debuggable)
|
||||
@@ -758,18 +761,23 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
}
|
||||
}
|
||||
|
||||
private val String.cachedName
|
||||
get() = konanCacheKind.outputKind?.let {
|
||||
"${it.prefix(compilation.konanTarget)}${this}-cache${it.suffix(compilation.konanTarget)}"
|
||||
} ?: error("No output for kind $konanCacheKind")
|
||||
|
||||
private fun ensureCompilerProvidedLibPrecached(platformLibName: String, platformLibs: Map<String, File>, visitedLibs: MutableSet<String>) {
|
||||
if (platformLibName in visitedLibs)
|
||||
return
|
||||
visitedLibs += platformLibName
|
||||
val platformLib = platformLibs[platformLibName] ?: error("$platformLibName is not found in platform libs")
|
||||
if (File(rootCacheDirectory, System.mapLibraryName("$platformLibName-cache")).exists())
|
||||
if (File(rootCacheDirectory, platformLibName.cachedName).exists())
|
||||
return
|
||||
for (dependency in createKotlinLibrary(org.jetbrains.kotlin.konan.file.File(platformLib.absolutePath)).unresolvedDependencies)
|
||||
ensureCompilerProvidedLibPrecached(dependency.path, platformLibs, visitedLibs)
|
||||
project.logger.info("Compiling $platformLibName (${visitedLibs.size}/${platformLibs.size}) to cache")
|
||||
val args = mutableListOf(
|
||||
"-p", "static_cache",
|
||||
"-p", konanCacheKind.produce!!,
|
||||
"-target", target
|
||||
)
|
||||
if (debuggable)
|
||||
@@ -787,7 +795,7 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
}
|
||||
|
||||
fun buildCompilerArgs(): List<String> = mutableListOf<String>().apply {
|
||||
if (!disableKonanCache && !optimized && compilation.konanTarget.family.isAppleFamily) {
|
||||
if (konanCacheKind != NativeCacheKind.NONE && !optimized && compilation.konanTarget.family.isAppleFamily) {
|
||||
rootCacheDirectory.mkdirs()
|
||||
ensureCompilerProvidedLibsPrecached()
|
||||
add("-Xcache-directory=${rootCacheDirectory.absolutePath}")
|
||||
|
||||
Reference in New Issue
Block a user