From 2a1d5d3e0a63dd92b6a43882ddda0279aaa7f636 Mon Sep 17 00:00:00 2001 From: Martin Petrov <357181+mpetrov@users.noreply.github.com> Date: Wed, 16 Mar 2022 05:15:50 -0400 Subject: [PATCH] [Native] Explicitly use Foundation in ObjC export. (#4762) This enables using exported Frameworks with `-fmodules-decluse`. One use-case for this is ensuring that distributed builds are explicitly providing all required modules; this is important for reproducibility. For more background on `use` declarations, see: https://clang.llvm.org/docs/Modules.html#use-declaration The easiest way to reproduce this locally is by compiling a framework, and emitting a pcm file with `swiftc`. Note that this requires a reference to a pcm for Foundation, which can be found in the clang ModuleCache. ``` kotlin-native/dist/bin/kotlinc-native ~/test.kt -produce framework -o /tmp/TestFramework.framework swiftc -emit-pcm -module-name TestFramework -o /tmp/TestFramework.pcm /tmp/TestFramework.framework/Modules/module.modulemap -Xcc -fmodules-decluse -Xcc -fmodule-file=Foundation=$HOME/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/1IQ2SWDEIAPH0/Foundation-2FJBXN8U6QRTS.pcm ``` --- .../org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt | 2 ++ 1 file changed, 2 insertions(+) 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 8e9cd8dda3f..dc6188d25d5 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 @@ -135,6 +135,8 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { | | export * | module * { export * } + | + | use Foundation |} """.trimMargin()