Platform libs: Generate static cache
The following targets are supported: macos_x64 ios_x64 ios_arm64 ios_arm32
This commit is contained in:
committed by
Ilya Matveev
parent
bc94ff8ed6
commit
33774cbf77
@@ -66,6 +66,14 @@ ext {
|
||||
platformManager = new PlatformManager(DistributionKt.buildDistribution(projectDir.absolutePath),
|
||||
ext.experimentalEnabled)
|
||||
|
||||
cacheableTargets = [
|
||||
KonanTarget.MACOS_X64.INSTANCE,
|
||||
KonanTarget.IOS_X64.INSTANCE,
|
||||
KonanTarget.IOS_ARM64.INSTANCE,
|
||||
KonanTarget.IOS_ARM32.INSTANCE
|
||||
]
|
||||
cacheableTargetNames = cacheableTargets.collect { it.visibleName }
|
||||
|
||||
kotlinCompilerModule="org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}"
|
||||
kotlinStdLibModule="org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
|
||||
kotlinCommonStdlibModule="org.jetbrains.kotlin:kotlin-stdlib-common:${kotlinStdlibVersion}:sources"
|
||||
@@ -445,6 +453,9 @@ targetList.each { target ->
|
||||
|
||||
task("${target}PlatformLibs") {
|
||||
dependsOn ":platformLibs:${target}Install"
|
||||
if (target in cacheableTargetNames) {
|
||||
dependsOn(":platformLibs:${target}Cache")
|
||||
}
|
||||
}
|
||||
|
||||
task("${target}CrossDist") {
|
||||
@@ -464,6 +475,7 @@ targetList.each { target ->
|
||||
|
||||
task distPlatformLibs {
|
||||
dependsOn ':platformLibs:hostInstall'
|
||||
dependsOn ':platformLibs:hostCache'
|
||||
}
|
||||
|
||||
task dist {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask
|
||||
import org.jetbrains.kotlin.KlibInstall
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
@@ -58,6 +59,15 @@ project.rootProject.ext.platformManager.enabled.each { target ->
|
||||
def targetName = target.visibleName
|
||||
|
||||
ArrayList<Task> installTasks = []
|
||||
ArrayList<Task> cacheTasks = []
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
task "${targetName}StdlibCache"(type: KonanCacheTask) {
|
||||
it.target = targetName
|
||||
originalKlib = file("$konanHome/klib/common/stdlib")
|
||||
cacheDirectory = file("$konanHome/klib/cache/$targetName-g")
|
||||
}
|
||||
}
|
||||
|
||||
targetDefFiles(target).each { df ->
|
||||
def libName = defFileToLibName(targetName, df.name)
|
||||
@@ -89,11 +99,37 @@ project.rootProject.ext.platformManager.enabled.each { target ->
|
||||
|
||||
}
|
||||
installTasks.add(tasks[libName])
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
task "${libName}Cache"(type: KonanCacheTask) {
|
||||
it.target = targetName
|
||||
originalKlib = tasks[libName].installDir
|
||||
cacheDirectory = file("$konanHome/klib/cache/$targetName-g")
|
||||
|
||||
dependsOn "${targetName}StdlibCache"
|
||||
dependsOn tasks[libName]
|
||||
dependsOn df.config.depends.collect {
|
||||
def depName = defFileToLibName(targetName, it)
|
||||
"${depName}Cache"
|
||||
}
|
||||
|
||||
cacheTasks.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task "${targetName}Install" {
|
||||
dependsOn installTasks
|
||||
}
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
task "${targetName}Cache" {
|
||||
dependsOn cacheTasks
|
||||
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Builds the compilation cache for platform: ${targetName}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Don't install libraries here - copy them in the distPlatformLibs task
|
||||
@@ -103,10 +139,23 @@ task hostInstall {
|
||||
}
|
||||
}
|
||||
|
||||
task hostCache {
|
||||
dependsOn tasks.withType(KonanCacheTask.class).findAll {
|
||||
it.target == HostManager.hostName
|
||||
}
|
||||
}
|
||||
|
||||
task install {
|
||||
dependsOn tasks.withType(KlibInstall.class)
|
||||
}
|
||||
|
||||
task cache {
|
||||
dependsOn tasks.withType(KonanCacheTask.class)
|
||||
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Builds all the compilation caches"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.konan.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.KonanCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanTargetableTask
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.io.File
|
||||
|
||||
enum class KonanCacheKind(val outputKind: CompilerOutputKind) {
|
||||
STATIC(CompilerOutputKind.STATIC_CACHE),
|
||||
DYNAMIC(CompilerOutputKind.DYNAMIC_CACHE)
|
||||
}
|
||||
|
||||
open class KonanCacheTask: DefaultTask() {
|
||||
@InputDirectory
|
||||
lateinit var originalKlib: File
|
||||
|
||||
// Taken into account by the [cacheFile] property.
|
||||
@Internal
|
||||
lateinit var cacheDirectory: File
|
||||
|
||||
@get:Input
|
||||
lateinit var target: String
|
||||
|
||||
@get:OutputFile
|
||||
protected val cacheFile: File
|
||||
get() {
|
||||
val konanTarget = HostManager().targetByName(target)
|
||||
val klibName = originalKlib.nameWithoutExtension
|
||||
val cachePrefix = cacheKind.outputKind.prefix(konanTarget)
|
||||
val cacheSuffix = cacheKind.outputKind.suffix(konanTarget)
|
||||
val cacheName = "${cachePrefix}${klibName}-cache${cacheSuffix}"
|
||||
return cacheDirectory.resolve(cacheName)
|
||||
}
|
||||
|
||||
@Input
|
||||
var cacheKind: KonanCacheKind = KonanCacheKind.STATIC
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val args = listOf(
|
||||
"-g",
|
||||
"-target", target,
|
||||
"-produce", cacheKind.outputKind.name.toLowerCase(),
|
||||
"-Xadd-cache=${originalKlib.absolutePath}",
|
||||
"-Xcache-directory=${cacheDirectory.absolutePath}"
|
||||
)
|
||||
KonanCompilerRunner(project).run(args)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user