This patch adds the function _IsOSVersionAtLeast, which uses of Objective-C's @available will compile into. This function uses the Core Foundation API to parse the SystemVersion.plist file, which contains the marketing OS version, which is used by @available, as recommended here: https://reviews.llvm.org/D27827.
The API that I used for this requires at least macOS 10.6/iOS 4.0. Is this far enough back? We could provide to a conservative mapping from darwin versions to marketing versions (as suggested by Alex Lorenz) if this is too new.
Inb4 this patch doesn't have a testcase! I can't figure out how to run the builtins tests, looks like they're not attached to the cmake check-all target, as mentioned in test/CMakeLists.txt:8, and the shell script at test/builtins/Unit/test errors out on me (it can't find the darwin_fat directory), and looks like it hasn't been touched since 2010. How are these tests run? Is there any place where this is documented?
I did test this on my own machine, and works as intended on iOS simulators and macOS.
This patch is part of a feature I proposed last summer:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html
Thanks for taking a look!
Erik