Files
kotlin-fork/kotlin-native/platformLibs/build.gradle
T
Vasily Levchenko c85c3ac123 [build] joint (step 1)
(cherry picked from commit 7d0775f7e69ab900200bcf1fa78b94d68e6bd4f6)
2021-02-24 11:04:59 +01:00

155 lines
5.1 KiB
Groovy

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.*
import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.getVisibleName
buildscript {
repositories {
maven {
url 'https://cache-redirector.jetbrains.com/maven-central'
}
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
maven {
url "https://kotlin.bintray.com/kotlinx"
}
}
}
// These properties are used by the 'konan' plugin, thus we set them before applying it.
ext.konanHome = distDir.absolutePath
def jvmArguments = [project.findProperty("platformLibsJvmArgs") ?: "-Xmx6G", *HostManager.defaultJvmArgs]
ext.jvmArgs = jvmArguments.join(" ")
ext.setProperty("org.jetbrains.kotlin.native.home", konanHome)
ext.setProperty("konan.jvmArgs", jvmArgs)
apply plugin: 'konan'
//#region Util functions.
private ArrayList<DefFile> targetDefFiles(KonanTarget target) {
file("src/platform/${getVisibleName(target.family)}")
.listFiles()
.findAll { it.name.endsWith(".def") }
// The libz.a/libz.so and zlib.h are missing in MIPS sysroots.
// Just workaround it until we have sysroots corrected.
.findAll { ! ((target in targetsWithoutZlib) && it.name == 'zlib.def') }
.collect { DefFileKt.DefFile(it, target) }
}
private String defFileToLibName(String target, String name) {
return "$target-$name".toString()
}
//#endregion
// TODO: I think most for the non-DSL language below can either be incorporated into DSL
// or moved out of .gradle file.
rootProject.project("kotlin-native").ext.platformManager.enabled.each { target ->
def targetName = target.visibleName
ArrayList<TaskProvider> installTasks = []
ArrayList<TaskProvider> cacheTasks = []
if (target in cacheableTargets) {
tasks.register("${targetName}StdlibCache", KonanCacheTask) {
it.target = targetName
it.originalKlib = file("$konanHome/klib/common/stdlib")
it.cacheRoot = file("$konanHome/klib/cache")
it.dependsOn ":${targetName}CrossDistRuntime"
}
}
targetDefFiles(target).each { df ->
def libName = defFileToLibName(targetName, df.name)
def fileNamePrefix = PlatformLibsInfo.namePrefix
konanArtifacts {
interop(libName, targets: [targetName]) {
defFile df.file
artifactName "${fileNamePrefix}${df.name}"
noDefaultLibs true
noEndorsedLibs true
libraries {
klibs df.config.depends.collect {
"${fileNamePrefix}${it}".toString()
}
}
extraOpts '-Xpurge-user-libs', "-Xshort-module-name", df.name
compilerOpts "-fmodules-cache-path=${project.buildDir}/clangModulesCache"
}
}
def libTask = konanArtifacts."$libName"."$targetName"
libTask.configure {
it.dependsOn df.config.depends.collect { defFileToLibName(targetName, it) }
it.dependsOn ":${targetName}CrossDist"
it.enableParallel = true
}
def klibInstallTask = tasks.register("$libName", KlibInstall) {
it.klib = project.provider { libTask.get().artifact }
it.repo = file("$konanHome/klib/platform/$targetName")
it.target = targetName
it.dependsOn libTask
}
installTasks.add(klibInstallTask)
if (target in cacheableTargets) {
def cacheTask = tasks.register("${libName}Cache", KonanCacheTask) {
it.target = targetName
it.originalKlib = tasks[libName].installDir.get()
it.cacheRoot = file("$konanHome/klib/cache")
it.dependsOn ":${targetName}StdlibCache"
it.dependsOn tasks[libName]
it.dependsOn df.config.depends.collect {
def depName = defFileToLibName(targetName, it)
"${depName}Cache"
}
}
cacheTasks.add(cacheTask)
}
}
tasks.register("${targetName}Install") {
it.dependsOn installTasks
}
if (target in cacheableTargets) {
tasks.register("${targetName}Cache") {
it.dependsOn cacheTasks
it.group = BasePlugin.BUILD_GROUP
it.description = "Builds the compilation cache for platform: ${targetName}"
}
}
}
// TODO: Don't install libraries here - copy them in the distPlatformLibs task
task hostInstall {
dependsOn tasks.withType(KlibInstall.class).matching {
it.target == HostManager.hostName
}
}
task hostCache {
dependsOn tasks.withType(KonanCacheTask.class).matching {
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"
}