SwiftPM packages linked into static libraries (bug)
Hey! I seem to have ran into a bug with the SwiftPM package integration for static libraries. When a static library depends on an SDK (e.g. Foundation, UIKit, …) all SwiftPM packages will also be linked into it. Adding other types of dependencies doesn’t seem to have any impact. It seems like it’s only when a static library depends on both a SwiftPM package and an SDK that the issue occurs.
In my case it caused just over 3000 duplicate symbol errors. As both my app and static library target linked with Alamofire from SwiftPM 😅
I was able to reproduce with latest master. See an example using this small modification of the SPM test fixture:
name: SPM
packages:
Codability:
url: https://github.com/yonaskolb/Codability
majorVersion: 0.2.1
localPackages:
- ../../.. #XcodeGen itself
targets:
App:
type: application
platform: iOS
sources: [SPM]
scheme: {}
dependencies:
- package: Codability
- target: StaticLibrary
StaticLibrary:
type: library.static
platform: iOS
sources: StaticLibrary
dependencies:
- package: Codability
- sdk: UIKit.framework # <- the addition
Screenshot

I am also seeing this issue, for a similar configuration. I think it might be a bug in SPM itself.
For instance:
name: PRODUCTNAME
deploymentTarget: "12.0"
options:
bundleIdPrefix: com.rightpoint
packages:
BonMot:
url: https://github.com/Rightpoint/BonMot.git
from: 5.5.0
Anchorage:
url: https://github.com/Rightpoint/Anchorage.git
from: 4.4.0
Swiftilities:
url: https://github.com/Rightpoint/Swiftilities.git
branch: feature/swift-package-manager
configs:
Debug: debug
Develop: release
Sprint: release
AppStore: release
configFiles:
Debug: xcconfig/Debug.xcconfig
Develop: xcconfig/Develop.xcconfig
Sprint: xcconfig/Sprint.xcconfig
AppStore: xcconfig/AppStore.xcconfig
settings:
PRODUCT_MODULE_NAME: $(TARGET_NAME)
targets:
PRODUCTNAME:
scheme:
testTargets:
- PRODUCTNAMETests
- ServicesTests
type: application
platform: iOS
sources: [Sources]
dependencies:
- target: Services
- package: BonMot
- package: Anchorage
- package: Swiftilities
PRODUCTNAMETests:
type: bundle.unit-test
platform: iOS
sources: [Tests]
dependencies:
- target: PRODUCTNAME
settings:
TEST_HOST: $(BUILT_PRODUCTS_DIR)/debug-PRODUCTNAME.app/debug-PRODUCTNAME
ServicesTests:
type: bundle.unit-test
platform: iOS
sources: [ServicesTests]
dependencies:
- target: Services
Services:
type: library.static
platform: iOS
sources: [Services]
dependencies:
- package: Swiftilities
I think just having any static library with a SPM dependency shared with an app target causes duplicate symbol issues.
I confirmed it's NOT a bug with SPM itself, and seems to be related to how XcodeGen integrates SPM dependencies. Here's an working example project generated manually via Xcode with a SPM dependency (swift-log) shared by both a static library and app target:
this needs to be fixed, this essentially renders using SPM with xcodegen useless. Having to deal with linker issues has been a pain with this for an extended amount of time, been thinking of going back to using Pods for dependency management for now.
Any idea why xcodegen doesn't work? What's different in the output from xcodegen vs manually setting this up in xcode?
Bump. Ran into this today as well.
I am also hitting this, I have a repository that contains ~20 swift package manager packages, which depend on each other.