[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
```
This commit is contained in:
Martin Petrov
2022-03-16 05:15:50 -04:00
committed by GitHub
parent 7bcd67068c
commit 2a1d5d3e0a
@@ -135,6 +135,8 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
|
| export *
| module * { export * }
|
| use Foundation
|}
""".trimMargin()