In my testing I've been able to successfully copy the various .swiftmodule files into Packages.framework/Modules. Here's how I got it to work:
-
Create a new
Packages.xcodeproj, separate to your main project file. This is where the Swift dependencies will be added, and produces a single dynamically linkedPackages.framework. -
Add a Run Script build phase with the following contents:
modules_dir="$BUILT_PRODUCTS_DIR"/"$MODULES_FOLDER_PATH" for swiftmodule in "$BUILT_PRODUCTS_DIR"/*.swiftmodule; do cp -r "$swiftmodule" "$modules_dir"/ doneThis will copy the generate
.swiftmodulefiles for all your dependencies into the framework bundle. -
Use
carthage build --no-skip-currentto build Packages.framework. -
Link & Embed Packages.framework in your regular project.
-
Update
SWIFT_INCLUDE_PATHSto addCarthage/Build/iOS/Packages.framework/Modulesso that your app can see the embedded Swift modules. -
(Optional) If your Swift dependency depends on any C modules, this will still not compile, because C/system modules don't produce
.swiftmodulefiles. So, for example, I had to fork GRDB in my project and changeimport CSQLiteto@_implementationOnly import CSQLite(and remove a bunch of@inlinableattributes that were no longer valid because the C SQLite symbols are no longer exported).
So this mostly works, depending on your specific dependencies. However I probably won't keep this setup because it adds more complexity than I'd like to my build process.