Skip to content

WIP: ios: Ensure errors on unguarded use of new APIs

Nirbheek Chauhan requested to merge nirbheek/cerbero:unguarded-usage-ios into main

APIs that are only available on newer macOS versions need to be guarded with __builtin_available for a runtime check that won't load the symbol at all on older OS versions.

WIP because we already check this for macOS, but on iOS we're currently getting spurious errors about things we don't use:

In file included from ../sys/applemedia/videotexturecache-vulkan.mm:43:
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:225:1: error: 'MTLTextureSwizzle' is only available on iOS 13.0 or newer [-Werror,-Wunguarded-availability-new]
MTLTextureSwizzle mvkMTLTextureSwizzleFromVkComponentSwizzle(VkComponentSwizzle vkSwizzle);
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLTexture.h:38:26: note: 'MTLTextureSwizzle' has been marked as being introduced in iOS 13.0 here, but the deployment target is iOS 11.0.0
typedef NS_ENUM(uint8_t, MTLTextureSwizzle) {
                         ^
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:225:19: note: annotate 'mvkMTLTextureSwizzleFromVkComponentSwizzle' with an availability attribute to silence this warning
MTLTextureSwizzle mvkMTLTextureSwizzleFromVkComponentSwizzle(VkComponentSwizzle vkSwizzle);
                  ^
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:228:1: error: 'MTLTextureSwizzleChannels' is only available on iOS 13.0 or newer [-Werror,-Wunguarded-availability-new]
MTLTextureSwizzleChannels mvkMTLTextureSwizzleChannelsFromVkComponentMapping(VkComponentMapping vkMapping);
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLTexture.h:53:3: note: 'MTLTextureSwizzleChannels' has been marked as being introduced in iOS 13.0 here, but the deployment target is iOS 11.0.0
} MTLTextureSwizzleChannels API_AVAILABLE(macos(10.15), ios(13.0));
  ^
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:228:27: note: annotate 'mvkMTLTextureSwizzleChannelsFromVkComponentMapping' with an availability attribute to silence this warning
MTLTextureSwizzleChannels mvkMTLTextureSwizzleChannelsFromVkComponentMapping(VkComponentMapping vkMapping);
                          ^
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:352:1: error: 'MTLPrimitiveTopologyClass' is only available on iOS 12.0 or newer [-Werror,-Wunguarded-availability-new]
MTLPrimitiveTopologyClass mvkMTLPrimitiveTopologyClassFromVkPrimitiveTopology(VkPrimitiveTopology vkTopology);
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPipeline.h:63:29: note: 'MTLPrimitiveTopologyClass' has been marked as being introduced in iOS 12.0 here, but the deployment target is iOS 11.0.0
typedef NS_ENUM(NSUInteger, MTLPrimitiveTopologyClass) {
                            ^
/Users/nirbheek/projects/repos/cerbero.git/build/dist/ios_universal/arm64/lib/pkgconfig/../../include/MoltenVK/mvk_datatypes.h:352:27: note: annotate 'mvkMTLPrimitiveTopologyClassFromVkPrimitiveTopology' with an availability attribute to silence this warning
MTLPrimitiveTopologyClass mvkMTLPrimitiveTopologyClassFromVkPrimitiveTopology(VkPrimitiveTopology vkTopology);
                          ^
3 errors generated.

13.0 is needed for these, and maybe we could bump to that if these aren't actually unneeded.

The current iOS version is 16.0 and Apple suggests limiting old version support to n-1 by saying that 8% of iPhones use iOS 14 and older, and 13% of iPads use iPadOS 14 and older: https://developer.apple.com/support/app-store/

They don't publish stats about iOS 12.0 and older, but that should be even lower, probably less than or around 5%.

If this is a huge problem for someone, they can complain and we can revisit this by, for example, making this code conditional.

Merge request reports