iosxcodeuniversal-binaryapple-siliconapple-m1

How to build a static library on M1 mac that supports iOS simulator on Intel mac?


I have a fat iOS library which supports both real devices (arm64...) and iOS simulator of Intel Mac (x86_64). But when I switched to M1 mac, things get tough.

If I use the old library, I will fail with error saying xxx.a (xxx.o) building for iOS Simulator, but linking in object file built for iOS, file 'xxx' for architecture arm64. It seems that I have to build a xcframework which contains binaries for different destinations.

So I tried to build different slices and hope to bundle them as a xcframework. But I finally found I don't know how to build the x86_64 slice with a M1 Mac.

My question is


Solution

  • The reason I failed to get x86_64 slice on M1 Mac is that there is a legacy option in my build setting: Valid architectures.

    Remove this configuration and run standard flow. Then you will get library containing x86_64 architecture smoothly.

    xcodebuild archive --destination="generic/platform=iOS Simulator" ...
    

    If your library code is not organized as a Xcode project but uses clang toolchain underneath. You can refer to this link. In a nutshell, specify target in a format like arm64-apple-ios14.3-simulator