Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary support for Swift Package Manager #395

Merged
merged 7 commits into from
Aug 18, 2020
Merged

Add preliminary support for Swift Package Manager #395

merged 7 commits into from
Aug 18, 2020

Conversation

knothed
Copy link
Contributor

@knothed knothed commented Jun 15, 2020

Since SPM came around, people wanted SwiftMessages to be compatible with SPM (#330, #362, #387). Sadly, SPM currently has no support for resource bundling – however, with Swift 5.3, this will finally change.

This pull request accomplishes two things:

  1. Add preliminary support for SPM until Swift 5.3 officially appears
  2. Prepare SwiftMessages for upcoming Swift 5.3 SPM support by adding a Package.swift and fixing SPM build errors.

How To Use SwiftMessages With SPM?

If you really want to include SwiftMessages via SPM and not via Carthage/CocoaPods, there is a simple way. Swift Package Manager can be used to include and build the Swift sources; then, the resources must manually be added to your main target – this works without any problems.

This solution is natural and has a similar feel to SPM as it handles resource updating automatically.
You can set it up in three steps:

  1. Add SwiftMessages to your project via Swift Package Manager (using the newest 8.0.2 release)
  2. Here is a directory containing all SwiftMessages resources. Just drop it somewhere into your project. SwiftMessages-Resources.zip
  3. Now, just adapt the destination in below build script and add it as a build phase if you want resource auto-updating (i.e. when a new release of SwiftMessages changes some of the resources, they are also automatically updated in your project – no manual work for you!)
source="${BUILD_DIR}/../../SourcePackages/checkouts/SwiftMessages/SwiftMessages/Resources"
destination="${PROJECT_DIR}/Path_To_SwiftMessages_Resource_Folder"
rsync -r "${source}" "${destination}/"

Only change Path_To_SwiftMessages_Resource_Folder, the rest should stay as is.

Thats the closest we can get to SPM until Swift 5.3 is released. Again, it does work.
I think this is worth a consideration for everyone who wants to use SwiftMessages with SPM now and not wait until Swift 5.3.

@fredpi
Copy link

fredpi commented Jun 17, 2020

@knothed Thanks for this proposal!

While this method will also work if a resource gets updated, it won't work when entire resource files get added / removed.

But as a workaround until Swift 5.3 arrives, this is still a great way to use SwiftMessages via SPM! 🎉

@wtmoose wtmoose merged commit c40ae0b into SwiftKickMobile:master Aug 18, 2020
@wtmoose
Copy link
Member

wtmoose commented Aug 18, 2020

This is in 8.0.2. Sorry for taking so long.

@wtmoose
Copy link
Member

wtmoose commented Aug 19, 2020

@knothed initial implementation of full SPM support is on the work/xcode12 branch

@wtmoose
Copy link
Member

wtmoose commented Sep 3, 2020

The script provided by @knothed fails for archive builds because the build directory structure is different. Here's an alternate script that should work universally. Just change destination as described above.

if [[ "${BUILD_DIR}" =~ (^.*DerivedData\/[^\/]*\/) ]]
then
    source="${BASH_REMATCH[1]}SourcePackages/checkouts/SwiftMessages/SwiftMessages/Resources"
else
    echo "Unexpected build directory structure ${BUILD_DIR}"
    exit 1    
fi
destination="${PROJECT_DIR}/SwiftMessagesResources"
rsync -r "${source}" "${destination}/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants