14

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 Answers4

3

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
Talha Javed
  • 87
  • 1
  • 6
  • 1
    This worked for me because ONLY_ACTIVE_ARCH was set to YES explicitly before Xcode 14 / iOS 16 – Glenn Apr 17 '23 at 09:14
1

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.

1

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)
Peace Li
  • 11
  • 1
-3

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