From 7055893605f8dd946dbef90888cb0f971d01002f Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Wed, 20 Jul 2022 11:00:02 +0300 Subject: [PATCH] [K/N] Move framework interface generation to "Produce Output" phase It allows to invoke interface generation even if we don't compile a binary. --- .../kotlin/backend/konan/CompilerOutput.kt | 4 +++- .../backend/konan/objcexport/ObjCExport.kt | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt index 537d36ee3e6..81db98dc1f6 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CompilerOutput.kt @@ -181,7 +181,9 @@ internal fun produceOutput(context: Context) { val config = context.config.configuration val tempFiles = context.config.tempFiles val produce = config.get(KonanConfigKeys.PRODUCE) - + if (produce == CompilerOutputKind.FRAMEWORK) { + context.objCExport.produceFrameworkInterface() + } when (produce) { CompilerOutputKind.STATIC, CompilerOutputKind.DYNAMIC, diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt index 103b1af2da5..c70e0b1411a 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt @@ -47,8 +47,6 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { private fun produceInterface(): ObjCExportedInterface? { if (!target.family.isAppleFamily) return null - if (!context.config.produce.isFinalBinary) return null - // TODO: emit RTTI to the same modules as classes belong to. // Not possible yet, since ObjCExport translates the entire "world" API at once // and can't do this per-module, e.g. due to global name conflict resolution. @@ -98,16 +96,21 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { val objCCodeGenerator = ObjCExportCodeGenerator(codegen, namer, mapper) - if (exportedInterface != null) { - produceFrameworkSpecific(exportedInterface.headerLines) - - exportedInterface.generateWorkaroundForSwiftSR10177() - } + exportedInterface?.generateWorkaroundForSwiftSR10177() objCCodeGenerator.generate(codeSpec) objCCodeGenerator.dispose() } + /** + * Populate framework directory with headers, module and info.plist. + */ + fun produceFrameworkInterface() { + if (exportedInterface != null) { + produceFrameworkSpecific(exportedInterface.headerLines) + } + } + private fun produceFrameworkSpecific(headerLines: List) { val framework = File(context.config.outputFile) val frameworkContents = when(target.family) {