Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Kotlin" />
<orderEntry type="module" module-name="cli" />
<orderEntry type="module" module-name="frontend" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="ir.psi2ir" />
<orderEntry type="module" module-name="ir.tree" />
<orderEntry type="module" module-name="frontend.java" />
</component>
</module>
@@ -0,0 +1,460 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package org.jetbrains.kotlin.cli.bc
import com.intellij.openapi.Disposable
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.konan.CURRENT
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.util.profile
import org.jetbrains.kotlin.utils.KotlinPaths
private class K2NativeCompilerPerformanceManager: CommonCompilerPerformanceManager("Kotlin to Native Compiler")
class K2Native : CLICompiler<K2NativeCompilerArguments>() {
override fun MutableList<String>.addPlatformOptions(arguments: K2NativeCompilerArguments) {}
override fun createMetadataVersion(versionArray: IntArray): BinaryVersion = KlibMetadataVersion(*versionArray)
override val performanceManager:CommonCompilerPerformanceManager by lazy {
K2NativeCompilerPerformanceManager()
}
override fun doExecute(@NotNull arguments: K2NativeCompilerArguments,
@NotNull configuration: CompilerConfiguration,
@NotNull rootDisposable: Disposable,
@Nullable paths: KotlinPaths?): ExitCode {
if (arguments.version) {
println("Kotlin/Native: ${CompilerVersion.CURRENT}")
return ExitCode.OK
}
val pluginLoadResult =
PluginCliParser.loadPluginsSafe(arguments.pluginClasspaths, arguments.pluginOptions, configuration)
if (pluginLoadResult != ExitCode.OK) return pluginLoadResult
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
val project = environment.project
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) ?: MessageCollector.NONE
configuration.put(CLIConfigurationKeys.PHASE_CONFIG, createPhaseConfig(toplevelPhase, arguments, messageCollector))
val konanConfig = KonanConfig(project, configuration)
val enoughArguments = arguments.freeArgs.isNotEmpty() || arguments.isUsefulWithoutFreeArgs
if (!enoughArguments) {
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
}
/* Set default version of metadata version */
val metadataVersionString = arguments.metadataVersion
if (metadataVersionString == null) {
configuration.put(CommonConfigurationKeys.METADATA_VERSION, KlibMetadataVersion.INSTANCE)
}
try {
runTopLevelPhases(konanConfig, environment)
} catch (e: KonanCompilationException) {
return ExitCode.COMPILATION_ERROR
} catch (e: Throwable) {
configuration.report(ERROR, """
|Compilation failed: ${e.message}
| * Source files: ${environment.getSourceFiles().joinToString(transform = KtFile::getName)}
| * Compiler version info: Konan: ${CompilerVersion.CURRENT} / Kotlin: ${KotlinVersion.CURRENT}
| * Output kind: ${configuration.get(KonanConfigKeys.PRODUCE)}
""".trimMargin())
throw e
}
return ExitCode.OK
}
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
get() = listTargets || listPhases || checkDependencies || !includes.isNullOrEmpty() ||
!librariesToCache.isNullOrEmpty() || libraryToAddToCache != null
fun Array<String>?.toNonNullList(): List<String> {
return this?.asList<String>() ?: listOf<String>()
}
// It is executed before doExecute().
override fun setupPlatformSpecificArgumentsAndServices(
configuration: CompilerConfiguration,
arguments : K2NativeCompilerArguments,
services : Services) {
val commonSources = arguments.commonSources?.toSet().orEmpty()
arguments.freeArgs.forEach {
configuration.addKotlinSourceRoot(it, it in commonSources)
}
with(KonanConfigKeys) {
with(configuration) {
arguments.kotlinHome?.let { put(KONAN_HOME, it) }
put(NODEFAULTLIBS, arguments.nodefaultlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
put(NOENDORSEDLIBS, arguments.noendorsedlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
put(NOSTDLIB, arguments.nostdlib || !arguments.libraryToAddToCache.isNullOrEmpty())
put(NOPACK, arguments.nopack)
put(NOMAIN, arguments.nomain)
put(LIBRARY_FILES,
arguments.libraries.toNonNullList())
put(LINKER_ARGS, arguments.linkerArguments.toNonNullList() +
arguments.singleLinkerArguments.toNonNullList())
arguments.moduleName?.let{ put(MODULE_NAME, it) }
arguments.target?.let{ put(TARGET, it) }
put(INCLUDED_BINARY_FILES,
arguments.includeBinaries.toNonNullList())
put(NATIVE_LIBRARY_FILES,
arguments.nativeLibraries.toNonNullList())
put(REPOSITORIES,
arguments.repositories.toNonNullList())
// TODO: Collect all the explicit file names into an object
// and teach the compiler to work with temporaries and -save-temps.
arguments.outputName ?.let { put(OUTPUT, it) }
val outputKind = CompilerOutputKind.valueOf(
(arguments.produce ?: "program").toUpperCase())
put(PRODUCE, outputKind)
put(METADATA_KLIB, arguments.metadataKlib)
arguments.libraryVersion ?. let { put(LIBRARY_VERSION, it) }
arguments.mainPackage ?.let{ put(ENTRY, it) }
arguments.manifestFile ?.let{ put(MANIFEST_FILE, it) }
arguments.runtimeFile ?.let{ put(RUNTIME_FILE, it) }
arguments.temporaryFilesDir?.let { put(TEMPORARY_FILES_DIR, it) }
put(LIST_TARGETS, arguments.listTargets)
put(OPTIMIZATION, arguments.optimization)
put(DEBUG, arguments.debug)
// TODO: remove after 1.4 release.
if (arguments.lightDebugDeprecated) {
configuration.report(WARNING,
"-Xg0 is now deprecated and skipped by compiler. Light debug information is enabled by default for Darwin platforms." +
" For other targets, please, use `-Xadd-light-debug=enable` instead.")
}
putIfNotNull(LIGHT_DEBUG, when (val it = arguments.lightDebugString) {
"enable" -> true
"disable" -> false
null -> null
else -> {
configuration.report(ERROR, "Unsupported -Xadd-light-debug= value: $it. Possible values are 'enable'/'disable'")
null
}
})
put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind))
put(OVERRIDE_CLANG_OPTIONS, arguments.clangOptions.toNonNullList())
put(ALLOCATION_MODE, arguments.allocator)
put(PRINT_IR, arguments.printIr)
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
put(PRINT_DESCRIPTORS, arguments.printDescriptors)
put(PRINT_LOCATIONS, arguments.printLocations)
put(PRINT_BITCODE, arguments.printBitCode)
put(PURGE_USER_LIBS, arguments.purgeUserLibs)
if (arguments.verifyCompiler != null)
put(VERIFY_COMPILER, arguments.verifyCompiler == "true")
put(VERIFY_BITCODE, arguments.verifyBitCode)
put(ENABLED_PHASES,
arguments.enablePhases.toNonNullList())
put(DISABLED_PHASES,
arguments.disablePhases.toNonNullList())
put(LIST_PHASES, arguments.listPhases)
put(COMPATIBLE_COMPILER_VERSIONS,
arguments.compatibleCompilerVersions.toNonNullList())
put(ENABLE_ASSERTIONS, arguments.enableAssertions)
put(MEMORY_MODEL, when (arguments.memoryModel) {
"relaxed" -> {
configuration.report(STRONG_WARNING, "Relaxed memory model is not yet fully functional")
MemoryModel.RELAXED
}
"strict" -> MemoryModel.STRICT
"experimental" -> MemoryModel.EXPERIMENTAL
else -> {
configuration.report(ERROR, "Unsupported memory model ${arguments.memoryModel}")
MemoryModel.STRICT
}
})
when {
arguments.generateWorkerTestRunner -> put(GENERATE_TEST_RUNNER, TestRunnerKind.WORKER)
arguments.generateTestRunner -> put(GENERATE_TEST_RUNNER, TestRunnerKind.MAIN_THREAD)
arguments.generateNoExitTestRunner -> put(GENERATE_TEST_RUNNER, TestRunnerKind.MAIN_THREAD_NO_EXIT)
else -> put(GENERATE_TEST_RUNNER, TestRunnerKind.NONE)
}
// We need to download dependencies only if we use them ( = there are files to compile).
put(
CHECK_DEPENDENCIES,
configuration.kotlinSourceRoots.isNotEmpty()
|| !arguments.includes.isNullOrEmpty()
|| arguments.checkDependencies
)
if (arguments.friendModules != null)
put(FRIEND_MODULES, arguments.friendModules!!.split(File.pathSeparator).filterNot(String::isEmpty))
put(EXPORTED_LIBRARIES, selectExportedLibraries(configuration, arguments, outputKind))
put(INCLUDED_LIBRARIES, selectIncludes(configuration, arguments, outputKind))
put(FRAMEWORK_IMPORT_HEADERS, arguments.frameworkImportHeaders.toNonNullList())
arguments.emitLazyObjCHeader?.let { put(EMIT_LAZY_OBJC_HEADER_FILE, it) }
put(BITCODE_EMBEDDING_MODE, selectBitcodeEmbeddingMode(this, arguments))
put(DEBUG_INFO_VERSION, arguments.debugInfoFormatVersion.toInt())
put(COVERAGE, arguments.coverage)
put(LIBRARIES_TO_COVER, arguments.coveredLibraries.toNonNullList())
arguments.coverageFile?.let { put(PROFRAW_PATH, it) }
put(OBJC_GENERICS, !arguments.noObjcGenerics)
put(DEBUG_PREFIX_MAP, parseDebugPrefixMap(arguments, configuration))
put(LIBRARIES_TO_CACHE, parseLibrariesToCache(arguments, configuration, outputKind))
val libraryToAddToCache = parseLibraryToAddToCache(arguments, configuration, outputKind)
if (libraryToAddToCache != null && !arguments.outputName.isNullOrEmpty())
configuration.report(ERROR, "$ADD_CACHE already implicitly sets output file name")
val cacheDirectories = arguments.cacheDirectories.toNonNullList()
libraryToAddToCache?.let { put(LIBRARY_TO_ADD_TO_CACHE, it) }
put(CACHE_DIRECTORIES, cacheDirectories)
put(CACHED_LIBRARIES, parseCachedLibraries(arguments, configuration))
parseShortModuleName(arguments, configuration, outputKind)?.let {
put(SHORT_MODULE_NAME, it)
}
put(DISABLE_FAKE_OVERRIDE_VALIDATOR, arguments.disableFakeOverrideValidator)
putIfNotNull(PRE_LINK_CACHES, parsePreLinkCachesValue(configuration, arguments.preLinkCaches))
}
}
}
override fun createArguments() = K2NativeCompilerArguments()
override fun executableScriptFileName() = "kotlinc-native"
companion object {
@JvmStatic fun main(args: Array<String>) {
profile("Total compiler main()") {
doMain(K2Native(), args)
}
}
@JvmStatic fun mainNoExit(args: Array<String>) {
profile("Total compiler main()") {
if (doMainNoExit(K2Native(), args) != ExitCode.OK) {
throw KonanCompilationException("Compilation finished with errors")
}
}
}
@JvmStatic fun mainNoExitWithGradleRenderer(args: Array<String>) {
profile("Total compiler main()") {
if (doMainNoExit(K2Native(), args, MessageRenderer.GRADLE_STYLE) != ExitCode.OK) {
throw KonanCompilationException("Compilation finished with errors")
}
}
}
}
}
private fun selectFrameworkType(
configuration: CompilerConfiguration,
arguments: K2NativeCompilerArguments,
outputKind: CompilerOutputKind
): Boolean {
return if (outputKind != CompilerOutputKind.FRAMEWORK && arguments.staticFramework) {
configuration.report(
STRONG_WARNING,
"'$STATIC_FRAMEWORK_FLAG' is only supported when producing frameworks, " +
"but the compiler is producing ${outputKind.name.toLowerCase()}"
)
false
} else {
arguments.staticFramework
}
}
private fun parsePreLinkCachesValue(
configuration: CompilerConfiguration,
value: String?
): Boolean? = when (value) {
"enable" -> true
"disable" -> false
null -> null
else -> {
configuration.report(ERROR, "Unsupported `-Xpre-link-caches` value: $value. Possible values are 'enable'/'disable'")
null
}
}
private fun selectBitcodeEmbeddingMode(
configuration: CompilerConfiguration,
arguments: K2NativeCompilerArguments
): BitcodeEmbedding.Mode = when {
arguments.embedBitcodeMarker -> {
if (arguments.embedBitcode) {
configuration.report(
STRONG_WARNING,
"'$EMBED_BITCODE_FLAG' is ignored because '$EMBED_BITCODE_MARKER_FLAG' is specified"
)
}
BitcodeEmbedding.Mode.MARKER
}
arguments.embedBitcode -> {
BitcodeEmbedding.Mode.FULL
}
else -> BitcodeEmbedding.Mode.NONE
}
private fun selectExportedLibraries(
configuration: CompilerConfiguration,
arguments: K2NativeCompilerArguments,
outputKind: CompilerOutputKind
): List<String> {
val exportedLibraries = arguments.exportedLibraries?.toList().orEmpty()
return if (exportedLibraries.isNotEmpty() && outputKind != CompilerOutputKind.FRAMEWORK &&
outputKind != CompilerOutputKind.STATIC && outputKind != CompilerOutputKind.DYNAMIC) {
configuration.report(STRONG_WARNING,
"-Xexport-library is only supported when producing frameworks or native libraries, " +
"but the compiler is producing ${outputKind.name.toLowerCase()}")
emptyList()
} else {
exportedLibraries
}
}
private fun selectIncludes(
configuration: CompilerConfiguration,
arguments: K2NativeCompilerArguments,
outputKind: CompilerOutputKind
): List<String> {
val includes = arguments.includes?.toList().orEmpty()
return if (includes.isNotEmpty() && outputKind == CompilerOutputKind.LIBRARY) {
configuration.report(
ERROR,
"The $INCLUDE_ARG flag is not supported when producing ${outputKind.name.toLowerCase()}"
)
emptyList()
} else {
includes
}
}
private fun parseCachedLibraries(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration
): Map<String, String> = arguments.cachedLibraries?.asList().orEmpty().mapNotNull {
val libraryAndCache = it.split(",")
if (libraryAndCache.size != 2) {
configuration.report(
ERROR,
"incorrect $CACHED_LIBRARY format: expected '<library>,<cache>', got '$it'"
)
null
} else {
libraryAndCache[0] to libraryAndCache[1]
}
}.toMap()
private fun parseLibrariesToCache(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
outputKind: CompilerOutputKind
): List<String> {
val input = arguments.librariesToCache?.asList().orEmpty()
return if (input.isNotEmpty() && !outputKind.isCache) {
configuration.report(ERROR, "$MAKE_CACHE can't be used when not producing cache")
emptyList()
} else if (input.isNotEmpty() && !arguments.libraryToAddToCache.isNullOrEmpty()) {
configuration.report(ERROR, "supplied both $MAKE_CACHE and $ADD_CACHE options")
emptyList()
} else {
input
}
}
private fun parseLibraryToAddToCache(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
outputKind: CompilerOutputKind
): String? {
val input = arguments.libraryToAddToCache
return if (input != null && !outputKind.isCache) {
configuration.report(ERROR, "$ADD_CACHE can't be used when not producing cache")
null
} else {
input
}
}
// TODO: Support short names for current module in ObjC export and lift this limitation.
private fun parseShortModuleName(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
outputKind: CompilerOutputKind
): String? {
val input = arguments.shortModuleName
return if (input != null && outputKind != CompilerOutputKind.LIBRARY) {
configuration.report(
STRONG_WARNING,
"$SHORT_MODULE_NAME_ARG is only supported when producing a Kotlin library, " +
"but the compiler is producing ${outputKind.name.toLowerCase()}"
)
null
} else {
input
}
}
private fun parseDebugPrefixMap(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration
): Map<String, String> = arguments.debugPrefixMap?.asList().orEmpty().mapNotNull {
val libraryAndCache = it.split("=")
if (libraryAndCache.size != 2) {
configuration.report(
ERROR,
"incorrect debug prefix map format: expected '<old>=<new>', got '$it'"
)
null
} else {
libraryAndCache[0] to libraryAndCache[1]
}
}.toMap()
fun main(args: Array<String>) = K2Native.main(args)
fun mainNoExitWithGradleRenderer(args: Array<String>) = K2Native.mainNoExitWithGradleRenderer(args)
@@ -0,0 +1,308 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package org.jetbrains.kotlin.cli.bc
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.Argument
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.config.*
class K2NativeCompilerArguments : CommonCompilerArguments() {
// First go the options interesting to the general public.
// Prepend them with a single dash.
// Keep the list lexically sorted.
@Argument(value = "-enable-assertions", deprecatedName = "-enable_assertions", shortName = "-ea", description = "Enable runtime assertions in generated code")
var enableAssertions: Boolean = false
@Argument(value = "-g", description = "Enable emitting debug information")
var debug: Boolean = false
@Argument(value = "-generate-test-runner", deprecatedName = "-generate_test_runner",
shortName = "-tr", description = "Produce a runner for unit tests")
var generateTestRunner = false
@Argument(value = "-generate-worker-test-runner",
shortName = "-trw", description = "Produce a worker runner for unit tests")
var generateWorkerTestRunner = false
@Argument(value = "-generate-no-exit-test-runner",
shortName = "-trn", description = "Produce a runner for unit tests not forcing exit")
var generateNoExitTestRunner = false
@Argument(value="-include-binary", deprecatedName = "-includeBinary", shortName = "-ib", valueDescription = "<path>", description = "Pack external binary within the klib")
var includeBinaries: Array<String>? = null
@Argument(value = "-library", shortName = "-l", valueDescription = "<path>", description = "Link with the library", delimiter = "")
var libraries: Array<String>? = null
@Argument(value = "-library-version", shortName = "-lv", valueDescription = "<version>", description = "Set library version")
var libraryVersion: String? = null
@Argument(value = "-list-targets", deprecatedName = "-list_targets", description = "List available hardware targets")
var listTargets: Boolean = false
@Argument(value = "-manifest", valueDescription = "<path>", description = "Provide a maniferst addend file")
var manifestFile: String? = null
@Argument(value="-memory-model", valueDescription = "<model>", description = "Memory model to use, 'strict', 'relaxed' and 'experimental' are currently supported")
var memoryModel: String? = "strict"
@Argument(value="-module-name", deprecatedName = "-module_name", valueDescription = "<name>", description = "Specify a name for the compilation module")
var moduleName: String? = null
@Argument(value = "-native-library", deprecatedName = "-nativelibrary", shortName = "-nl",
valueDescription = "<path>", description = "Include the native bitcode library", delimiter = "")
var nativeLibraries: Array<String>? = null
@Argument(value = "-no-default-libs", deprecatedName = "-nodefaultlibs", description = "Don't link the libraries from dist/klib automatically")
var nodefaultlibs: Boolean = false
@Argument(value = "-no-endorsed-libs", description = "Don't link the endorsed libraries from dist automatically")
var noendorsedlibs: Boolean = false
@Argument(value = "-nomain", description = "Assume 'main' entry point to be provided by external libraries")
var nomain: Boolean = false
@Argument(value = "-nopack", description = "Don't pack the library into a klib file")
var nopack: Boolean = false
@Argument(value="-linker-options", deprecatedName = "-linkerOpts", valueDescription = "<arg>", description = "Pass arguments to linker", delimiter = " ")
var linkerArguments: Array<String>? = null
@Argument(value="-linker-option", valueDescription = "<arg>", description = "Pass argument to linker", delimiter = "")
var singleLinkerArguments: Array<String>? = null
@Argument(value = "-nostdlib", description = "Don't link with stdlib")
var nostdlib: Boolean = false
@Argument(value = "-opt", description = "Enable optimizations during compilation")
var optimization: Boolean = false
@Argument(value = "-output", shortName = "-o", valueDescription = "<name>", description = "Output name")
var outputName: String? = null
@Argument(value = "-entry", shortName = "-e", valueDescription = "<name>", description = "Qualified entry point name")
var mainPackage: String? = null
@Argument(value = "-produce", shortName = "-p",
valueDescription = "{program|static|dynamic|framework|library|bitcode}",
description = "Specify output file kind")
var produce: String? = null
@Argument(value = "-repo", shortName = "-r", valueDescription = "<path>", description = "Library search path")
var repositories: Array<String>? = null
@Argument(value = "-target", valueDescription = "<target>", description = "Set hardware target")
var target: String? = null
// The rest of the options are only interesting to the developers.
// Make sure to prepend them with -X.
// Keep the list lexically sorted.
@Argument(
value = "-Xcache-directory",
valueDescription = "<path>",
description = "Path to the directory containing caches",
delimiter = ""
)
var cacheDirectories: Array<String>? = null
@Argument(
value = CACHED_LIBRARY,
valueDescription = "<library path>,<cache path>",
description = "Comma-separated paths of a library and its cache",
delimiter = ""
)
var cachedLibraries: Array<String>? = null
@Argument(value="-Xcheck-dependencies", deprecatedName = "--check_dependencies", description = "Check dependencies and download the missing ones")
var checkDependencies: Boolean = false
@Argument(value="-Xcompatible-compiler-version", valueDescription = "<version>", description = "Assume the given compiler version to be binary compatible")
var compatibleCompilerVersions: Array<String>? = null
@Argument(value = EMBED_BITCODE_FLAG, description = "Embed LLVM IR bitcode as data")
var embedBitcode: Boolean = false
@Argument(value = EMBED_BITCODE_MARKER_FLAG, description = "Embed placeholder LLVM IR data as a marker")
var embedBitcodeMarker: Boolean = false
@Argument(value = "-Xemit-lazy-objc-header", description = "")
var emitLazyObjCHeader: String? = null
@Argument(value = "-Xenable", deprecatedName = "--enable", valueDescription = "<Phase>", description = "Enable backend phase")
var enablePhases: Array<String>? = null
@Argument(
value = "-Xexport-library",
valueDescription = "<path>",
description = "A library to be included into produced framework API.\n" +
"Must be one of libraries passed with '-library'",
delimiter = ""
)
var exportedLibraries: Array<String>? = null
@Argument(value="-Xdisable-fake-override-validator", description = "Disable IR fake override validator")
var disableFakeOverrideValidator: Boolean = false
@Argument(
value = "-Xframework-import-header",
valueDescription = "<header>",
description = "Add additional header import to framework header"
)
var frameworkImportHeaders: Array<String>? = null
@Argument(
value = "-Xadd-light-debug",
valueDescription = "{disable|enable}",
description = "Add light debug information for optimized builds. This option is skipped in debug builds.\n" +
"It's enabled by default on Darwin platforms where collected debug information is stored in .dSYM file.\n" +
"Currently option is disabled by default on other platforms."
)
var lightDebugString: String? = null
// TODO: remove after 1.4 release.
@Argument(value = "-Xg0", description = "Add light debug information. Deprecated option. Please use instead -Xadd-light-debug=enable")
var lightDebugDeprecated: Boolean = false
@Argument(
value = MAKE_CACHE,
valueDescription = "<path>",
description = "Path of the library to be compiled to cache",
delimiter = ""
)
var librariesToCache: Array<String>? = null
@Argument(
value = ADD_CACHE,
valueDescription = "<path>",
description = "Path to the library to be added to cache",
delimiter = ""
)
var libraryToAddToCache: String? = null
@Argument(value = "-Xprint-bitcode", deprecatedName = "--print_bitcode", description = "Print llvm bitcode")
var printBitCode: Boolean = false
@Argument(value = "-Xprint-descriptors", deprecatedName = "--print_descriptors", description = "Print descriptor tree")
var printDescriptors: Boolean = false
@Argument(value = "-Xprint-ir", deprecatedName = "--print_ir", description = "Print IR")
var printIr: Boolean = false
@Argument(value = "-Xprint-ir-with-descriptors", deprecatedName = "--print_ir_with_descriptors", description = "Print IR with descriptors")
var printIrWithDescriptors: Boolean = false
@Argument(value = "-Xprint-locations", deprecatedName = "--print_locations", description = "Print locations")
var printLocations: Boolean = false
@Argument(value="-Xpurge-user-libs", deprecatedName = "--purge_user_libs", description = "Don't link unused libraries even explicitly specified")
var purgeUserLibs: Boolean = false
@Argument(value = "-Xruntime", deprecatedName = "--runtime", valueDescription = "<path>", description = "Override standard 'runtime.bc' location")
var runtimeFile: String? = null
@Argument(
value = INCLUDE_ARG,
valueDescription = "<path>",
description = "A path to an intermediate library that should be processed in the same manner as source files"
)
var includes: Array<String>? = null
@Argument(
value = SHORT_MODULE_NAME_ARG,
valueDescription = "<name>",
description = "A short name used to denote this library in the IDE and in a generated Objective-C header"
)
var shortModuleName: String? = null
@Argument(value = STATIC_FRAMEWORK_FLAG, description = "Create a framework with a static library instead of a dynamic one")
var staticFramework: Boolean = false
@Argument(value = "-Xtemporary-files-dir", deprecatedName = "--temporary_files_dir", valueDescription = "<path>", description = "Save temporary files to the given directory")
var temporaryFilesDir: String? = null
@Argument(value = "-Xverify-bitcode", deprecatedName = "--verify_bitcode", description = "Verify llvm bitcode after each method")
var verifyBitCode: Boolean = false
@Argument(value = "-Xverify-compiler", description = "Verify compiler")
var verifyCompiler: String? = null
@Argument(
value = "-friend-modules",
valueDescription = "<path>",
description = "Paths to friend modules"
)
var friendModules: String? = null
@Argument(value = "-Xdebug-info-version", description = "generate debug info of given version (1, 2)")
var debugInfoFormatVersion: String = "1" /* command line parser doesn't accept kotlin.Int type */
@Argument(value = "-Xcoverage", description = "emit coverage")
var coverage: Boolean = false
@Argument(
value = "-Xlibrary-to-cover",
valueDescription = "<path>",
description = "Provide code coverage for the given library.\n" +
"Must be one of libraries passed with '-library'",
delimiter = ""
)
var coveredLibraries: Array<String>? = null
@Argument(value = "-Xcoverage-file", valueDescription = "<path>", description = "Save coverage information to the given file")
var coverageFile: String? = null
@Argument(value = "-Xno-objc-generics", description = "Disable generics support for framework header")
var noObjcGenerics: Boolean = false
@Argument(value="-Xoverride-clang-options", valueDescription = "<arg1,arg2,...>", description = "Explicit list of Clang options")
var clangOptions: Array<String>? = null
@Argument(value="-Xallocator", valueDescription = "std | mimalloc", description = "Allocator used in runtime")
var allocator: String = "std"
@Argument(value = "-Xmetadata-klib", description = "Produce a klib that only contains the declarations metadata")
var metadataKlib: Boolean = false
@Argument(value = "-Xdebug-prefix-map", valueDescription = "<old1=new1,old2=new2,...>", description = "Remap file source directory paths in debug info")
var debugPrefixMap: Array<String>? = null
@Argument(
value = "-Xpre-link-caches",
valueDescription = "{disable|enable}",
description = "Perform caches pre-link"
)
var preLinkCaches: String? = null
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> =
super.configureAnalysisFlags(collector).also {
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
it[AnalysisFlags.useExperimental] = useExperimental + listOf("kotlin.ExperimentalUnsignedTypes")
if (printIr)
phasesToDumpAfter = arrayOf("ALL")
}
override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) {
if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_4
|| languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4
) {
collector.report(
severity = CompilerMessageSeverity.ERROR,
message = "Native backend cannot be used with language or API version below 1.4"
)
}
}
}
const val EMBED_BITCODE_FLAG = "-Xembed-bitcode"
const val EMBED_BITCODE_MARKER_FLAG = "-Xembed-bitcode-marker"
const val STATIC_FRAMEWORK_FLAG = "-Xstatic-framework"
const val INCLUDE_ARG = "-Xinclude"
const val CACHED_LIBRARY = "-Xcached-library"
const val MAKE_CACHE = "-Xmake-cache"
const val ADD_CACHE = "-Xadd-cache"
const val SHORT_MODULE_NAME_ARG = "-Xshort-module-name"