Swift Package to wrap C library that isn't available via brew, apt etc

Hi folks,

I'm seeking to wrap a C library using the SPM - however this isn't a library available via distribution channels like homebrew and apt, I'm wrapping .h header files (and .c files if this is possible) directly.

Is this currently possible?

If so, should I be manually creating module maps for every header? There's about 20 headers in the src folder for this library.

Many guides I've found are for wrapping system libraries available via distribution channels mentioned, so it's unclear if the SPM supports what I'm trying to do.

Fallback: should I just compile the library and work with the static lib (.a file) instead? It'd be ace to use the SPM for this and make it portable (and shareable!) if possible :D

just put all the codes into a package and it will done.

MyCLib
├── Sources
│   └── MyCLib
│       ├── include
│       │   └── public.h
│       ├── private.h
│       └── source.c
└── Package.swift

also, you can change the folder layout but you have to tell SwiftPM where the sources located.
here examples:

2 Likes

Woo! That's wonderful - nice and clear. Thanks for the links too.

Now I can try to build the package for my target - looks like this lib isn't supported for iOS :frowning:

'CoreAudio/HostTime.h' file not found

edit: think I'm finding a workaround! Technical Q&A QA1643: Audio Host Time On iOS