Run tests with rosetta in ios simulator from command line

Hello everyone,

I am currently building a swift library that has a technical limitation of running tests in iOS Simulator with Rosetta only (since it depends on a library that can only, for now, build it for iOS Simulator x86_64).

Currently, I can run this swift library tests in XCode with an iPhone Rosetta target, but I want to understand how to run these tests from the command line. I am not an expert in xcodebuild tool, so if anyone can help me, I would appreciate a lot.

I have tried, without success, running:

 xcodebuild -scheme MyLibrary -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath build -verbose EXCLUDED_ARCHS=arm64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO test

In which I get an error similar to:

xctest (17305) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at [...] MyLibraryTests' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))))

I suspect it's not running xctest with arch -x86_64. So I have also tried:

 arch -x86_64 xcodebuild -scheme MyLibrary -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath build -verbose EXCLUDED_ARCHS=arm64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO test

But result is the same.

I want to understand what is the command that XCode runs the tests in iOS Simulator with Rosetta. Other IDEs prints the command line used, but I could not find any setting that would tell XCode to print it.

Any help appreciated.

Thanks in advance, --Thiago

You can achieve it on Xcode 14.3 by specifying arch=x86_64 in the destination. But be aware that this sadly makes xcodebuild ignore all the other destination constraints you specify and the first found simulator will be used :-(

-destination 'platform=iOS Simulator,name=iPhone 14,arch=x86_64'

I've tried that initially, but it doesn't works for me. None of the available destinations specifies an arch attribute and when I set this it actually selects all destinations available for testing.

Run tests with rosetta in ios simulator from command line
 
 
Q