[K/N] Add -Xllvm-variant` compiler option
We need a handle that allows user to pick `dev` variant instead of `user` one just in case. Additionally, I added a possibility to provide a path to an arbitrary LLVM distribution because it is useful for development purposes.
This commit is contained in:
@@ -353,6 +353,20 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
arguments.externalDependencies?.let { put(EXTERNAL_DEPENDENCIES, it) }
|
arguments.externalDependencies?.let { put(EXTERNAL_DEPENDENCIES, it) }
|
||||||
|
putIfNotNull(LLVM_VARIANT, when (val variant = arguments.llvmVariant) {
|
||||||
|
"user" -> LlvmVariant.User
|
||||||
|
"dev" -> LlvmVariant.Dev
|
||||||
|
null -> null
|
||||||
|
else -> {
|
||||||
|
val file = File(variant)
|
||||||
|
if (!file.exists) {
|
||||||
|
configuration.report(ERROR, "`-Xllvm-variant` should be `user`, `dev` or an absolute path. Got: $variant")
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
LlvmVariant.Custom(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -337,6 +337,13 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
)
|
)
|
||||||
var workerExceptionHandling: String? = null
|
var workerExceptionHandling: String? = null
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
value = "-Xllvm-variant",
|
||||||
|
valueDescription = "{dev|user}",
|
||||||
|
description = "Choose LLVM distribution which will be used during compilation."
|
||||||
|
)
|
||||||
|
var llvmVariant: String? = null
|
||||||
|
|
||||||
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> =
|
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> =
|
||||||
super.configureAnalysisFlags(collector, languageVersion).also {
|
super.configureAnalysisFlags(collector, languageVersion).also {
|
||||||
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
|
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
|
||||||
|
|||||||
+15
-6
@@ -29,12 +29,21 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|||||||
|
|
||||||
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
||||||
|
|
||||||
internal val distribution = Distribution(
|
internal val distribution = run {
|
||||||
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
val overridenProperties = mutableMapOf<String, String>().apply {
|
||||||
false,
|
configuration.get(KonanConfigKeys.OVERRIDE_KONAN_PROPERTIES)?.let(this::putAll)
|
||||||
configuration.get(KonanConfigKeys.RUNTIME_FILE),
|
configuration.get(KonanConfigKeys.LLVM_VARIANT)?.getKonanPropertiesEntry()?.let { (key, value) ->
|
||||||
configuration.get(KonanConfigKeys.OVERRIDE_KONAN_PROPERTIES)
|
put(key, value)
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Distribution(
|
||||||
|
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
||||||
|
false,
|
||||||
|
configuration.get(KonanConfigKeys.RUNTIME_FILE),
|
||||||
|
overridenProperties
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private val platformManager = PlatformManager(distribution)
|
private val platformManager = PlatformManager(distribution)
|
||||||
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
||||||
|
|||||||
+1
@@ -167,6 +167,7 @@ class KonanConfigKeys {
|
|||||||
val WORKER_EXCEPTION_HANDLING: CompilerConfigurationKey<WorkerExceptionHandling> = CompilerConfigurationKey.create("unhandled exception processing in Worker.executeAfter")
|
val WORKER_EXCEPTION_HANDLING: CompilerConfigurationKey<WorkerExceptionHandling> = CompilerConfigurationKey.create("unhandled exception processing in Worker.executeAfter")
|
||||||
val EXTERNAL_DEPENDENCIES: CompilerConfigurationKey<String?> =
|
val EXTERNAL_DEPENDENCIES: CompilerConfigurationKey<String?> =
|
||||||
CompilerConfigurationKey.create("use external dependencies to enhance IR linker error messages")
|
CompilerConfigurationKey.create("use external dependencies to enhance IR linker error messages")
|
||||||
|
val LLVM_VARIANT: CompilerConfigurationKey<LlvmVariant?> = CompilerConfigurationKey.create("llvm variant")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
|
||||||
|
sealed class LlvmVariant {
|
||||||
|
object User : LlvmVariant() {
|
||||||
|
override fun getKonanPropertiesEntry(): Pair<String, String> =
|
||||||
|
konanPropertiesKey to "\$llvm.${HostManager.hostName}.user"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Dev : LlvmVariant() {
|
||||||
|
override fun getKonanPropertiesEntry(): Pair<String, String> =
|
||||||
|
konanPropertiesKey to "\$llvm.${HostManager.hostName}.user"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Custom(val path: File) : LlvmVariant() {
|
||||||
|
override fun getKonanPropertiesEntry(): Pair<String, String> =
|
||||||
|
konanPropertiesKey to path.canonicalPath
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun getKonanPropertiesEntry(): Pair<String, String>
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val konanPropertiesKey: String by lazy {
|
||||||
|
"llvmHome.${HostManager.hostName}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user