Restrict macOS builds to x86_64 with SPM

Is there a way to restrict macOS SPM builds to only compile/link/test for x86_64?

I develop frameworks with binary dependencies which haven't yet supported arm64. When targeting macOS 11, I am getting linking errors. Xcode is building a x86_64 and arm64 version of the framework, but it can only link to a x86_64 binary dependency.

1 Like

There's always the brute-force solution:

#if !arch(x86_64)
fatalError("This package only supports x86_64; see <github issue> for further information")
#endif
1 Like

I read your comment and I was already dismissing your suggestion; but the more I think about it, the more sense it makes :sweat_smile: The build would finish, I could test my framework, and in case of needing to release it, I can always lipo -remove the "non-working" arm64 version.

I was hoping to find something more "final", such as setting a unsafe flag in the SPM manifest, or the like. Building/testing for debug works flawlessly (since it is using ONLY_NATIVE_ARCH), but it doesn't seam to work on release (or at least I don't know how to properly set unsafe flags).

1 Like

Hopefully one of the SPM developers can weigh in here with another suggestion (but Apple is shutdown this week for the American thanksgiving holiday, so you may not get a response until folks are back at their [remote, because of COVID] desks).

Oh, I wasn't aware of that. Thank you for the heads-up.

Maybe @NeoNacho or @Aciid could shed some light into this?

There is currently no way to restrict platforms or architectures of a package, so the brute force solution @scanon suggested is the only way to communicate this to your users (apart from documentation, of course).

For the question of how to build for a single architecture in Xcode, you should get a build for only the host architecture if you pick "My Mac" but for both architectures if you pick "Any Mac" as your run destination in the UI.

When using xcodebuild, the destination platform=macOS will build for the host and generic/platform=macOS will build for both architectures.

1 Like

Thank you for the confirmation, @NeoNacho.

Building with target "My Mac" with build or release configuration does indeed only build for the host architecture (x86_64 for me). However, building for testing (⌘+⇧+U) on target "My Mac" with release configuration builds for all architectures, which makes my tests fail (since my binary dependencies don't support arm64 yet). Build for testing with debug configuration does the right thing, though.

To sum up: Build for testing seems to ignore the "My Mac" target when using release configuration on SPM projects.

You can quickly replicate this on my open-source package:

  • Open it and set the IG scheme with "My Mac" target.
  • Edit the scheme > Test > Build configuration Release.
  • ⌘+⇧+U to build for testing.

Can you give me pointers on how to run tests on release in Xcode for hosting architecture only?

I think there is currently no solution for this, since the release configuration implies ONLY_ACTIVE_ARCH set to false for packages which means they will always build for all supported architectures.

Thanks for elaborating on this. Would you say this is a problem with XCode or the build system behind it?

I'm having similar problem with the Release configuration on XCode/XCode Server, whereas i still can produce an archive (Release configuration) with xcodebuild command:

xcodebuild archive -scheme "ProjectScheme" -arch "x86_64"

When using xcodebuild command, all packages are built only for a single, in this case native arch x86_64.

Terms of Service

Privacy Policy

Cookie Policy