Error unsupported Swift architecture.

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:

  1. arm64 defined and x86 defined - should be OK
  2. arm64 defined and x86 not - should be error
  3. 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?

We're facing the same issue in our CMake generated frameworks.... Your explanation was very helpful as indeed, with CMake we only generate one arch at a time....

I hope some workaround can be found.

Is this problem solved?

I ran into a siilar issue today using xcode 14.2 running on a M1. Starting xcode with Rosetta solved that problem for now. But this must not be the long term solution for this...

Hi,

Im with the same error when i try run in Simulator on M1 and Xcode 14.2.

There is any solution?

Thanks.

It works for me, Chinese developers look at it https://www.jianshu.com/p/f66b056700fe

1.lipo -create x86_64 && arm64

    input0 = "#{iphoneos_framework}/#{framework_name}"
    input1 = "#{iphonesimulator_framework}/#{framework_name}"
    output = "#{universal_framework}/#{framework_name}"
    cmd = "lipo -create #{input0} #{input1} -output #{output}"
    system(cmd) || raise("lipo create failed for #{scheme}")

2.use shell copy input1/Modules/***.swiftmodule into output/Modules/***.swiftmodule

x86_64-apple-ios-simulator.abi.json;
x86_64-apple-ios-simulator.swiftdoc;
x86_64-apple-ios-simulator.swiftmodule;
x86_64-apple-ios-simulator.swiftsourceinfo;

3.use ruby script change #elif defined(x86_64)

swift_header = "#{universal_framework}/Headers/#{framework_name}-Swift.h"
    if File.exist?(swift_header)
      cmds = ["sed -i '' \"2 s/^#elif defined(__x86_64__) \\&&\\ __x86_64__/#if defined(__x86_64__) \\&\\& __x86_64__ \\|\\| defined(__arm64__) \\&\\& __arm64__/\" #{swift_header}",
        "sed -i '' 's/#if 0//g' #{swift_header}"]
      cmd_swift = cmds.join(';') system(cmd_swift)

I had this problem today using XCode 15.3. After having problems downloading the simulator for iOS 17.4, I thought about running it under Rosetta, and it worked. I suspect this is a new variant of an old problem that came when they switched to the M series processors.

Error unsupported Swift architecture.
 
 
Q