Skip to content

Commit 73420fb

Browse files
authored
Final touch ups to sync with review discussion
1 parent 73c13ef commit 73420fb

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

proposals/0403-swiftpm-mixed-language-targets.md

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -302,20 +302,28 @@ build nodes for the its `SwiftTargetBuildDescription` and
302302

303303

304304

305-
##### module.modulemap
305+
##### Module Maps
306306

307307
The product module map’s purpose is to define the public API of the mixed
308308
language module. It has two parts, a primary module declaration and a secondary
309309
submodule declaration. The former of which exposes the public C language
310310
headers and the latter of which exposes the generated interop header.
311311

312312
There are two cases when creating the product module map:
313-
- If a custom module map exists in the target, its contents are copied to the
314-
product module map and a submodule is added to expose the generated interop
315-
header.
313+
- If a custom module map exists in the target, its contents are copied and
314+
extended to modularize the generated interop header. These contents are
315+
written to the build directory as `extended-custom-module.modulemap`.
316+
Since the public header directory and build directory are passed as import
317+
paths to the build invocations, a different name is needed for this module
318+
map as the `-import-underlying-module` should only be able to find one
319+
`module.modulemap` file from the given import paths.
316320
- Else, the product module map’s contents will be generated via the same
317321
generation rules established in [SE-0038] with an added step to generate the
318-
`.Swift` submodule.
322+
`.Swift` submodule. This file is called `module.modulemap` and lives in the
323+
build directory.
324+
325+
Clients will use an _extended_ module map that includes the modularized interop
326+
header. Building the target will use _unextended_ module map.
319327

320328
> Note: It’s possible that the Clang part of the module exports no public API.
321329
> This could be the case for a target whose public API surface is written in
@@ -326,7 +334,7 @@ Below is an example of a module map for a target that has an umbrella
326334
header in its public headers directory (`include`).
327335

328336
```
329-
// module.modulemap
337+
// extended-custom-module.modulemap
330338
331339
// This declaration is either copied from the custom module map or generated
332340
// via the rules from SE-0038.
@@ -343,54 +351,18 @@ module MixedTarget.Swift {
343351

344352
##### all-product-headers.yaml
345353

346-
The product `all-product-headers.yaml` overlay file is only created when there
347-
exists a custom module map that needs to be swapped out for the product module
348-
map.
354+
An `all-product-headers.yaml` VFS overlay file will adjust the public headers
355+
directory to expose the interop header as a relative path, and, if a custom
356+
module map exists, swap it out for the extended one that modualrizes the interop
357+
header.
349358

350-
In the case that this overlay file exists, it will be passed alongside the
351-
product module map as a compilation argument to clients:
359+
In either case, it will be passed alongside the module map as a compilation
360+
argument to clients:
352361
```
353362
-fmodule-map-file=/Users/crusty/Developer/MixedTarget/Sources/MixedTarget/include/module.modulemap
354363
-ivfsoverlay /Users/crusty/Developer/MixedTarget/.build/.../MixedTarget.build/Product/all-product-headers.yaml
355364
```
356365

357-
The `-fmodule-map-file` argument tells the client to find the mixed target’s
358-
module map in its public `include` directory. However, the product module map
359-
should be used instead of the custom module map, so passing the overlay via
360-
`-vfsoverlay` will ensure that resolving the module map path redirects to the
361-
product module map in the build directory. The reason this is necessary is
362-
because a custom module map will likely have relative paths within it (e.g.
363-
`umbrella header “MyHeader.h”`) that are preserved when its contents are copied
364-
to the product module map. In order for these relative paths to be resolved,
365-
the product module map needs to appear as if it is in the original directory
366-
that the custom module map resides in.
367-
368-
The below sample shows what this overlay file may look like:
369-
```yaml
370-
// all-product-headers.yaml
371-
372-
{
373-
"version": 0,
374-
"case-sensitive": false,
375-
"roots":
376-
[
377-
{
378-
"name": "/Users/crusty/Developer/MixedTarget/Sources/MixedTarget/include",
379-
"type": "directory",
380-
"contents":
381-
[
382-
{
383-
"name": "module.modulemap",
384-
"type": "file",
385-
"external-contents": "/Users/crusty/Developer/MixedTarget/.build/.../MixedTarget.build/Product/module.modulemap",
386-
},
387-
],
388-
},
389-
],
390-
"use-external-names": false,
391-
}
392-
```
393-
394366
### Additional changes to the package manager
395367

396368
It is the goal for mixed language targets to work on all platforms supported

0 commit comments

Comments
 (0)