I have a XCFramework which depends upon several other Static Frameworks. All of those sub frameworks are built with BUILD_FOR_LIBRARIES_FOR_DISTRIBUTION enabled. The sub frameworks don't need to be accessible from outside the XCFramework. When I try to compile my XCFramework in the client app, I am getting errors on the import Core, which is the XCFramework's swiftinterface file, for one of the sub frameworks.

/Users/paulossenbruggen/Library/Developer/Xcode/DerivedData/DemoProject-dnxwshtlynfbgcdviialmdfrdwwa/Build/Products/Debug-iphonesimulator/Core.framework/Modules/RideCore.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:4:8: No such module 'AwaitKit'
/Users/paulossenbruggen/Projects/DemoProject/DemoProject/GPSLocationComponent.swift:9:8: Failed to load module 'Core'
/Users/paulossenbruggen/Projects/DemoProject/Carthage/Build/iOS/Core.framework/Modules/Core.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:4:8: No such module 'AwaitKit'

What seems to be missing is the swiftinterface files for the dependent modules. For example, I am using AwaitKit but the swiftinterface is not there within the XCFramework. With nm I can see that the objects for AwaitKit are there, but when processing the import in the Core swiftinterface file it produces an error.

So, what is unclear is can I just copy the AwaitKit swiftinterface somewhere in the xcframework? And if so where? Is there a way to tell xcbuild -xcframework tool to include the swiftinterface files for dependent libraries? Or perhaps there is something else I should be doing that I am not doing?

For reference this is how the XCFramework are being built. The BUILD_LIBRARIES_FOR_DISTRIBUTION flag is being set in the project setting and the dependent libraries are also defined in the project file:

TEMP_DIR=archive
rm -rd "RideCore.xcframework"
xcodebuild archive -scheme Core -destination "generic/platform=iOS" -archivePath "$TEMP_DIR/Core.iOS.xcarchive" SKIP_INSTALL=NO -sdk iphoneos
xcodebuild archive -scheme Core -destination "platform=iOS Simulator,name=iPhone 11" -archivePath "$TEMP_DIR/Core.iOS-simulator.xcarchive" SKIP_INSTALL=NO -sdk iphonesimulator
xcodebuild -create-xcframework -framework "$TEMP_DIR/Core.iOS.xcarchive/Products/@executable_path/Frameworks/Core.framework" -framework "$TEMP_DIR/Core.iOS-simulator.xcarchive/Products/@executable_path//Frameworks/Core.framework" -output "Core.xcframework"
1 Like

Experiencing the same problem, did you manage to resolve it?

I filed a bug report when I posted this, and on the first day of WWDC received a response. I can verify it worked for me with Xcode 12 beta.

Can you please elaborate on the solution?

Just need to use Xcode 12 beta. I could not get it working with prior versions of Xcode.

Ok, Thanks

Might you be able to share the tree output of the working version of your framework? I'm having a similar issue but I'm on xcode 12.4...

I put the test project I submitted to Apple for the bug fix here. GitHub - possen/HostApp: Demonstrate issue with swiftinterface files not generated with Defines Module on. I hope that helps. Prior to Xcode 12, this would not link properly.

The compilation of "HostAppXC" only works if previously having compiled the 2 other frameworks so that the interfaces are known to Xcode via stuff in derived data.
Doesn't work if just running the xcframework creation script because then Xcode doesn't know where to look for BarKit.

Normally with an XCFramework you would publish it somewhere so that users of that framework just need to drag it into a project and use it.

The original question was never answered.

The author asked if it is somehow possible to build a framework with static dependencies (statically linking other swift binaries into the framework) and deliver that one framework, all while still compiling successfully for consumers of this framework.

So, has anyone gained knowledge about that issue until now?

1 Like