Architectures&Valid Architectures,及xcodebuild -arch

指令集相关的两个配置项


Valid Architectures (VALID_ARCHS)

A space-separated list of architectures for which the target should actually be built. For each target, this is intersected with the list specified in Architectures (ARCHS), and the resulting set is built. This allows individual targets to opt out of building for particular architectures. If the resulting set of architectures is empty, no executable will be produced.

Architectures (ARCHS)

A list of the architectures for which the product will be built. This is usually set to a predefined build setting provided by the platform. If more than one architecture is specified, a universal binary will be produced.

以上是摘自Xcode Help里关于Architectures和Valid Architectures这两个构建设置项的英文描述,可参照https://help.apple.com/xcode/mac/10.2/#/itcaec37c2a6?sub=devf0a9d5aca

设计目的

这两项设置最终决定了构建产物所支持的指令集,即它们所包含的指令集的交集。

  • Valid Architectures (VALID_ARCHS)
    有效的指令集,用来给对应的target设置有效指令集范围。我们在打包时支持的指令集越多,包的体积几乎是按倍数增加,基于这方面的考虑,苹果提供了此项配置用于剔除低版本CUP指令集的支持。另外,在设计原则上所有指令集是向下兼容的,高版本运行低版本指令集时达不到应该有的性能,如果包体积大小的权重高的话也可以采取牺牲性能来达到期望目的,比如用armv7来取代armv7s。
  • Architectures (ARCHS)
    目标指令集,只有设置成有效的(即Valid Architectures (VALID_ARCHS) 所包含的)才会起作用。

与xcodebuild相关

默认情况下xcodebuild会读取BuildSetting里的配置项,但是我们也可以用构建命令的option -arch来指定需要的指令集,而且会覆盖项目中设置的。-arch的说明可以是xcodebuild --help查看。

-arch ARCH                                               
build each target for the architecture ARCH; this will override architectures defined in the project

多个指令集构建时,追加多个-arch即可,如下:

xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos -arch armv7s -arch arm64

你可能感兴趣的:(Architectures&Valid Architectures,及xcodebuild -arch)