diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index b2c8c39a8df..3387cb5b86c 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -152,6 +152,7 @@ class K2Native : CLICompiler() { put(DEBUG, arguments.debug) put(LIGHT_DEBUG, arguments.lightDebug) put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind)) + put(OVERRIDE_CLANG_OPTIONS, arguments.clangOptions.toNonNullList()) put(PRINT_IR, arguments.printIr) put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors) diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index effb906645c..303d69869b8 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -231,6 +231,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xobjc-generics", description = "Enable experimental generics support for framework header") var objcGenerics: Boolean = false + @Argument(value="-Xoverride-clang-options", valueDescription = "", description = "Explicit list of Clang options") + var clangOptions: Array? = null + override fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> = super.configureAnalysisFlags(collector).also { val useExperimental = it[AnalysisFlags.useExperimental] as List<*> diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BitcodeCompiler.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BitcodeCompiler.kt index fa785bb7085..eb6a75dfe22 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BitcodeCompiler.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BitcodeCompiler.kt @@ -18,6 +18,9 @@ internal class BitcodeCompiler(val context: Context) { private val optimize = context.shouldOptimize() private val debug = context.config.debug + private val overrideClangOptions = + context.configuration.getList(KonanConfigKeys.OVERRIDE_CLANG_OPTIONS) + private fun MutableList.addNonEmpty(elements: List) { addAll(elements.filter { it.isNotEmpty() }) } @@ -58,7 +61,8 @@ internal class BitcodeCompiler(val context: Context) { } else -> context.llvm.targetTriple } - val flags = mutableListOf().apply { + val flags = overrideClangOptions.takeIf(List::isNotEmpty) + ?: mutableListOf().apply { addNonEmpty(configurables.clangFlags) addNonEmpty(listOf("-triple", targetTriple)) if (configurables is ZephyrConfigurables) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index 822e99d4814..0f5a02b42e7 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -84,6 +84,8 @@ class KonanConfigKeys { = CompilerConfigurationKey.create("optimized compilation") val OUTPUT: CompilerConfigurationKey = CompilerConfigurationKey.create("program or library name") + val OVERRIDE_CLANG_OPTIONS: CompilerConfigurationKey> + = CompilerConfigurationKey.create("arguments for clang") val PRINT_BITCODE: CompilerConfigurationKey = CompilerConfigurationKey.create("print bitcode") val PRINT_DESCRIPTORS: CompilerConfigurationKey