Source libraries: Add a flag for source libraries
This commit is contained in:
committed by
Ilya Matveev
parent
6dc8aee429
commit
275e399068
@@ -70,11 +70,6 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
configuration.put(CommonConfigurationKeys.METADATA_VERSION, KonanMetadataVersion.INSTANCE)
|
||||
}
|
||||
|
||||
if (konanConfig.linkOnly) {
|
||||
configuration.report(WARNING, "You have not specified any source files. " +
|
||||
"Only libraries will be used to produce the output binary.")
|
||||
}
|
||||
|
||||
try {
|
||||
runTopLevelPhases(konanConfig, environment)
|
||||
} catch (e: KonanCompilationException) {
|
||||
@@ -95,7 +90,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
}
|
||||
|
||||
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
|
||||
get() = this.listTargets || this.listPhases || this.checkDependencies || this.libraries?.isNotEmpty() ?: false
|
||||
get() = listTargets || listPhases || checkDependencies || !sourceLibraries.isNullOrEmpty()
|
||||
|
||||
fun Array<String>?.toNonNullList(): List<String> {
|
||||
return this?.asList<String>() ?: listOf<String>()
|
||||
@@ -195,7 +190,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
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, if (configuration.kotlinSourceRoots.isNotEmpty()) {
|
||||
put(CHECK_DEPENDENCIES, if (configuration.kotlinSourceRoots.isNotEmpty() || !arguments.sourceLibraries.isNullOrEmpty()) {
|
||||
true
|
||||
} else {
|
||||
arguments.checkDependencies
|
||||
@@ -204,6 +199,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
put(FRIEND_MODULES, arguments.friendModules!!.split(File.pathSeparator).filterNot(String::isEmpty))
|
||||
|
||||
put(EXPORTED_LIBRARIES, selectExportedLibraries(configuration, arguments, outputKind))
|
||||
put(SOURCE_LIBRARIES, selectSourceLibraries(configuration, arguments, outputKind))
|
||||
put(FRAMEWORK_IMPORT_HEADERS, arguments.frameworkImportHeaders.toNonNullList())
|
||||
arguments.emitLazyObjCHeader?.let { put(EMIT_LAZY_OBJC_HEADER_FILE, it) }
|
||||
|
||||
@@ -305,5 +301,22 @@ private fun selectExportedLibraries(
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectSourceLibraries(
|
||||
configuration: CompilerConfiguration,
|
||||
arguments: K2NativeCompilerArguments,
|
||||
outputKind: CompilerOutputKind
|
||||
): List<String> {
|
||||
val sourceLibraries = arguments.sourceLibraries?.toList().orEmpty()
|
||||
val produceBinaryOrBitcode = outputKind.let { it.isNativeBinary || it == CompilerOutputKind.BITCODE }
|
||||
|
||||
return if (sourceLibraries.isNotEmpty() && !produceBinaryOrBitcode) {
|
||||
configuration.report(ERROR, "The $SOURCE_LIBRARY_ARG flag is only supported when producing native binaries or bitcode files, " +
|
||||
"but the compiler is producing ${outputKind.name.toLowerCase()}")
|
||||
emptyList()
|
||||
} else {
|
||||
sourceLibraries
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = K2Native.main(args)
|
||||
|
||||
|
||||
@@ -157,6 +157,15 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xruntime", deprecatedName = "--runtime", valueDescription = "<path>", description = "Override standard 'runtime.bc' location")
|
||||
var runtimeFile: String? = null
|
||||
|
||||
// TODO: Rename?
|
||||
// TODO: Improve description
|
||||
@Argument(
|
||||
value = SOURCE_LIBRARY_ARG,
|
||||
valueDescription = "<path>",
|
||||
description = "Produce an output binary from a klibrary instead of source files"
|
||||
)
|
||||
var sourceLibraries: Array<String>? = null
|
||||
|
||||
@Argument(value = STATIC_FRAMEWORK_FLAG, description = "Create a framework with a static library instead of a dynamic one")
|
||||
var staticFramework: Boolean = false
|
||||
|
||||
@@ -208,3 +217,4 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
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 SOURCE_LIBRARY_ARG = "-Xsource-library"
|
||||
|
||||
+1
-4
@@ -39,10 +39,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
internal val target = targetManager.target
|
||||
internal val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)!!
|
||||
|
||||
val linkOnly: Boolean =
|
||||
configuration.kotlinSourceRoots.isEmpty() && libraryNames.isNotEmpty() && produce.isNativeBinary
|
||||
|
||||
val infoArgsOnly = configuration.kotlinSourceRoots.isEmpty() && !linkOnly
|
||||
val infoArgsOnly = configuration.kotlinSourceRoots.isEmpty() && configuration[KonanConfigKeys.SOURCE_LIBRARIES].isNullOrEmpty()
|
||||
|
||||
// TODO: debug info generation mode and debug/release variant selection probably requires some refactoring.
|
||||
val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG)
|
||||
|
||||
+3
-1
@@ -94,10 +94,12 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("library search path repositories")
|
||||
val RUNTIME_FILE: CompilerConfigurationKey<String?>
|
||||
= CompilerConfigurationKey.create("override default runtime file path")
|
||||
val SOURCE_LIBRARIES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey("a klibraries used to produce the final binaries instead of source code") // TODO: Better description.
|
||||
val SOURCE_MAP: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("generate source map")
|
||||
val STATIC_FRAMEWORK: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("Produce a static library for a framework")
|
||||
= CompilerConfigurationKey.create("produce a static library for a framework")
|
||||
val TARGET: CompilerConfigurationKey<String?>
|
||||
= CompilerConfigurationKey.create("target we compile for")
|
||||
val TEMPORARY_FILES_DIR: CompilerConfigurationKey<String?>
|
||||
|
||||
Reference in New Issue
Block a user