Packaging .a static C libraries in Swift Package Manager

There is no way to publish binaries yet, but much thought is going into making it possible:

That means you have three options:

  1. Depend on OpenSSL as source. Its GitHub repository is here. Fork it, add a Package.swift, tag a version, and depend on that. (And maybe submit your Package.swift back to them as a pull request.) Sometimes this strategy requires generating and checking in files the project normally leaves Git‐ignored.

  2. Distribute the binary separately, and instruct your clients to install it on the system first. (And your clients’ clients will have to do the same thing.) Once it is installed on the system, linkedLibrary should just work without needing unsafe flags.

  3. Use unsafeFlags and never release semantic versions, telling your clients to depend on branches instead. Branch dependencies allow unsafe flags, because they are only intended for development. The branches in the dependency tree will in turn prevent clients from release semantic versions too.

All these strategies see quite a lot of use, so which one you choose is up to you. (I’m partial to option 1.)

6 Likes