[K/N] Separate ClangArgs for jni and native

Since LLVM for Windows is now native instead on MinGW, we have to
compile code in a different environment in case of JNI. This commits
just separates ClangArgs into two subclasses without actual behavior
changes.
This commit is contained in:
Sergey Bogolepov
2021-07-23 12:04:07 +07:00
committed by Space
parent fbbbc1c092
commit a78fcd6b64
8 changed files with 61 additions and 41 deletions
@@ -31,7 +31,10 @@ internal object Android {
"android-${API}/arch-${architectureMap.getValue(target)}"
}
class ClangArgs(private val configurables: Configurables) {
sealed class ClangArgs(
private val configurables: Configurables,
private val forJni: Boolean
) {
private val absoluteTargetToolchain = configurables.absoluteTargetToolchain
private val absoluteTargetSysRoot = configurables.absoluteTargetSysRoot
@@ -152,16 +155,6 @@ class ClangArgs(private val configurables: Configurables) {
val clangPaths = listOf("$absoluteLlvmHome/bin", binDir)
private val jdkDir by lazy {
val home = File.javaHome.absoluteFile
if (home.child("include").exists)
home.absolutePath
else
home.parentFile.absolutePath
}
val hostCompilerArgsForJni = listOf("", HostManager.jniHostPlatformIncludeDir).map { "-I$jdkDir/include/$it" }.toTypedArray()
/**
* Clang args for Objectice-C and plain C compilation.
*/
@@ -224,5 +217,31 @@ class ClangArgs(private val configurables: Configurables) {
fun clangCXX(vararg userArgs: String) = targetClangXXCmd + userArgs.asList()
fun llvmAr(vararg userArgs: String) = targetArCmd + userArgs.asList()
/**
* Should be used when compiling library for JNI.
* For example, it is used for Kotlin/Native's Clang and LLVM libraries.
*/
class Jni(configurables: Configurables) : ClangArgs(configurables, forJni = true) {
private val jdkDir by lazy {
val home = File.javaHome.absoluteFile
if (home.child("include").exists)
home.absolutePath
else
home.parentFile.absolutePath
}
val hostCompilerArgsForJni: Array<String> by lazy {
listOf("", HostManager.jniHostPlatformIncludeDir)
.map { "-I$jdkDir/include/$it" }
.toTypedArray()
}
}
/**
* Used for compiling native code that meant to be run on end-user's hardware.
* E.g., Kotlin/Native runtime and interop stubs.
*/
class Native(configurables: Configurables) : ClangArgs(configurables, forJni = false)
}
@@ -21,10 +21,15 @@ import org.jetbrains.kotlin.konan.util.DependencyProcessor
class Platform(val configurables: Configurables)
: Configurables by configurables {
val clang by lazy {
ClangArgs(configurables)
val clang: ClangArgs.Native by lazy {
ClangArgs.Native(configurables)
}
val linker by lazy {
val clangForJni: ClangArgs.Jni by lazy {
ClangArgs.Jni(configurables)
}
val linker: LinkerFlags by lazy {
linker(configurables)
}
}