Once again I am evaluating whether I can build a project with SwiftPM or we need our own build system.
This time, it's a project that is mostly cross-platform C, (and in fact cross-compiles to weird architectures outside the scope of this problem).
Generally it's desirable for the Swift clients to use the C types directly. I have been annotating the C headers with swift_name
to get a more modern-feeling API. In rare cases, we implement some behavior in Swift directly if it's not interesting to the other platforms (.description
on the C types is a good example).
SwiftPM seems to want separate targets for C and Swift:
targets: [
package depends on.
.target(
name: "lib-c",
dependencies: []),
.target(
name: "lib",
dependencies: ["lib-c"],
),
.testTarget(
name: "libTests",
dependencies: ["lib"]),
]
This is not the end of the world from a build perspective. However, this seems to also imply callers will need to import lib-c
and import lib
in order to get both the C types and e.g. .description
, which is not a good end experience.
In other build systems we can specify a custom modulemap for our built products, as to cause import lib
to pull in lib-c
as well. I looked and did not see a similar mechanism in SwiftPM, and wanted to double-check that this sort of case is not supported before I went off in a different direction.