Is it possible to make a pure Swift package that wraps a C library from Homebrew

This is frustrating because I have found dozens of guides, including here, that ALMOST match, but "almost" isn't enough. (GitHub's search interface doesn't seem to be good enough to find examples.)

  • Is it possible for a Swift package to compose only if the wrapped C code, without any actual .swift file with original Swift code?
  • I'm getting the C code from a library (libetpan) that's on Homebrew.
  • There's an option for "pkgconfig" in the package manifest, but my MacBook doesn't seem to have the pkg-config tool installed by default.
  • I'm new to the module-map stuff too. And how to define/place the module's *.h bridging header.

(At least other people can search for this query later.)

Yes. Swift packages are not required to have any Swift code in them. Simply omit the Swift wrapping code.

That doesn't matter, SwiftPM parses the pkg-config code itself. However, I recommend installing homebrew's pkg-config tool, as otherwise it may omit installing the pc files for the packages.

If you use a system library target all you need is a header file and the module.modulemap. The documentation on that page is quite effective at showing how you'd do this for libgit2.

1 Like