Support static ObjC frameworks
This commit is contained in:
committed by
Ilya Matveev
parent
eb9965d2c8
commit
0647194a45
@@ -149,6 +149,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
put(LIST_TARGETS, arguments.listTargets)
|
put(LIST_TARGETS, arguments.listTargets)
|
||||||
put(OPTIMIZATION, arguments.optimization)
|
put(OPTIMIZATION, arguments.optimization)
|
||||||
put(DEBUG, arguments.debug)
|
put(DEBUG, arguments.debug)
|
||||||
|
put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind))
|
||||||
|
|
||||||
put(PRINT_IR, arguments.printIr)
|
put(PRINT_IR, arguments.printIr)
|
||||||
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
|
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
|
||||||
@@ -219,6 +220,23 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 selectBitcodeEmbeddingMode(
|
private fun selectBitcodeEmbeddingMode(
|
||||||
configuration: CompilerConfiguration,
|
configuration: CompilerConfiguration,
|
||||||
arguments: K2NativeCompilerArguments,
|
arguments: K2NativeCompilerArguments,
|
||||||
|
|||||||
@@ -134,6 +134,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-Xruntime", deprecatedName = "--runtime", valueDescription = "<path>", description = "Override standard 'runtime.bc' location")
|
@Argument(value = "-Xruntime", deprecatedName = "--runtime", valueDescription = "<path>", description = "Override standard 'runtime.bc' location")
|
||||||
var runtimeFile: String? = null
|
var runtimeFile: 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")
|
@Argument(value = "-Xtemporary-files-dir", deprecatedName = "--temporary_files_dir", valueDescription = "<path>", description = "Save temporary files to the given directory")
|
||||||
var temporaryFilesDir: String? = null
|
var temporaryFilesDir: String? = null
|
||||||
|
|
||||||
@@ -168,3 +171,4 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
|
|
||||||
const val EMBED_BITCODE_FLAG = "-Xembed-bitcode"
|
const val EMBED_BITCODE_FLAG = "-Xembed-bitcode"
|
||||||
const val EMBED_BITCODE_MARKER_FLAG = "-Xembed-bitcode-marker"
|
const val EMBED_BITCODE_MARKER_FLAG = "-Xembed-bitcode-marker"
|
||||||
|
const val STATIC_FRAMEWORK_FLAG = "-Xstatic-framework"
|
||||||
|
|||||||
+2
@@ -88,6 +88,8 @@ class KonanConfigKeys {
|
|||||||
= CompilerConfigurationKey.create("override default runtime file path")
|
= CompilerConfigurationKey.create("override default runtime file path")
|
||||||
val SOURCE_MAP: CompilerConfigurationKey<List<String>>
|
val SOURCE_MAP: CompilerConfigurationKey<List<String>>
|
||||||
= CompilerConfigurationKey.create("generate source map")
|
= CompilerConfigurationKey.create("generate source map")
|
||||||
|
val STATIC_FRAMEWORK: CompilerConfigurationKey<Boolean>
|
||||||
|
= CompilerConfigurationKey.create("Produce a static library for a framework")
|
||||||
val TARGET: CompilerConfigurationKey<String?>
|
val TARGET: CompilerConfigurationKey<String?>
|
||||||
= CompilerConfigurationKey.create("target we compile for")
|
= CompilerConfigurationKey.create("target we compile for")
|
||||||
val TEMPORARY_FILES_DIR: CompilerConfigurationKey<String?>
|
val TEMPORARY_FILES_DIR: CompilerConfigurationKey<String?>
|
||||||
|
|||||||
+14
-6
@@ -15,6 +15,18 @@ typealias BitcodeFile = String
|
|||||||
typealias ObjectFile = String
|
typealias ObjectFile = String
|
||||||
typealias ExecutableFile = String
|
typealias ExecutableFile = String
|
||||||
|
|
||||||
|
private fun determineLinkerOutput(context: Context): LinkerOutputKind =
|
||||||
|
when (context.config.produce) {
|
||||||
|
CompilerOutputKind.FRAMEWORK -> {
|
||||||
|
val staticFramework = context.config.configuration.getBoolean(KonanConfigKeys.STATIC_FRAMEWORK)
|
||||||
|
if (staticFramework) LinkerOutputKind.STATIC_LIBRARY else LinkerOutputKind.DYNAMIC_LIBRARY
|
||||||
|
}
|
||||||
|
CompilerOutputKind.DYNAMIC -> LinkerOutputKind.DYNAMIC_LIBRARY
|
||||||
|
CompilerOutputKind.STATIC -> LinkerOutputKind.STATIC_LIBRARY
|
||||||
|
CompilerOutputKind.PROGRAM -> LinkerOutputKind.EXECUTABLE
|
||||||
|
else -> TODO("${context.config.produce} should not reach native linker stage")
|
||||||
|
}
|
||||||
|
|
||||||
internal class LinkStage(val context: Context) {
|
internal class LinkStage(val context: Context) {
|
||||||
|
|
||||||
private val config = context.config.configuration
|
private val config = context.config.configuration
|
||||||
@@ -24,12 +36,8 @@ internal class LinkStage(val context: Context) {
|
|||||||
|
|
||||||
private val optimize = context.shouldOptimize()
|
private val optimize = context.shouldOptimize()
|
||||||
private val debug = context.config.debug
|
private val debug = context.config.debug
|
||||||
private val linkerOutput = when (context.config.produce) {
|
private val linkerOutput = determineLinkerOutput(context)
|
||||||
CompilerOutputKind.DYNAMIC, CompilerOutputKind.FRAMEWORK -> LinkerOutputKind.DYNAMIC_LIBRARY
|
|
||||||
CompilerOutputKind.STATIC -> LinkerOutputKind.STATIC_LIBRARY
|
|
||||||
CompilerOutputKind.PROGRAM -> LinkerOutputKind.EXECUTABLE
|
|
||||||
else -> TODO("${context.config.produce} should not reach native linker stage")
|
|
||||||
}
|
|
||||||
private val nomain = config.get(KonanConfigKeys.NOMAIN) ?: false
|
private val nomain = config.get(KonanConfigKeys.NOMAIN) ?: false
|
||||||
private val emitted = context.bitcodeFileName
|
private val emitted = context.bitcodeFileName
|
||||||
private val libraries = context.llvm.librariesToLink
|
private val libraries = context.llvm.librariesToLink
|
||||||
|
|||||||
Reference in New Issue
Block a user