[Native] Adapt Skia interop to ClangArgs refactoring.
This commit is contained in:
+6
-2
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.konan.target.customerDistribution
|
||||
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
||||
import org.jetbrains.kotlin.native.interop.indexer.Language
|
||||
|
||||
class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
||||
|
||||
@@ -41,8 +42,11 @@ class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
||||
|
||||
fun downloadDependencies() = platform.downloadDependencies()
|
||||
|
||||
val defaultCompilerOpts =
|
||||
platform.clang.targetLibclangArgs.toList()
|
||||
fun getDefaultCompilerOptsForLanguage(language: Language): List<String> = when (language) {
|
||||
Language.C,
|
||||
Language.OBJECTIVE_C -> platform.clang.libclangArgs.toList()
|
||||
Language.CPP -> platform.clang.libclangXXArgs.toList()
|
||||
}
|
||||
|
||||
val platformCompilerOpts = if (flavor == KotlinPlatform.JVM)
|
||||
platform.clang.hostCompilerArgsForJni.toList() else emptyList()
|
||||
|
||||
+5
-6
@@ -229,10 +229,6 @@ private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArgum
|
||||
val verbose = cinteropArguments.verbose
|
||||
|
||||
val entryPoint = def.config.entryPoints.atMostOne()
|
||||
val linkerOpts =
|
||||
def.config.linkerOpts.toTypedArray() +
|
||||
tool.defaultCompilerOpts +
|
||||
additionalLinkerOpts
|
||||
val linkerName = cinteropArguments.linker ?: def.config.linker
|
||||
val linker = "${tool.llvmHome}/bin/$linkerName"
|
||||
val compiler = "${tool.llvmHome}/bin/clang"
|
||||
@@ -359,7 +355,10 @@ private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArgum
|
||||
val compilerCmd = arrayOf(compiler, *compilerArgs,
|
||||
"-c", outCFile.absolutePath, "-o", outOFile.absolutePath)
|
||||
runCmd(compilerCmd, verbose)
|
||||
|
||||
val linkerOpts =
|
||||
def.config.linkerOpts.toTypedArray() +
|
||||
tool.getDefaultCompilerOptsForLanguage(library.language) +
|
||||
additionalLinkerOpts
|
||||
val outLib = File(nativeLibsDir, System.mapLibraryName(libName))
|
||||
val linkerCmd = arrayOf(linker,
|
||||
outOFile.absolutePath, "-shared", "-o", outLib.absolutePath,
|
||||
@@ -477,7 +476,7 @@ internal fun buildNativeLibrary(
|
||||
val language = selectNativeLanguage(def.config)
|
||||
val compilerOpts: List<String> = mutableListOf<String>().apply {
|
||||
addAll(def.config.compilerOpts)
|
||||
addAll(tool.defaultCompilerOpts)
|
||||
addAll(tool.getDefaultCompilerOptsForLanguage(language))
|
||||
// We compile with -O2 because Clang may insert inline asm in bitcode at -O0.
|
||||
// It is undesirable in case of watchos_arm64 since we target armv7k
|
||||
// for this target instead of arm64_32 because it is not supported in LLVM 8.
|
||||
|
||||
@@ -57,7 +57,6 @@ externalStdlibTestsDir.mkdirs()
|
||||
|
||||
ext.platformManager = project.project(":kotlin-native").platformManager
|
||||
ext.target = platformManager.targetManager(project.testTarget).target
|
||||
ext.llvmHome = platformManager.platform(target).configurables.absoluteLlvmHome
|
||||
|
||||
ext.testLibraryDir = "${ext.testOutputRoot}/klib/platform/${project.target.name}"
|
||||
|
||||
@@ -3825,26 +3824,14 @@ createInterop("leakMemoryWithRunningThread") {
|
||||
}
|
||||
|
||||
createInterop("cppClass") {
|
||||
if (isAppleTarget(project)) {
|
||||
// TODO: For cpp we need a header with `new`.
|
||||
it.extraOpts "-compiler-option", "-I$llvmHome/include/c++/v1"
|
||||
}
|
||||
it.defFile 'interop/cpp/cppClass.def'
|
||||
}
|
||||
|
||||
createInterop("cppTypes") {
|
||||
if (isAppleTarget(project)) {
|
||||
// TODO: For cpp we need a header with `new`.
|
||||
it.extraOpts "-compiler-option", "-I$llvmHome/include/c++/v1"
|
||||
}
|
||||
it.defFile 'interop/cpp/types.def'
|
||||
}
|
||||
|
||||
createInterop("cppSkia") {
|
||||
if (PlatformInfo.isMac()) {
|
||||
// TODO: For cpp we need a header with `new`.
|
||||
it.extraOpts "-compiler-option", "-I$llvmHome/include/c++/v1"
|
||||
}
|
||||
it.defFile 'interop/cpp/skia.def'
|
||||
}
|
||||
|
||||
|
||||
+19
-2
@@ -179,12 +179,29 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
|
||||
val clangArgsForKonanSources =
|
||||
clangXXArgs + clangArgsSpecificForKonanSources
|
||||
|
||||
val targetLibclangArgs: List<String> =
|
||||
private val libclangSpecificArgs =
|
||||
// libclang works not exactly the same way as the clang binary and
|
||||
// (in particular) uses different default header search path.
|
||||
// See e.g. http://lists.llvm.org/pipermail/cfe-dev/2013-November/033680.html
|
||||
// We workaround the problem with -isystem flag below.
|
||||
listOf("-isystem", "$absoluteLlvmHome/lib/clang/$llvmVersion/include", *clangArgs)
|
||||
// TODO: Revise after update to LLVM 10.
|
||||
listOf("-isystem", "$absoluteLlvmHome/lib/clang/$llvmVersion/include")
|
||||
|
||||
/**
|
||||
* libclang args for plain C and Objective-C.
|
||||
*
|
||||
* Note that it's different from [clangArgs].
|
||||
*/
|
||||
val libclangArgs: List<String> =
|
||||
libclangSpecificArgs + clangArgs
|
||||
|
||||
/**
|
||||
* libclang args for C++.
|
||||
*
|
||||
* Note that it's different from [clangXXArgs].
|
||||
*/
|
||||
val libclangXXArgs: List<String> =
|
||||
libclangSpecificArgs + clangXXArgs
|
||||
|
||||
private val targetClangCmd
|
||||
= listOf("${absoluteLlvmHome}/bin/clang") + clangArgs
|
||||
|
||||
Reference in New Issue
Block a user