skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. If your Mac chip is M2 or M1, you can try to use the Rosetta mode of XCode to compile.

    Login or Signup to reply.
  3. 1.lipo -create x86_64 && arm64

    input0 = "#{iphoneos_framework}/#{framework_name}"
        input1 = "#{iphonesimulator_framework}/#{framework_name}"
        output = "#{universal_framework}/#{framework_name}"
        raise "#{input0} not found!" unless File.exist?(input0)
        raise "#{input1} not found!" unless File.exist?(input1)
        #
        cmd = "lipo -create #{input0} #{input1} -output #{output}"
        system(cmd) || raise("lipo create failed for #{scheme}")
    

    2.use shell copy input1/Modules/xxx.swiftmodule into output/Modules/xxx.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)
    
    Login or Signup to reply.
  4. if you are using Xcode 14. just paste this code in your podfile

     post_install do |pi|
        pi.pods_project.targets.each do |t|
          t.build_configurations.each do |config|
            config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
          end
        end
      end
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search