简体   繁体   English

Xcode 13 中的体系结构特定构建设置

[英]Architecture-Specific Build Settings in Xcode 13

I'm trying to use architecture-specific build settings in my Xcode Framework so that I can handle the case of the Apple Silicon Mac and the Intel Mac separately.我正在尝试在我的 Xcode 框架中使用特定于体系结构的构建设置,以便我可以分别处理 Apple Silicon Mac 和 Intel Mac 的情况。 I need to use this build setting as a macro in Metal to check whether the half data type is supported on the CPU (it's supported on Apple Silicon but not supported on Intel).我需要将此构建设置用作 Metal 中的宏来检查 CPU 是否支持half数据类型(Apple Silicon 支持但 Intel 不支持)。

My current implementation uses an xcconfig file with the following line:我当前的实现使用带有以下行的 xcconfig 文件:

IS_X86_64[arch=x86_64] = 1

Then, in my build settings I have the following user-defined condition (from the xcconfig):然后,在我的构建设置中,我有以下用户定义的条件(来自 xcconfig):

用户定义的构建设置(来自 xcconfig)

I then create the macro IS_INTEL so it can be used in Metal:然后我创建宏IS_INTEL以便它可以在 Metal 中使用:

为 Metal 创建 IS_INTEL 宏

Here's The Problem这是问题所在

In theory I feel like this should work.从理论上讲,我觉得这应该可行。 However, running my Metal app on my Intel mac yields 0 for IS_X86_64 .但是,在我的英特尔 mac 上运行我的 Metal 应用程序会为IS_X86_64生成0 The first thing I did was check whether I set up my build setting correctly and replaced我做的第一件事是检查我是否正确设置了构建设置并替换了

IS_X86_64[arch=x86_64] = 1 with IS_X86_64[arch=*] = 1 IS_X86_64[arch=x86_64] = 1IS_X86_64[arch=*] = 1

This worked so I knew that the problem had to be that my current architecture wasn't being represented correctly.这行得通,所以我知道问题一定是我当前的架构没有被正确表示。 Diving further into why this was happening, it turns out that the value for CURRENT_ARCH (which should hold the value for the current device architecture that the project is being run on) is undefined_arch .进一步探究为什么会发生这种情况,事实证明CURRENT_ARCH的值(应该保存项目正在运行的当前设备架构的值)是undefined_arch

In their Xcode 10 release notes , apple mentioned something about undefined_arch saying:在他们的Xcode 10 release notes中,苹果提到了一些关于undefined_arch的内容:

The new build system passes undefined_arch as the value for the ARCH environment variable when running shell script build phases.新的构建系统在运行 shell 脚本构建阶段时将 undefined_arch 作为 ARCH 环境变量的值传递。 The value was previously not well defined.该值以前没有很好地定义。 Any shell scripts depending on this value must behave correctly for all defined architectures being built, available via the ARCHS environment variable.取决于此值的任何 shell 脚本必须对正在构建的所有已定义架构正确运行,可通过 ARCHS 环境变量获得。

However, I'm not building my project on the shell and I don't have any shell scripts.但是,我没有在 shell 上构建我的项目,也没有任何 shell 脚本。 Does anyone know how I can fix this so that architecture-specific build settings behave as they should?有谁知道我该如何解决这个问题,以便特定于体系结构的构建设置按应有的方式运行?

You can check the architecture via built-in macros.您可以通过内置宏检查架构。 You can see how they are used in usr/include/TargetConditionals.h :您可以在usr/include/TargetConditionals.h中查看它们的使用方式:

#if __is_target_arch(x86_64)
    ...
#endif

More macros:更多宏:

__is_target_arch(arm64)
__is_target_arch(arm64e)
__is_target_os(ios)
__is_target_environment(macabi)
__is_target_environment(simulator)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM