[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) }
|
||||
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
|
||||
|
||||
@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> =
|
||||
super.configureAnalysisFlags(collector, languageVersion).also {
|
||||
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) {
|
||||
|
||||
internal val distribution = Distribution(
|
||||
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
||||
false,
|
||||
configuration.get(KonanConfigKeys.RUNTIME_FILE),
|
||||
configuration.get(KonanConfigKeys.OVERRIDE_KONAN_PROPERTIES)
|
||||
)
|
||||
internal val distribution = run {
|
||||
val overridenProperties = mutableMapOf<String, String>().apply {
|
||||
configuration.get(KonanConfigKeys.OVERRIDE_KONAN_PROPERTIES)?.let(this::putAll)
|
||||
configuration.get(KonanConfigKeys.LLVM_VARIANT)?.getKonanPropertiesEntry()?.let { (key, value) ->
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
Distribution(
|
||||
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
||||
false,
|
||||
configuration.get(KonanConfigKeys.RUNTIME_FILE),
|
||||
overridenProperties
|
||||
)
|
||||
}
|
||||
|
||||
private val platformManager = PlatformManager(distribution)
|
||||
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 EXTERNAL_DEPENDENCIES: CompilerConfigurationKey<String?> =
|
||||
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