I have a static iOS library that is distributed as multiple .a files + .h header files in my project that I like to use in my Swift project.
To make it calling-side API a bit nicer though, I'd like to wrap it though in a Swift package.
My SPM package directory tree looks like this:
Wrapper Project
├── Sources
│ ├── Wrapper.swift (Public API - Foundation Types)
│ ├── DependencyAWrapper.swift (Private - Dependent on DependencyA)
│ ├── Frameworks
│ │ └── DependencyA
│ │ ├── DepAHeader.h
│ │ ├── libA_iOS.a
│ │ └── module.modulemap
└── Package.swift
DependencyA is the static library mentioned before, DependencyAWrapper imports DependencyA defined in the module.modulemap like this:
module DependencyA {
header "DepAHeader.h"
export *
}
The import is actually using @_implementationOnly import
, since the iOS executable which will implement the Wrapper Project
doesn't need to know about DependencyA. From what I understand though, DependencyA will still be available in the iOS executable due to SPM limitations - which is fine.
The only public
API that the wrapper offers is in Wrapper.swift and uses Foundation types exclusively, nothing from DependencyA
or any such imports.
The Package.swift
for the Wrapper Project
looks like this:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "Wrapper Project",
platforms: [
.iOS(.v12)
],
products: [
.library(name: "WrapperProject", targets: ["WrapperProject"])
],
dependencies: [],
targets: [
.target(
name: "WrapperProject",
dependencies: [],
path: "Sources",
cSettings: [
.headerSearchPath("Frameworks/**")
]
),
]
)
Building the Wrapper in Xcode seems to work fine, although warnings are given for the .a file(s) that these are unused.
When importing the Wrapper into my iOS App/Executable with Xcode though, I'm getting Undefined Symbol
and other linker issues for the API in libA. Suggesting that there's a linker issue and potentially missing the .a files completely in the iOS Executable.
When building the Wrapper and iOS Project both in Xcode though, I can build and run my project successfully after setting the "Header Search Path" and the "Library Search Path" to my Frameworks folder (on the Wrapper project).
My best assumption is that the static library gets lost because it's not included with the Wrapper Project when built with SPM and then there's also the library linking missing.
Hoping to find an answer here on how to get this working so that I can use SPM and no longer have to rely on other solutions.
(I've tried making the DependencyA a system library before, but that seemed to have ended with the same issue.)