[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.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanKlibInstallTask
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileNativeBinary
|
||||||
import org.jetbrains.kotlin.konan.target.Architecture
|
import org.jetbrains.kotlin.konan.target.Architecture
|
||||||
import org.jetbrains.kotlin.konan.target.Family
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
@@ -130,28 +129,10 @@ allprojects {
|
|||||||
testOutputExternal.mkdirs()
|
testOutputExternal.mkdirs()
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
library('testLibrary') {
|
|
||||||
srcDir 'testLibrary'
|
|
||||||
}
|
|
||||||
library('baseTestClass', targets: [target]) {
|
library('baseTestClass', targets: [target]) {
|
||||||
srcFiles 'testing/library.kt'
|
srcFiles 'testing/library.kt'
|
||||||
}
|
}
|
||||||
UtilsKt.dependsOnDist(UtilsKt.findKonanBuildTask(project, "testLibrary", HostManager.@Companion.getHost()))
|
UtilsKt.dependsOnDist(UtilsKt.findKonanBuildTask(project, "baseTestClass", target))
|
||||||
}
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void konanc(String[] args) {
|
void konanc(String[] args) {
|
||||||
@@ -2137,19 +2118,19 @@ standaloneTest("link_default_libs") {
|
|||||||
UtilsKt.dependsOnPlatformLibs(it)
|
UtilsKt.dependsOnPlatformLibs(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("link_testLib_explicitly1") {
|
//standaloneTest("link_testLib_explicitly1") {
|
||||||
// there is no testLibrary for cross targets yet.
|
// // there is no testLibrary for cross targets yet.
|
||||||
enabled = project.target.name == project.hostName
|
// enabled = project.target.name == project.hostName
|
||||||
dependsOn installTestLib
|
// dependsOn installTestLib
|
||||||
useGoldenData = true
|
// useGoldenData = true
|
||||||
source = "link/testLib_explicitly1.kt"
|
// source = "link/testLib_explicitly1.kt"
|
||||||
// We force library inclusion, so need to see the warning banner.
|
// // We force library inclusion, so need to see the warning banner.
|
||||||
flags = ['-l', 'testLibrary', '-r', testLibraryDir]
|
// flags = ['-l', 'testLibrary', '-r', testLibraryDir]
|
||||||
doLast {
|
// doLast {
|
||||||
def file = new File("$testLibraryDir/testLibrary")
|
// def file = new File("$testLibraryDir/testLibrary")
|
||||||
file.deleteDir()
|
// file.deleteDir()
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
linkTest("no_purge_for_dependencies") {
|
linkTest("no_purge_for_dependencies") {
|
||||||
useGoldenData = true
|
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(vararg files: Any) = tasks().forEach { it.configure { link(*files) } }
|
||||||
override fun link(files: FileCollection) = 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 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(vararg files: Any)
|
||||||
fun link(files: FileCollection)
|
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 -----------------------------------------------------
|
// 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
|
override val artifactSuffix: String
|
||||||
@Internal get() = ".klib"
|
@Internal get() = ".klib".takeUnless { noPack } ?: ""
|
||||||
|
|
||||||
override val artifactPrefix: String
|
override val artifactPrefix: String
|
||||||
@Internal get() = ""
|
@Internal get() = ""
|
||||||
@@ -63,6 +71,9 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
|||||||
@InputFiles val headers = mutableSetOf<FileCollection>()
|
@InputFiles val headers = mutableSetOf<FileCollection>()
|
||||||
@InputFiles val linkFiles = mutableSetOf<FileCollection>()
|
@InputFiles val linkFiles = mutableSetOf<FileCollection>()
|
||||||
|
|
||||||
|
@Input
|
||||||
|
var noPack: Boolean = false
|
||||||
|
|
||||||
fun buildArgs() = mutableListOf<String>().apply {
|
fun buildArgs() = mutableListOf<String>().apply {
|
||||||
addArg("-o", artifact.canonicalPath)
|
addArg("-o", artifact.canonicalPath)
|
||||||
|
|
||||||
@@ -96,6 +107,8 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
|||||||
addKey("-no-default-libs", noDefaultLibs)
|
addKey("-no-default-libs", noDefaultLibs)
|
||||||
addKey("-no-endorsed-libs", noEndorsedLibs)
|
addKey("-no-endorsed-libs", noEndorsedLibs)
|
||||||
|
|
||||||
|
addKey("-nopack", noPack)
|
||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,10 +163,15 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
|||||||
override fun link(vararg files: Any) {
|
override fun link(vararg files: Any) {
|
||||||
linkFiles.add(project.files(files))
|
linkFiles.add(project.files(files))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun link(files: FileCollection) {
|
override fun link(files: FileCollection) {
|
||||||
linkFiles.add(files)
|
linkFiles.add(files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun noPack(flag: Boolean) {
|
||||||
|
noPack = flag
|
||||||
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
internal interface RunToolParameters: WorkParameters {
|
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.
|
* 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.konan.tasks.KonanCacheTask
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
||||||
import org.jetbrains.kotlin.konan.target.*
|
import org.jetbrains.kotlin.konan.target.*
|
||||||
@@ -61,14 +60,12 @@ konanTargetList.forEach { target ->
|
|||||||
val artifactName = "${fileNamePrefix}${df.name}"
|
val artifactName = "${fileNamePrefix}${df.name}"
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
interop(
|
interop(args = mapOf("targets" to listOf(targetName)), name = libName) {
|
||||||
args = mapOf("targets" to listOf(targetName)),
|
|
||||||
name = libName
|
|
||||||
) {
|
|
||||||
df.file?.let { defFile(it) }
|
df.file?.let { defFile(it) }
|
||||||
artifactName(artifactName)
|
artifactName(artifactName)
|
||||||
noDefaultLibs(true)
|
noDefaultLibs(true)
|
||||||
noEndorsedLibs(true)
|
noEndorsedLibs(true)
|
||||||
|
noPack(true)
|
||||||
libraries {
|
libraries {
|
||||||
klibs(df.config.depends.map { "${fileNamePrefix}${it}" })
|
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>
|
val libTask = konanArtifacts.getByName(libName).getByTarget(targetName) as TaskProvider<KonanInteropTask>
|
||||||
libTask.configure {
|
libTask.configure {
|
||||||
dependsOn(df.config.depends.map { defFileToLibName(targetName, it) })
|
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
|
enableParallel = project.findProperty("kotlin.native.platformLibs.parallel")?.toString()?.toBoolean() ?: true
|
||||||
}
|
}
|
||||||
|
|
||||||
val klibInstallTask = tasks.register(libName, KonanKlibInstallTask::class.java) {
|
val klibInstallTask = tasks.register(libName, Sync::class.java) {
|
||||||
klib = libTask.map { it.artifact }
|
from(libTask.map { it.artifact })
|
||||||
repo = file("$konanHome/klib/platform/$targetName")
|
into("$konanHome/klib/platform/$targetName/$artifactName")
|
||||||
this.target = targetName
|
|
||||||
dependsOn(libTask)
|
|
||||||
}
|
}
|
||||||
installTasks.add(klibInstallTask)
|
installTasks.add(klibInstallTask)
|
||||||
|
|
||||||
if (target in cacheableTargets) {
|
if (target in cacheableTargets) {
|
||||||
val cacheTask = tasks.register("${libName}Cache", KonanCacheTask::class.java) {
|
val cacheTask = tasks.register("${libName}Cache", KonanCacheTask::class.java) {
|
||||||
this.target = targetName
|
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
|
klibUniqName = artifactName
|
||||||
cacheRoot = file("$konanHome/klib/cache").absolutePath
|
cacheRoot = file("$konanHome/klib/cache").absolutePath
|
||||||
|
|
||||||
dependsOn(":kotlin-native:${targetName}StdlibCache")
|
dependsOn(":kotlin-native:${targetName}StdlibCache")
|
||||||
dependsOn(tasks.named(libName))
|
|
||||||
dependsOn(df.config.depends.map {
|
// Make it depend on platform libraries defined in def files and their caches
|
||||||
val depName = defFileToLibName(targetName, it)
|
df.config.depends.map {
|
||||||
"${depName}Cache"
|
defFileToLibName(targetName, it)
|
||||||
})
|
}.forEach {
|
||||||
|
dependsOn(it)
|
||||||
|
dependsOn("${it}Cache")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cacheTasks.add(cacheTask)
|
cacheTasks.add(cacheTask)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user