[Native] Adapt Skia interop to ClangArgs refactoring.

This commit is contained in:
Sergey Bogolepov
2021-04-30 17:07:52 +07:00
committed by Space
parent f330d67740
commit 13464cce68
4 changed files with 30 additions and 23 deletions
@@ -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()
@@ -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.