[Question] How can local Swift packages' dynamic library targets dynamically link to local XCFrameworks that are in the Carthage/Build directory?

[Question] How can local Swift packages' dynamic library targets dynamically link to local XCFrameworks that are in the Carthage/Build directory—without causing Xcode to synthesize any copy-frameworks steps for the linked XCFramework—and without causing Xcode to build and place static versions of any of these dynamic libraries into $(BUILT_PRODUCTS_DIR)/Frameworks?

We have a Xcode workspace with:

  • an app target declared using an Xcode project file
  • 40+ locally-declared dynamic framework targets, each declared using an Xcode project file
  • 10+ locally-declared dynamic Swift Package targets
  • ~15 Carthage dependencies being built as XCFrameworks

The app embeds all the dynamic targets and all the Carthage XCFrameworks.

Xcode project files have been a constant source of nasty merge conflicts (and project corruption due to people screwing up the .pbxproj files during merge conflict resolution). This is because they use multiple instances of a randomly-generated GUID to track every file and every dependency. So when multiple people work on the same module(s) and make the same changes on separate branches, you end up with merge conflicts 100% of the time, whenever they try to merge their branches together.

So to avoid these constant headaches, we are trying to transition all our dynamic framework targets over to using local Swift Packages instead of Xcode project files.

Now, many of our frameworks depend on those XCFrameworks in Carthage/Build directory.

My question is: how can our Swift packages' dynamic library targets dynamically link to XCFrameworks that are in the Carthage/Build directory? So far I cannot seem to find any way to do this that works.

(First we tried linking to the XCFrameworks by setting each one we need to link to as a .binaryTarget of the Swift Package that needs to depend on it. However this leads to intermittent build errors as detailed here. Then we tried wrapping these XCFrameworks in a wrapper package as detailed here, however this method only works if the Swift Package wrapper is a static library, which won't work for us because it would lead to multiple copies of each XCFramework being embedded in the final app.)

Surely there must be a third option we're missing? How can we do this? Thanks.

I figured out a solution. See post here: Binary Frameworks with SwiftPM - #20 by 1oo7