Reputation: 732
Goal is to host a git repo for a Swift Package to distribute proprietary code as a binary in a XCFramework. The source code has dependencies on other Swift Packages. Listing the dependencies in the .package config is not enough. Simply asking consumers to import dependencies is not an option, as they may be making use of the same packages at different levels. The main problem I am trying to solve is how to resolve these dependencies when my Swift Package is imported into a project.
The packages I am using are also available in a CocoaPod as well.
I have gone thru the following resources and SO posts, but can not find answer to this specific purpose.
Upvotes: 9
Views: 4725
Reputation: 732
Found a way to do it on the Swift forums. Someone suggested using a "dummy" target to wrap the binary framework in. You can then list dependencies in the dummy target's definition in the manifest.
I have the binary hosted in a zip and it is available by both SPM and Cocoa Pods. Tackling both package managers with one framework binary.
Upvotes: 1
Reputation: 21
I faced into same issue couple of months ago and haven't found a proper solution so I just started to use Cocoapods for distribution and this script for archiving my framework target which have some Cocoapods as a dependencies:
xcodebuild archive -workspace "../workspace_name.xcworkspace" \
-scheme %scheme_name% \
-sdk iphonesimulator \
-archivePath "./SdkArchives/ios_simulators.xcarchive" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO
xcodebuild archive -workspace "../workspace_name.xcworkspace" \
-scheme %scheme_name% \
-sdk iphoneos \
-archivePath "./SdkArchives/ios_devices.xcarchive" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO
rm -rf ../DevPods/SDK/framework_name.xcframework
xcodebuild -create-xcframework \
-framework ./SdkArchives/ios_devices.xcarchive/Products/Library/Frameworks/framework_name.framework \
-framework ./SdkArchives/ios_simulators.xcarchive/Products/Library/Frameworks/framework_name.framework \
-output ../DevPods/SDK/framework_name.xcframework
rm -rf SdkArchives
Than you can simply package this xcframework
as a pod using this lines in your podspeck:
s.vendored_frameworks = 'framework_name.xcframework'
s.dependency 'framework_name_dependency'
Also you could check out this article, I haven't tried it but looks promising. https://kean.blog/post/xcframeworks-caveats
Upvotes: 2