XcodeGen icon indicating copy to clipboard operation
XcodeGen copied to clipboard

SwiftPM packages linked into static libraries (bug)

Open rastersize opened this issue 6 years ago • 6 comments

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

Screenshot of Xcode with the incorrect linkage of the SwiftPM package

rastersize avatar Jan 02 '20 19:01 rastersize

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.

chrisballinger avatar Feb 04 '20 19:02 chrisballinger

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:

StaticLibSPMBug.zip

chrisballinger avatar Feb 04 '20 20:02 chrisballinger

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.

DrewKiino avatar Jun 15 '20 08:06 DrewKiino

Any idea why xcodegen doesn't work? What's different in the output from xcodegen vs manually setting this up in xcode?

mikaelbartlett avatar Nov 03 '20 15:11 mikaelbartlett

Bump. Ran into this today as well.

mthole avatar Feb 13 '21 00:02 mthole

I am also hitting this, I have a repository that contains ~20 swift package manager packages, which depend on each other.

daniel-beard avatar Sep 16 '21 16:09 daniel-beard