Version identifiers for iOS and Apple platforms

Jacob Carlborg doob at me.com
Sun Feb 23 14:26:45 UTC 2020


Currently the `iOS` version identifier is predefined by the compiler 
when targeting iOS. This is fine. In druntime and Phobos the version 
identifier `Darwin` is used to include macOS, iOS, tvOS and watchOS. 
This is set manually when needed.

I have started to use the `AppleARM` version identifier to indicate iOS, 
tvOS and watchOS. This is set manually when needed. This is not a good 
name because on the simulators `iOS`, `TVOS` and `WatchOS` should be 
defined as well, but the simulators are running x86(-64). Therefore I 
would like to come up with a better name.

In the Apple SDK there's a header file, `TargetConditionals.h` [1] which 
defines a bunch of target specific preprocessor defines. Here's an 
extract of the relevant documentation:

TARGET_OS_MAC       - Generated code will run under Mac OS X variant
    TARGET_OS_OSX    - Generated code will run under OS X devices
    TARGET_OS_IPHONE - Generated code for firmware, devices, or simulator
       TARGET_OS_IOS - Generated code will run under iOS
       TARGET_OS_TV  - Generated code will run under Apple TV OS
       TARGET_OS_WATCH     - Generated code will run under Apple Watch OS
       TARGET_OS_BRIDGE    - Generated code will run under Bridge devices
       TARGET_OS_MACCATALYST    - Generated code will run under macOS
    TARGET_OS_SIMULATOR      - Generated code will run under a simulator

`TARGET_OS_MAC` is defined for any kind of Apple platform. We're 
currently using `Darwin` for this. `TARGET_OS_OSX` is defined for macOS, 
we're using `OSX` for this. `TARGET_OS_IPHONE` is defined for iOS, tvOS 
or watchOS. This is what I have used `AppleARM` for, so far.

Would it be better to rename `AppleARM` to `iPhone`? I'm hesitating a 
bit since I think `iPhone` sounds a bit misleading. It probably has that 
name in the header file due to backward compatibility.

When it comes to the simulators. Should we define one version identifier 
for each simulator device, like `iOSSimulator` and `watchOSSimulator`. 
Or should we just define one version identifier, like `AppleSimulator`, 
for all of them?

[1] 
https://github.com/theos/sdks/blob/master/iPhoneOS11.2.sdk/usr/include/TargetConditionals.h

-- 
/Jacob Carlborg


More information about the digitalmars-d-ldc mailing list