[K/N][build] Rewrite platforms libs to kts
This commit is contained in:
@@ -1,148 +0,0 @@
|
||||
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 org.jetbrains.kotlin.UtilsKt
|
||||
|
||||
import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.getVisibleName
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
if (UtilsKt.getCacheRedirectorEnabled(project))
|
||||
maven { url 'https://cache-redirector.jetbrains.com/maven-central'}
|
||||
else
|
||||
mavenCentral()
|
||||
maven {
|
||||
url project.bootstrapKotlinRepo
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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
|
||||
|
||||
if (HostManager.host.name == "macos_arm64") {
|
||||
JvmToolchain.configureJvmToolchain(project, JdkMajorVersion.JDK_17)
|
||||
}
|
||||
|
||||
// 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 = []
|
||||
|
||||
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 ":kotlin-native:${targetName}CrossDist"
|
||||
it.enableParallel = project.hasProperty("kotlin.native.platformLibs.parallel")
|
||||
? project.findProperty("kotlin.native.platformLibs.parallel")?.toString()?.toBoolean()
|
||||
: HostManager.host != "macos_arm64"
|
||||
}
|
||||
|
||||
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").absolutePath
|
||||
|
||||
it.dependsOn ":kotlin-native:${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"
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.KlibInstall
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
|
||||
// These properties are used by the 'konan' plugin, thus we set them before applying it.
|
||||
val distDir: File by project
|
||||
val konanHome: String by extra(distDir.absolutePath)
|
||||
val jvmArgs: String by extra(
|
||||
mutableListOf<String>().apply {
|
||||
addAll(HostManager.defaultJvmArgs)
|
||||
add(project.findProperty("platformLibsJvmArgs") as? String ?: "-Xmx6G")
|
||||
}.joinToString(" ")
|
||||
)
|
||||
|
||||
extra["org.jetbrains.kotlin.native.home"] = konanHome
|
||||
extra["konan.jvmArgs"] = jvmArgs
|
||||
|
||||
plugins {
|
||||
id("konan")
|
||||
}
|
||||
|
||||
val targetsWithoutZlib: List<KonanTarget> by project
|
||||
|
||||
// region: Util functions.
|
||||
fun targetDefFiles(target: KonanTarget) =
|
||||
project.fileTree("src/platform/${target.family.visibleName}")
|
||||
.filter { 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.
|
||||
.filter { ! ((target in targetsWithoutZlib) && it.name == "zlib.def") }
|
||||
.map { DefFile(it, target) }
|
||||
|
||||
|
||||
fun defFileToLibName(target: String, name: String) = "$target-$name"
|
||||
|
||||
// endregion
|
||||
|
||||
if (HostManager.host == KonanTarget.MACOS_ARM64) {
|
||||
project.configureJvmToolchain(JdkMajorVersion.JDK_17)
|
||||
}
|
||||
|
||||
val konanTargetList: List<KonanTarget> by project
|
||||
val targetList: List<String> by project
|
||||
val cacheableTargets: List<KonanTarget> by project
|
||||
|
||||
konanTargetList.forEach { target ->
|
||||
val targetName = target.visibleName
|
||||
val installTasks = mutableListOf<TaskProvider<out Task>>()
|
||||
val cacheTasks = mutableListOf<TaskProvider<out Task>>()
|
||||
|
||||
targetDefFiles(target).forEach { df ->
|
||||
val libName = defFileToLibName(targetName, df.name)
|
||||
val fileNamePrefix = PlatformLibsInfo.namePrefix
|
||||
|
||||
konanArtifacts {
|
||||
interop(
|
||||
args = mapOf("targets" to listOf(targetName)),
|
||||
name = libName
|
||||
) {
|
||||
df.file?.let { defFile(it) }
|
||||
artifactName("${fileNamePrefix}${df.name}")
|
||||
noDefaultLibs(true)
|
||||
noEndorsedLibs(true)
|
||||
libraries {
|
||||
klibs(df.config.depends.map { "${fileNamePrefix}${it}" })
|
||||
}
|
||||
extraOpts("-Xpurge-user-libs", "-Xshort-module-name", df.name)
|
||||
compilerOpts("-fmodules-cache-path=${project.buildDir}/clangModulesCache")
|
||||
}
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
val libTask = konanArtifacts.getByName(libName).getByTarget(targetName) as? TaskProvider<KonanInteropTask>
|
||||
libTask?.configure {
|
||||
dependsOn(df.config.depends.map { defFileToLibName(targetName, it) })
|
||||
dependsOn(":kotlin-native:${targetName}CrossDist")
|
||||
|
||||
enableParallel = if (project.hasProperty("kotlin.native.platformLibs.parallel")) {
|
||||
project.findProperty("kotlin.native.platformLibs.parallel")?.toString()?.toBoolean() ?: false
|
||||
} else {
|
||||
(HostManager.host != KonanTarget.MACOS_ARM64)
|
||||
}
|
||||
}
|
||||
|
||||
val klibInstallTask = tasks.register(libName, KlibInstall::class.java) {
|
||||
klib = project.provider { libTask?.get()?.artifact }
|
||||
repo = file("$konanHome/klib/platform/$targetName")
|
||||
this.target = targetName
|
||||
dependsOn(libTask)
|
||||
}
|
||||
installTasks.add(klibInstallTask)
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
val cacheTask = tasks.register("${libName}Cache", KonanCacheTask::class.java) {
|
||||
this.target = targetName
|
||||
originalKlib = klibInstallTask.get().installDir.get()
|
||||
cacheRoot = file("$konanHome/klib/cache").absolutePath
|
||||
|
||||
dependsOn(":kotlin-native:${targetName}StdlibCache")
|
||||
dependsOn(tasks[libName])
|
||||
dependsOn(df.config.depends.map {
|
||||
val depName = defFileToLibName(targetName, it)
|
||||
"${depName}Cache"
|
||||
})
|
||||
}
|
||||
cacheTasks.add(cacheTask)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("${targetName}Install") {
|
||||
dependsOn(installTasks)
|
||||
}
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
tasks.register("${targetName}Cache") {
|
||||
dependsOn(cacheTasks)
|
||||
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Builds the compilation cache for platform: $targetName"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val hostName: String by project
|
||||
|
||||
val hostInstall by tasks.registering {
|
||||
dependsOn("${hostName}Install")
|
||||
}
|
||||
|
||||
val hostCache by tasks.registering {
|
||||
dependsOn("${hostName}Cache")
|
||||
}
|
||||
|
||||
val cache by tasks.registering {
|
||||
dependsOn(tasks.withType(KonanCacheTask::class.java))
|
||||
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Builds all the compilation caches"
|
||||
}
|
||||
Reference in New Issue
Block a user