[K/N] Refactor :kotlin-native:dependencies

Move K/N dependencies handling logic into gradle plugins:

`NativeDependenciesDownloader` is instantiated in
`:kotlin-native:dependencies` and provides a single configuration that
contains all directories with the dependencies. The configuration has
a variant for each target.

`NativeDependencies` is instantiated by projects that require native
dependencies (i.e. previously used to depend on
`:kotlin-native:dependencies:update`). This plugin creates a configuration
that by default depends on `:kotlin-native:dependencies`. Its extension
provides `llvmDependency`, `libffiDependency`, `hostPlatformDependency`,
`targetDependency()` to depend on the parts needed for the project and
provides accessors `llvmPath`, `libffiPath`, `hostPlatform` that are
safe to use during configuration time, but which do not automatically
resolve those dependencies.

`llvmDir`, `*LibffiDir` properties on `:kotlin-native` are removed
completely, as their use is replaced by `NativeDependencies`. As a
consequence, `evaluationDependsOn(":kotlin-native:dependencies")` is
also gone.

All direct dependencies on `:kotlin-native:dependencies:update` are
replaced with dependencies on specific parts via `NativeDependencies`
This commit is contained in:
Alexander Shabalin
2023-08-28 11:55:32 +02:00
committed by Space Team
parent 9de791b9ac
commit 4922223bec
23 changed files with 519 additions and 186 deletions
@@ -17,14 +17,13 @@ plugins {
id("kotlin.native.build-tools-conventions")
id("native-interop-plugin")
id("native")
id("native-dependencies")
}
val libclangextProject = project(":kotlin-native:libclangext")
val libclangextTask = libclangextProject.path + ":build"
val libclangextDir = libclangextProject.buildDir
val libclangextIsEnabled = libclangextProject.findProperty("isEnabled")!! as Boolean
val llvmDir = project.findProperty("llvmDir")
val libclang =
@@ -34,11 +33,11 @@ val libclang =
"lib/${System.mapLibraryName("clang")}"
}
val cflags = mutableListOf( "-I$llvmDir/include",
val cflags = mutableListOf( "-I${nativeDependencies.llvmPath}/include",
"-I${project(":kotlin-native:libclangext").projectDir.absolutePath}/src/main/include",
*platformManager.hostPlatform.clangForJni.hostCompilerArgsForJni)
val ldflags = mutableListOf("$llvmDir/$libclang", "-L${libclangextDir.absolutePath}", "-lclangext")
val ldflags = mutableListOf("${nativeDependencies.llvmPath}/$libclang", "-L${libclangextDir.absolutePath}", "-lclangext")
if (libclangextIsEnabled) {
assert(HostManager.hostIsMac)
@@ -74,7 +73,7 @@ if (libclangextIsEnabled) {
"clangTooling", "clangFormat", "LLVMTarget", "LLVMMC", "LLVMLinker", "LLVMTransformUtils",
"LLVMBitWriter", "LLVMBitReader", "LLVMAnalysis", "LLVMProfileData", "LLVMCore",
"LLVMSupport", "LLVMBinaryFormat", "LLVMDemangle"
).map { "$llvmDir/lib/lib${it}.a" }
).map { "${nativeDependencies.llvmPath}/lib/lib${it}.a" }
ldflags.addAll(llvmLibs)
ldflags.addAll(listOf("-lpthread", "-lz", "-lm", "-lcurses"))
@@ -93,12 +92,12 @@ native {
val cxxflags = listOf("-std=c++11", *cflags.toTypedArray())
suffixes {
(".c" to ".$obj") {
tool(*platformManager.hostPlatform.clangForJni.clangC("").toTypedArray())
tool(*hostPlatform.clangForJni.clangC("").toTypedArray())
flags(*cflags.toTypedArray(),
"-c", "-o", ruleOut(), ruleInFirst())
}
(".cpp" to ".$obj") {
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
tool(*hostPlatform.clangForJni.clangCXX("").toTypedArray())
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
}
@@ -115,7 +114,7 @@ native {
sourceSets["main-cpp"]!!.transform(".cpp" to ".$obj"))
target(solib("clangstubs"), *objSet) {
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
tool(*hostPlatform.clangForJni.clangCXX("").toTypedArray())
flags(
"-shared",
"-o", ruleOut(), *ruleInAll(),
@@ -182,11 +181,12 @@ tasks.withType<Test>().configureEach {
project(":kotlin-native:Interop:Runtime")
)
dependsOn(projectsWithNativeLibs.map { "${it.path}:nativelibs" })
dependsOn(nativeDependencies.llvmDependency)
systemProperty("java.library.path", projectsWithNativeLibs.joinToString(File.pathSeparator) {
File(it.buildDir, "nativelibs").absolutePath
})
systemProperty("kotlin.native.llvm.libclang", "$llvmDir/" + if (HostManager.hostIsMingw) {
systemProperty("kotlin.native.llvm.libclang", "${nativeDependencies.llvmPath}/" + if (HostManager.hostIsMingw) {
"bin/libclang.dll"
} else {
"lib/${System.mapLibraryName("clang")}"
@@ -10,19 +10,18 @@ import org.jetbrains.kotlin.*
plugins {
id("org.jetbrains.kotlin.jvm")
id("native")
id("native-dependencies")
}
native {
val isWindows = PlatformInfo.isWindows()
val obj = if (isWindows) "obj" else "o"
val lib = if (isWindows) "lib" else "a"
val host = rootProject.project(":kotlin-native").extra["hostName"]
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
val cflags = mutableListOf("-I$hostLibffiDir/include",
*platformManager.hostPlatform.clangForJni.hostCompilerArgsForJni)
val cflags = mutableListOf("-I${nativeDependencies.libffiPath}/include",
*hostPlatform.clangForJni.hostCompilerArgsForJni)
suffixes {
(".c" to ".$obj") {
tool(*platformManager.hostPlatform.clangForJni.clangC("").toTypedArray())
tool(*hostPlatform.clangForJni.clangC("").toTypedArray())
flags( *cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
}
}
@@ -34,15 +33,16 @@ native {
val objSet = sourceSets["callbacks"]!!.transform(".c" to ".$obj")
target(solib("callbacks"), objSet) {
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
tool(*hostPlatform.clangForJni.clangCXX("").toTypedArray())
flags("-shared",
"-o",ruleOut(), *ruleInAll(),
"-L${project(":kotlin-native:libclangext").buildDir}",
"$hostLibffiDir/lib/libffi.$lib",
"${nativeDependencies.libffiPath}/lib/libffi.$lib",
"-lclangext")
}
tasks.named(solib("callbacks")).configure {
dependsOn(":kotlin-native:libclangext:${lib("clangext")}")
dependsOn(nativeDependencies.libffiDependency)
}
}
@@ -21,6 +21,7 @@ buildscript {
plugins {
kotlin("jvm")
application
id("native-dependencies")
}
application {
@@ -59,11 +60,11 @@ tasks {
project(":kotlin-native:Interop:Runtime")
)
dependsOn(projectsWithNativeLibs.map { "${it.path}:nativelibs" })
dependsOn(nativeDependencies.llvmDependency)
systemProperty("java.library.path", projectsWithNativeLibs.joinToString(File.pathSeparator) {
File(it.buildDir, "nativelibs").absolutePath
})
val llvmDir = project.findProperty("llvmDir")
val libclangPath = "$llvmDir/" + if (org.jetbrains.kotlin.konan.target.HostManager.hostIsMingw) {
val libclangPath = "${nativeDependencies.llvmPath}/" + if (org.jetbrains.kotlin.konan.target.HostManager.hostIsMingw) {
"bin/libclang.dll"
} else {
"lib/${System.mapLibraryName("clang")}"