4922223bec
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`
77 lines
2.4 KiB
Kotlin
77 lines
2.4 KiB
Kotlin
/*
|
|
* 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.
|
|
*/
|
|
|
|
import org.jetbrains.kotlin.tools.lib
|
|
import org.jetbrains.kotlin.tools.solib
|
|
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 cflags = mutableListOf("-I${nativeDependencies.libffiPath}/include",
|
|
*hostPlatform.clangForJni.hostCompilerArgsForJni)
|
|
suffixes {
|
|
(".c" to ".$obj") {
|
|
tool(*hostPlatform.clangForJni.clangC("").toTypedArray())
|
|
flags( *cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
|
}
|
|
}
|
|
sourceSet {
|
|
"callbacks" {
|
|
dir("src/callbacks/c")
|
|
}
|
|
}
|
|
val objSet = sourceSets["callbacks"]!!.transform(".c" to ".$obj")
|
|
|
|
target(solib("callbacks"), objSet) {
|
|
tool(*hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
|
flags("-shared",
|
|
"-o",ruleOut(), *ruleInAll(),
|
|
"-L${project(":kotlin-native:libclangext").buildDir}",
|
|
"${nativeDependencies.libffiPath}/lib/libffi.$lib",
|
|
"-lclangext")
|
|
}
|
|
tasks.named(solib("callbacks")).configure {
|
|
dependsOn(":kotlin-native:libclangext:${lib("clangext")}")
|
|
dependsOn(nativeDependencies.libffiDependency)
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
implementation(project(":kotlin-native:utilities:basic-utils"))
|
|
implementation(project(":kotlin-stdlib"))
|
|
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
|
|
}
|
|
|
|
sourceSets.main.get().java.srcDir("src/jvm/kotlin")
|
|
|
|
|
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
|
kotlinOptions {
|
|
freeCompilerArgs += listOf(
|
|
"-opt-in=kotlin.ExperimentalUnsignedTypes",
|
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
|
"-Xskip-prerelease-check"
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
val nativelibs = project.tasks.create<Copy>("nativelibs") {
|
|
val callbacksSolib = solib("callbacks")
|
|
dependsOn(callbacksSolib)
|
|
|
|
from("$buildDir/$callbacksSolib")
|
|
into("$buildDir/nativelibs/")
|
|
}
|