|
18 | 18 | * [Debug](#debug)
|
19 | 19 | * [Release](#release)
|
20 | 20 | * [Depending on Apple Modules](#depending-on-apple-modules)
|
| 21 | + * [C language targets](#c-language-targets) |
21 | 22 | * [Resources](Resources.md)
|
22 | 23 |
|
23 | 24 | ---
|
@@ -53,6 +54,22 @@ and `swift build` will now produce an:
|
53 | 54 |
|
54 | 55 | executable output file.
|
55 | 56 |
|
| 57 | +The C language modules are laid out in a similar format. A C language library named `Baz` can be created in following format: |
| 58 | + |
| 59 | + example/Sources/Baz/Baz.c |
| 60 | + example/Sources/Baz/include/Baz.h |
| 61 | + |
| 62 | +The public headers for this library go in the directory named `include`. |
| 63 | + |
| 64 | +Similarly, an executable C language module named `Baz` would look like this: |
| 65 | + |
| 66 | + example/Sources/Baz/main.c |
| 67 | + |
| 68 | +Note: It is possible to have C, C++, Objective-C and Objective-C++ sources as part of a C language target. Swift modules can |
| 69 | +import C language targets but not vice versa. |
| 70 | + |
| 71 | +Read more on C language targets [here](#c-language-targets). |
| 72 | + |
56 | 73 | ### Test Suite Layouts
|
57 | 74 |
|
58 | 75 | The package manager supports laying out test sources following a similar convention as primary sources:
|
@@ -341,3 +358,18 @@ A C language target is build with following flags in release mode:
|
341 | 358 | ### Depending on Apple Modules
|
342 | 359 |
|
343 | 360 | At this time there is no explicit support for depending on Foundation, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
|
| 361 | + |
| 362 | +## C language targets |
| 363 | + |
| 364 | +The C language targets are laid out similar to Swift targets execept that the C langauge libraries should contain a directory named `include` to hold the public headers. |
| 365 | +To allow a Swift module to import a C language module, add a [target dependency](#targets) in the manifest file. Swift Package Manager will automatically generate a modulemap for each C language library module for these 3 cases: |
| 366 | + |
| 367 | +* If `include/Foo/Foo.h` exists and `Foo` is the only directory under the include directory then `include/Foo/Foo.h` becomes the umbrella header. |
| 368 | + |
| 369 | +* If `include/Foo.h` exists and `include` contains no other subdirectory then `include/Foo.h` becomes the umbrella header. |
| 370 | + |
| 371 | +* Otherwise if the `include` directory only contains header files and no other subdirectory, it becomes the umbrella directory. |
| 372 | + |
| 373 | +In case of complicated `include` layouts, a custom `module.modulemap` can be provided inside `include`. SwiftPM will error out if it can not generate a modulemap w.r.t the above rules. |
| 374 | + |
| 375 | +For executable modules, only one valid C language main file is allowed i.e. it is invalid to have `main.c` and `main.cpp` in the same module. |
0 commit comments