After switching to xcode 14 build system. Generated headers for our pod frameworks start looking like that:
#if 0
#elif defined(__arm64__) && __arm64__
// Generated by Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
... bridging for arm64
#else
#error unsupported Swift architecture
#endif
#if 0
#elif defined(__x86_64__) && __x86_64__
// Generated by Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
... bridging for x86
#else
#error unsupported Swift architecture
#endif
If I look in headers I see that scenarios:
arm64 defined and x86 defined – should be OK
arm64 defined and x86 not – should be error
arm64 not defined and x86 does – should be error
So to avoid error both architectures should be defined. And this cause client application build fail with error: error unsupported Swift architecture.
Even if ONLY_ACTIVE_ARCH = 0, that probably should be the hotfix. I still getting this error.
Does anyone know why precompiled headers now requires both architectures. And how to fix build error?
4
Answers
SOLUTION THAT HELPS US:
When building frameworks we were using
-arch arm64
or-arch arm64
and build frameworks for different architectures and then join them.Apple changed the way they generate bridging headers this solution fails because of format of header I attached in question.
The solution for us is just remove -arch and build fat framework.
If your Mac chip is M2 or M1, you can try to use the Rosetta mode of XCode to compile.
1.lipo -create x86_64 && arm64
2.use shell copy input1/Modules/xxx.swiftmodule into output/Modules/xxx.swiftmodule
3.use ruby script change #elif defined(x86_64)
if you are using Xcode 14. just paste this code in your podfile