What's the difference between "Architectures" and "Valid Architectures" in Xcode Build Settings?
Asked Answered
M

3

121

What's the meaning of them and can I set them in different values?

Marmite answered 3/10, 2012 at 2:35 Comment(0)
P
118

Architectures are the ones you want to build, valid architectures are the ones you could conceive of building with your codebase.

So maybe you only want to build your binary for armv7s, but the same source code would compile fine for armv7 and armv6. So VALID_ARCHS = armv6 armv7 armv7s, but you set ARCHS = armv7s because that's all you actually want to build with your code.

Or, in Apple-ese:

ARCHS (Architectures)

Space-separated list of identifiers. Specifies the architectures (ABIs, processor models) to which the binary is targeted. When this build setting specifies more than one architecture, the generated binary may contain object code for each of the specified architectures.

and:

VALID_ARCHS (Valid Architectures)

Space-separated list of identifiers. Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary.

Source: Xcode Build Setting Reference

In practice, you leave VALID_ARCHS alone and don't worry about changing it, and just fiddle with ARCHS to set the architectures you want to build. Typically, you set a Debug build to just NATIVE_ARCH, since you only want to build the debug version for the machine you'll be testing/running it on, and Release builds for the full spectrum of architectures you plan to support.

Photosphere answered 3/10, 2012 at 2:39 Comment(2)
@DanMoore The "resulting architecture list" is done in memory at build time.Vetavetch
@onmyway133 Most of the time, you don't want VALID_ARCHS. If you were writing inline asm for only certain architectures, you might change VALID_ARCHS to reflect that your code is no longer intended for any but those architectures. Mostly, though, it's just a cue to you from Xcode that indicates which architectures it can build for, and you pick from there for your ARCHS.Photosphere
P
6

From Apple document,we know that the binary Xcode will build is the list Valid Architectures intersected with Architectures.

So ,i don't think Jeremy's answer is right, as he say:

So maybe you only want to build your binary for armv7s, but the same source code would
compile fine for armv7 and armv6. So VALID_ARCHS = armv6 armv7 armv7s, but you set ARCHS = armv7s because that's all you actually want to build with your code.

When you set VALID_ARCHS = armv6 armv7 armv7s,and set ARCHS = armv7s,the result of binary Xcode will build is armv7s,it could not compatible with armv6/armv7.

And if you want to compatible with armv6/armv7/armv7s,you must set VALID_ARCHS = armv6 armv7 armv7s and ARCHS = armv6.In this way , the result of binary Xcode will build is armv6, and it can run fine on both armv6/armv7/armv7s as arm processor is backwards compatible.

Pauli answered 9/5, 2014 at 4:24 Comment(1)
He was right: "because that's all you actually want to build with your code."Plumber
C
4

Pre xcode 12 era

VALID_ARCHS could support such workflow:

  • You set VALID_ARCHS on a target.
  • When calling xcodebuild you pass the archs you want to build for with xcodebuild ARCHS=... to say which architectures you want to include in your binaries (they could be universal).

Xcode will take intersection of the two and build the targets for them. Imagine a target only supports arm64, while most of your targets support x86_64 and arm64. You call xcodebuild ARCHS="x86_64 arm64". This is what happens:

  • You set on the target: VALID_ARCHS=arm64
  • xcodebuild sets ARCHS to: arm64 x86_64
  • Target will be built for intersection arm64

However, if you were to use ARCHS, this is what happens

  • You set on the target: ARCHS=arm64
  • xcodebuild overwrites ARCHS to arm64 x64
  • Target will be built for arm64 and x86_64! <- not what you wanted.

xcode 12 era and beyond

https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes

VALID_ARCHS is deprecated. Instead EXCLUDED_ARCHS should be used on targets to exclude some architectures.

So now to do the same workflow, you set DISABLED_ARCHS=x86_64 on the aforementioned target.

Cassation answered 28/9, 2022 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.