Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • how to build a static library on M1 mac that supports iOS simulator of Intel Mac?
  • Or was my thinking wrong from the beginning?
like image 347
Rookie Avatar asked Jan 04 '21 14:01

Rookie


People also ask

What architecture does IOS simulator use?

actually i386 architecture is for iPhone simulator where as x86_64 architecture is for iPad simulators, both are 32 and 64bit compatible.

Is IOS simulator arm64?

Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions. Seeing these when trying to create an xcframework for Apple Silicon that supports Mac Catalyst and the iOS Simulator: Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions.

How do I run a simulator on an m1-based Mac?

To run a simulator on an M1-based Mac, your linked frameworks need to support an ARM64 for M1 slice. This is accomplished by application vendors shipping a new product packaged as an XCFramework rather than the traditional Framework. This new product version can include an M1 Simulator slice for testing.

Why can’t we run on ARM64 simulators on M1 MacBooks?

When we run in M1 Macbooks we are unable to run on arm64 simulators and get the following error: Our SDK is built into an XCframework bundle, however this issue still persists.

Is it possible to build the static library into its own xcframework?

We have tried building the static library into its own XCframework as well by separating the architectures into two different binaries, one for Device and one for Simulator, however we still didn't get it to work.

Is it possible to debug a universal binary on Apple Silicon?

It’s possible to debug both slices of a universal binary on Apple silicon, but you must run the x86_64 slice under Rosetta translation. Xcode 12.2 and later is a requirement for building universal binaries. Earlier versions of Xcode don’t contain the support needed to build and test universal versions of your macOS code.


1 Answers

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

like image 189
Rookie Avatar answered Sep 18 '22 13:09

Rookie