[K/N][build] Build platform libraries without zipping/unzipping
With "-nopack" compiler option, it is possible to build unzipped klibs. This makes it possible to get rid of install tasks that unzip them. Also, an obsolete test for klib installation was removed.
This commit is contained in:
committed by
Space Team
parent
094490acbd
commit
9961780fbd
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanKlibInstallTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileNativeBinary
|
||||
import org.jetbrains.kotlin.konan.target.Architecture
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
@@ -130,28 +129,10 @@ allprojects {
|
||||
testOutputExternal.mkdirs()
|
||||
|
||||
konanArtifacts {
|
||||
library('testLibrary') {
|
||||
srcDir 'testLibrary'
|
||||
}
|
||||
library('baseTestClass', targets: [target]) {
|
||||
srcFiles 'testing/library.kt'
|
||||
}
|
||||
UtilsKt.dependsOnDist(UtilsKt.findKonanBuildTask(project, "testLibrary", HostManager.@Companion.getHost()))
|
||||
}
|
||||
tasks.named("compileKonanBaseTestClass${UtilsKt.getTestTargetSuffix(project)}").configure {
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
def installTestLib = tasks.register("installTestLibrary", KonanKlibInstallTask) {
|
||||
dependsOn "compileKonanTestLibraryHost"
|
||||
klib = project.provider { konanArtifacts.testLibrary.getArtifactByTarget('host') }
|
||||
repo = rootProject.file(testLibraryDir)
|
||||
|
||||
doLast {
|
||||
// Remove the version in build/, so that we don't link two copies.
|
||||
def file = project.file("build/konan/libs/${project.target.name}/testLibrary.klib")
|
||||
file.delete()
|
||||
}
|
||||
UtilsKt.dependsOnDist(UtilsKt.findKonanBuildTask(project, "baseTestClass", target))
|
||||
}
|
||||
|
||||
void konanc(String[] args) {
|
||||
@@ -2137,19 +2118,19 @@ standaloneTest("link_default_libs") {
|
||||
UtilsKt.dependsOnPlatformLibs(it)
|
||||
}
|
||||
|
||||
standaloneTest("link_testLib_explicitly1") {
|
||||
// there is no testLibrary for cross targets yet.
|
||||
enabled = project.target.name == project.hostName
|
||||
dependsOn installTestLib
|
||||
useGoldenData = true
|
||||
source = "link/testLib_explicitly1.kt"
|
||||
// We force library inclusion, so need to see the warning banner.
|
||||
flags = ['-l', 'testLibrary', '-r', testLibraryDir]
|
||||
doLast {
|
||||
def file = new File("$testLibraryDir/testLibrary")
|
||||
file.deleteDir()
|
||||
}
|
||||
}
|
||||
//standaloneTest("link_testLib_explicitly1") {
|
||||
// // there is no testLibrary for cross targets yet.
|
||||
// enabled = project.target.name == project.hostName
|
||||
// dependsOn installTestLib
|
||||
// useGoldenData = true
|
||||
// source = "link/testLib_explicitly1.kt"
|
||||
// // We force library inclusion, so need to see the warning banner.
|
||||
// flags = ['-l', 'testLibrary', '-r', testLibraryDir]
|
||||
// doLast {
|
||||
// def file = new File("$testLibraryDir/testLibrary")
|
||||
// file.deleteDir()
|
||||
// }
|
||||
//}
|
||||
|
||||
linkTest("no_purge_for_dependencies") {
|
||||
useGoldenData = true
|
||||
|
||||
+2
@@ -70,4 +70,6 @@ open class KonanInteropLibrary(name: String,
|
||||
override fun link(vararg files: Any) = tasks().forEach { it.configure { link(*files) } }
|
||||
override fun link(files: FileCollection) = tasks().forEach { it.configure { link(files) } }
|
||||
override fun dependencies(closure: Closure<Unit>) = tasks().forEach { it.configure { dependencies(closure) }}
|
||||
|
||||
override fun noPack(flag: Boolean) = tasks().forEach { it.configure { noPack(flag) } }
|
||||
}
|
||||
+2
@@ -103,4 +103,6 @@ interface KonanInteropSpec: KonanBuildingSpec {
|
||||
|
||||
fun link(vararg files: Any)
|
||||
fun link(files: FileCollection)
|
||||
|
||||
fun noPack(flag: Boolean)
|
||||
}
|
||||
+19
-1
@@ -40,9 +40,17 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
||||
}
|
||||
|
||||
// Output directories -----------------------------------------------------
|
||||
override val artifact: File
|
||||
@Internal get() = destinationDir.resolve(artifactFullName)
|
||||
|
||||
val artifactFile: File?
|
||||
@Optional @OutputFile get() = if (!noPack) artifact else null
|
||||
|
||||
val artifactDirectory: File?
|
||||
@Optional @OutputDirectory get() = if (noPack) artifact else null
|
||||
|
||||
override val artifactSuffix: String
|
||||
@Internal get() = ".klib"
|
||||
@Internal get() = ".klib".takeUnless { noPack } ?: ""
|
||||
|
||||
override val artifactPrefix: String
|
||||
@Internal get() = ""
|
||||
@@ -63,6 +71,9 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
||||
@InputFiles val headers = mutableSetOf<FileCollection>()
|
||||
@InputFiles val linkFiles = mutableSetOf<FileCollection>()
|
||||
|
||||
@Input
|
||||
var noPack: Boolean = false
|
||||
|
||||
fun buildArgs() = mutableListOf<String>().apply {
|
||||
addArg("-o", artifact.canonicalPath)
|
||||
|
||||
@@ -96,6 +107,8 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
||||
addKey("-no-default-libs", noDefaultLibs)
|
||||
addKey("-no-endorsed-libs", noEndorsedLibs)
|
||||
|
||||
addKey("-nopack", noPack)
|
||||
|
||||
addAll(extraOpts)
|
||||
}
|
||||
|
||||
@@ -150,10 +163,15 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
||||
override fun link(vararg files: Any) {
|
||||
linkFiles.add(project.files(files))
|
||||
}
|
||||
|
||||
override fun link(files: FileCollection) {
|
||||
linkFiles.add(files)
|
||||
}
|
||||
|
||||
override fun noPack(flag: Boolean) {
|
||||
noPack = flag
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
internal interface RunToolParameters: WorkParameters {
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.konan.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.KonanKlibRunner
|
||||
import org.jetbrains.kotlin.kotlinNativeDist
|
||||
import java.io.File
|
||||
|
||||
open class KonanKlibInstallTask : DefaultTask() {
|
||||
@get:InputFile
|
||||
var klib: Provider<File> = project.provider { project.buildDir }
|
||||
|
||||
@get:Internal
|
||||
var repo: File = project.rootDir
|
||||
|
||||
val installDir: Provider<File>
|
||||
@OutputDirectory
|
||||
get() = project.provider {
|
||||
val klibName = klib.get().nameWithoutExtension
|
||||
project.file("${repo.absolutePath}/$klibName")
|
||||
}
|
||||
|
||||
@get:Input
|
||||
var target: String = HostManager.hostName
|
||||
|
||||
@TaskAction
|
||||
fun exec() {
|
||||
val args = listOf(
|
||||
"install", klib.get().absolutePath,
|
||||
"-target", target,
|
||||
"-repository", repo.absolutePath
|
||||
)
|
||||
KonanKlibRunner(project, konanHome = project.kotlinNativeDist.absolutePath).run(args)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanKlibInstallTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
@@ -61,14 +60,12 @@ konanTargetList.forEach { target ->
|
||||
val artifactName = "${fileNamePrefix}${df.name}"
|
||||
|
||||
konanArtifacts {
|
||||
interop(
|
||||
args = mapOf("targets" to listOf(targetName)),
|
||||
name = libName
|
||||
) {
|
||||
interop(args = mapOf("targets" to listOf(targetName)), name = libName) {
|
||||
df.file?.let { defFile(it) }
|
||||
artifactName(artifactName)
|
||||
noDefaultLibs(true)
|
||||
noEndorsedLibs(true)
|
||||
noPack(true)
|
||||
libraries {
|
||||
klibs(df.config.depends.map { "${fileNamePrefix}${it}" })
|
||||
}
|
||||
@@ -77,7 +74,7 @@ konanTargetList.forEach { target ->
|
||||
}
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val libTask = konanArtifacts.getByName(libName).getByTarget(targetName) as TaskProvider<KonanInteropTask>
|
||||
libTask.configure {
|
||||
dependsOn(df.config.depends.map { defFileToLibName(targetName, it) })
|
||||
@@ -86,27 +83,30 @@ konanTargetList.forEach { target ->
|
||||
enableParallel = project.findProperty("kotlin.native.platformLibs.parallel")?.toString()?.toBoolean() ?: true
|
||||
}
|
||||
|
||||
val klibInstallTask = tasks.register(libName, KonanKlibInstallTask::class.java) {
|
||||
klib = libTask.map { it.artifact }
|
||||
repo = file("$konanHome/klib/platform/$targetName")
|
||||
this.target = targetName
|
||||
dependsOn(libTask)
|
||||
val klibInstallTask = tasks.register(libName, Sync::class.java) {
|
||||
from(libTask.map { it.artifact })
|
||||
into("$konanHome/klib/platform/$targetName/$artifactName")
|
||||
}
|
||||
installTasks.add(klibInstallTask)
|
||||
|
||||
if (target in cacheableTargets) {
|
||||
val cacheTask = tasks.register("${libName}Cache", KonanCacheTask::class.java) {
|
||||
this.target = targetName
|
||||
originalKlib.fileProvider(klibInstallTask.flatMap { it.installDir })
|
||||
originalKlib.fileProvider(libTask.map {
|
||||
it.artifactDirectory ?: error("Artifact wasn't set for ${it.name}")
|
||||
})
|
||||
klibUniqName = artifactName
|
||||
cacheRoot = file("$konanHome/klib/cache").absolutePath
|
||||
|
||||
dependsOn(":kotlin-native:${targetName}StdlibCache")
|
||||
dependsOn(tasks.named(libName))
|
||||
dependsOn(df.config.depends.map {
|
||||
val depName = defFileToLibName(targetName, it)
|
||||
"${depName}Cache"
|
||||
})
|
||||
|
||||
// Make it depend on platform libraries defined in def files and their caches
|
||||
df.config.depends.map {
|
||||
defFileToLibName(targetName, it)
|
||||
}.forEach {
|
||||
dependsOn(it)
|
||||
dependsOn("${it}Cache")
|
||||
}
|
||||
}
|
||||
cacheTasks.add(cacheTask)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user