[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:
@@ -45,7 +45,7 @@ val libclang =
|
|||||||
|
|
||||||
val cflags = mutableListOf( "-I$llvmDir/include",
|
val cflags = mutableListOf( "-I$llvmDir/include",
|
||||||
"-I${project(":kotlin-native:libclangext").projectDir.absolutePath}/src/main/include",
|
"-I${project(":kotlin-native:libclangext").projectDir.absolutePath}/src/main/include",
|
||||||
*platformManager.hostPlatform.clang.hostCompilerArgsForJni)
|
*platformManager.hostPlatform.clangForJni.hostCompilerArgsForJni)
|
||||||
|
|
||||||
val ldflags = mutableListOf("$llvmDir/$libclang", "-L${libclangextDir.absolutePath}", "-lclangext")
|
val ldflags = mutableListOf("$llvmDir/$libclang", "-L${libclangextDir.absolutePath}", "-lclangext")
|
||||||
|
|
||||||
@@ -99,17 +99,15 @@ val lib = if (HostManager.hostIsMingw) "lib" else "a"
|
|||||||
|
|
||||||
native {
|
native {
|
||||||
val obj = if (HostManager.hostIsMingw) "obj" else "o"
|
val obj = if (HostManager.hostIsMingw) "obj" else "o"
|
||||||
val host = rootProject.project(":kotlin-native").extra["hostName"]
|
|
||||||
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
|
|
||||||
val cxxflags = listOf("-std=c++11", *cflags.toTypedArray())
|
val cxxflags = listOf("-std=c++11", *cflags.toTypedArray())
|
||||||
suffixes {
|
suffixes {
|
||||||
(".c" to ".$obj") {
|
(".c" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangC("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangC("").toTypedArray())
|
||||||
flags(*cflags.toTypedArray(),
|
flags(*cflags.toTypedArray(),
|
||||||
"-c", "-o", ruleOut(), ruleInFirst())
|
"-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
(".cpp" to ".$obj") {
|
(".cpp" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +124,7 @@ native {
|
|||||||
sourceSets["main-cpp"]!!.transform(".cpp" to ".$obj"))
|
sourceSets["main-cpp"]!!.transform(".cpp" to ".$obj"))
|
||||||
|
|
||||||
target(solib("clangstubs"), *objSet) {
|
target(solib("clangstubs"), *objSet) {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags(
|
flags(
|
||||||
"-shared",
|
"-shared",
|
||||||
"-o", ruleOut(), *ruleInAll(),
|
"-o", ruleOut(), *ruleInAll(),
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ native {
|
|||||||
val host = rootProject.project(":kotlin-native").extra["hostName"]
|
val host = rootProject.project(":kotlin-native").extra["hostName"]
|
||||||
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
|
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
|
||||||
val cflags = mutableListOf("-I$hostLibffiDir/include",
|
val cflags = mutableListOf("-I$hostLibffiDir/include",
|
||||||
*platformManager.hostPlatform.clang.hostCompilerArgsForJni)
|
*platformManager.hostPlatform.clangForJni.hostCompilerArgsForJni)
|
||||||
suffixes {
|
suffixes {
|
||||||
(".c" to ".$obj") {
|
(".c" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangC("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangC("").toTypedArray())
|
||||||
flags( *cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
flags( *cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ native {
|
|||||||
val objSet = sourceSets["callbacks"]!!.transform(".c" to ".$obj")
|
val objSet = sourceSets["callbacks"]!!.transform(".c" to ".$obj")
|
||||||
|
|
||||||
target(solib("callbacks"), objSet) {
|
target(solib("callbacks"), objSet) {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags("-shared",
|
flags("-shared",
|
||||||
"-o",ruleOut(), *ruleInAll(),
|
"-o",ruleOut(), *ruleInAll(),
|
||||||
"-L${project(":kotlin-native:libclangext").buildDir}",
|
"-L${project(":kotlin-native:libclangext").buildDir}",
|
||||||
|
|||||||
+10
-10
@@ -16,16 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.native.interop.tool
|
package org.jetbrains.kotlin.native.interop.tool
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.*
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
|
||||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
|
||||||
import org.jetbrains.kotlin.konan.target.customerDistribution
|
|
||||||
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
|
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
||||||
import org.jetbrains.kotlin.native.interop.indexer.Language
|
import org.jetbrains.kotlin.native.interop.indexer.Language
|
||||||
|
|
||||||
class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
class ToolConfig(userProvidedTargetName: String?, private val flavor: KotlinPlatform) {
|
||||||
|
|
||||||
private val konanHome = KonanHomeProvider.determineKonanHome()
|
private val konanHome = KonanHomeProvider.determineKonanHome()
|
||||||
private val distribution = customerDistribution(konanHome)
|
private val distribution = customerDistribution(konanHome)
|
||||||
@@ -36,7 +33,10 @@ class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
|||||||
|
|
||||||
private val platform = platformManager.platform(target)
|
private val platform = platformManager.platform(target)
|
||||||
|
|
||||||
val clang = platform.clang
|
val clang = when (flavor) {
|
||||||
|
KotlinPlatform.JVM -> platform.clangForJni
|
||||||
|
KotlinPlatform.NATIVE -> platform.clang
|
||||||
|
}
|
||||||
|
|
||||||
val substitutions = defaultTargetSubstitutions(target)
|
val substitutions = defaultTargetSubstitutions(target)
|
||||||
|
|
||||||
@@ -44,12 +44,12 @@ class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
|||||||
|
|
||||||
fun getDefaultCompilerOptsForLanguage(language: Language): List<String> = when (language) {
|
fun getDefaultCompilerOptsForLanguage(language: Language): List<String> = when (language) {
|
||||||
Language.C,
|
Language.C,
|
||||||
Language.OBJECTIVE_C -> platform.clang.libclangArgs.toList()
|
Language.OBJECTIVE_C -> clang.libclangArgs.toList()
|
||||||
Language.CPP -> platform.clang.libclangXXArgs.toList()
|
Language.CPP -> clang.libclangXXArgs.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
val platformCompilerOpts = if (flavor == KotlinPlatform.JVM)
|
val platformCompilerOpts = if (clang is ClangArgs.Jni)
|
||||||
platform.clang.hostCompilerArgsForJni.toList() else emptyList()
|
clang.hostCompilerArgsForJni.toList() else emptyList()
|
||||||
|
|
||||||
val llvmHome = platform.absoluteLlvmHome
|
val llvmHome = platform.absoluteLlvmHome
|
||||||
val sysRoot = platform.absoluteTargetSysRoot
|
val sysRoot = platform.absoluteTargetSysRoot
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ native {
|
|||||||
}
|
}
|
||||||
suffixes {
|
suffixes {
|
||||||
(".cpp" to ".$obj") {
|
(".cpp" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ native {
|
|||||||
}
|
}
|
||||||
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
||||||
target(lib("clangext"), objSet) {
|
target(lib("clangext"), objSet) {
|
||||||
tool(*platformManager.hostPlatform.clang.llvmAr("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.llvmAr("").toTypedArray())
|
||||||
flags("-qv", ruleOut(), *ruleInAll())
|
flags("-qv", ruleOut(), *ruleInAll())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ native {
|
|||||||
}
|
}
|
||||||
suffixes {
|
suffixes {
|
||||||
(".cpp" to ".$obj") {
|
(".cpp" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ native {
|
|||||||
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
||||||
|
|
||||||
target(lib("coverageMapping"), objSet) {
|
target(lib("coverageMapping"), objSet) {
|
||||||
tool(*platformManager.hostPlatform.clang.llvmAr("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.llvmAr("").toTypedArray())
|
||||||
flags("-qv", ruleOut(), *ruleInAll())
|
flags("-qv", ruleOut(), *ruleInAll())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ val llvmDir = project.findProperty("llvmDir")
|
|||||||
|
|
||||||
native {
|
native {
|
||||||
val obj = if (HostManager.hostIsMingw) "obj" else "o"
|
val obj = if (HostManager.hostIsMingw) "obj" else "o"
|
||||||
val host = rootProject.project(":kotlin-native").extra["hostName"]
|
|
||||||
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
|
|
||||||
val cxxflags = mutableListOf(
|
val cxxflags = mutableListOf(
|
||||||
"--std=c++17",
|
"--std=c++17",
|
||||||
"-I${llvmDir}/include",
|
"-I${llvmDir}/include",
|
||||||
@@ -37,7 +35,7 @@ native {
|
|||||||
)
|
)
|
||||||
suffixes {
|
suffixes {
|
||||||
(".cpp" to ".$obj") {
|
(".cpp" to ".$obj") {
|
||||||
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.clangCXX("").toTypedArray())
|
||||||
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
flags(*cxxflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ native {
|
|||||||
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
val objSet = sourceSets["main"]!!.transform(".cpp" to ".$obj")
|
||||||
|
|
||||||
target(lib("debugInfo"), objSet) {
|
target(lib("debugInfo"), objSet) {
|
||||||
tool(*platformManager.hostPlatform.clang.llvmAr("").toTypedArray())
|
tool(*platformManager.hostPlatform.clangForJni.llvmAr("").toTypedArray())
|
||||||
flags("-qv", ruleOut(), *ruleInAll())
|
flags("-qv", ruleOut(), *ruleInAll())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-11
@@ -31,7 +31,10 @@ internal object Android {
|
|||||||
"android-${API}/arch-${architectureMap.getValue(target)}"
|
"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 absoluteTargetToolchain = configurables.absoluteTargetToolchain
|
||||||
private val absoluteTargetSysRoot = configurables.absoluteTargetSysRoot
|
private val absoluteTargetSysRoot = configurables.absoluteTargetSysRoot
|
||||||
@@ -152,16 +155,6 @@ class ClangArgs(private val configurables: Configurables) {
|
|||||||
|
|
||||||
val clangPaths = listOf("$absoluteLlvmHome/bin", binDir)
|
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.
|
* 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 clangCXX(vararg userArgs: String) = targetClangXXCmd + userArgs.asList()
|
||||||
|
|
||||||
fun llvmAr(vararg userArgs: String) = targetArCmd + 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)
|
class Platform(val configurables: Configurables)
|
||||||
: Configurables by configurables {
|
: Configurables by configurables {
|
||||||
|
|
||||||
val clang by lazy {
|
val clang: ClangArgs.Native by lazy {
|
||||||
ClangArgs(configurables)
|
ClangArgs.Native(configurables)
|
||||||
}
|
}
|
||||||
val linker by lazy {
|
|
||||||
|
val clangForJni: ClangArgs.Jni by lazy {
|
||||||
|
ClangArgs.Jni(configurables)
|
||||||
|
}
|
||||||
|
|
||||||
|
val linker: LinkerFlags by lazy {
|
||||||
linker(configurables)
|
linker(configurables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user