surpher/PactSwift

Task: Example of using PactSwift with Xcode's SPM

Closed this issue · 2 comments

❕ Problem Statement

PactSwift is intended to be used with test targets only. For obvious reasons, but among them, it's a tool to help us test our networking layer, it contains "huge" binaries, etc. It appears that Xcode 11 or Xcode 12 SPM interface doesn't allow us to define to what targets the package bundles into.

💬 Task Description

Research how PactSwift could be used with SPM in an iOS project directly in Xcode instead of faffing about in CLI.
PactSwift should only be available to be imported in test targets.

  • PactSwift can already be successfully pulled into an Xcode project as a Swift Package and be imported into test target
  • Requires a manual step defining "Library Search Path" in build settings
  • Requires replacing fake binaries with binaries build on the user's machine

👩‍🔧 Technical Design Notes

  • script to guide the user to compile the binary for the platform they need, it should be possible to re-use it in CI/CD pipeline!
  • demo project with a working Pact test
  • Instructions on how to set up with SPM

🤝 Relationships

  • Other Related Issues: #xxx, #yyy

Looking at this on the side and preparing an example project in surpher/pact-swift-examples.

Due to how SPM works, big binary files (which we're removing from the repo due to GitHub LFS storage and bandwidth limitations), PactSwift moving to build the binaries as part of a Build Phase, there might be a required configuration step after adding PactSwift as a package via Xcode (or cli?).

Maybe a script that would automate the build of libpact_mock_server.a and libpact_mock_server.dylib might be an option:

  • checks for rust, rustup and cargo-lipo
  • adds the wanted architecture triples
  • builds the binaries
  • replaces the fake libs in PactSwift/Resources

Working example at https://github.com/surpher/pact-swift-examples/tree/master/Pact-iOS-SPM-Example

It is a bit hacky, but it works around the SPM and binaries limitations when using Xcode.
Still working on the CI workflow demo. A working example, yet still hacky, available in https://github.com/surpher/pact-swift-examples/tree/master/Pact-iOS-SPM-Example