[Draft] Expanding Build Configuration Tests for Simulator and Device targets

Gist: target.md · GitHub

Feedback, corrections, suggestions requested and welcome. Thanks, -- Erica

Expanding Build Configuration Tests for Simulator and Device targets

Proposal: SE-00XX
Author(s): Erica Sadun <http://github.com/erica&gt;
Status: TBD
Review manager: TBD
<target.md · GitHub

This proposal introduces a build configuration test to differentiate device and simulator builds. This test represent a common categorization requirement for Metal, Keychain, and AVFoundation Camera code.

This proposal was discussed on-list in the Expanding Build Configuration Tests for Simulator and Device targets <applewebdata://E091D50D-DE8F-40D6-9BFD-E493DCEAA4F4> thread.

<target.md · GitHub

Swift target detection is unnecessarily complicated and error prone as they're based on testing for target architectures that may potentially change over time. Making simulator detection dependent on a mismatch between architecture and the operating system shows an obvious gap in the current build configuration test suite.

// Test for a simulator destination
#if (arch(i386) || arch(x86_64)) && (!os(OSX))
    print("Simulator")
#else
    print("Device")
#endif

// More restrictive test for iOS simulator
// Adjust the os test for watchOS, tvOS
#if (arch(i386) || arch(x86_64)) && os(iOS)
    // iOS simulator code
#endif
<target.md · GitHub Design

This proposal adds #if target(simulator) and #if target(device) to distinguish whether application code is compiled to run in a simulated environment or on a device. Code running on desktop systems are considered to be on-device.

<target.md · GitHub on Existing Code

This proposal does not impact existing code. As it is unnecessarily complicated to craft fixits that look for common test patterns, I recommend only that the new configurations be mentioned in release notes and added to the Using Swift with Cocoa and Objective-C document.

<target.md · GitHub Art

Swift currently supports the following configuration tests:

The literals true and false
The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux
The arch() function that tests for x86_64, arm, arm64, and i386
The swift() function that tests for specific Swift language releases, e.g. swift(>=2.2)
<target.md · GitHub Considered

There are no alternatives considered.

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

···

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

···

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution > <swift-evolution@swift.org> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

I'm afraid it is just the source code.

Dmitri

···

On Mon, Mar 14, 2016 at 1:04 PM, Erica Sadun <erica@ericasadun.com> wrote:

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution >> <swift-evolution@swift.org> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

That reminds me, arm64 and aarch64 are equivalent, inconsistently used, and not synonymous. I’m not suggesting that anything change in Erica’s proposal, but it might be worth a little bit of discussion to decide whether arm64 will be the one, and only, name for 64-bit arm in swift.

- Will

···

On Mar 14, 2016, at 1:05 PM, Dmitri Gribenko via swift-evolution <swift-evolution@swift.org> wrote:

I'm afraid it is just the source code.

Dmitri

On Mon, Mar 14, 2016 at 1:04 PM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution >>> <swift-evolution@swift.org> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>>*/
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

That reminds me, arm64 and aarch64 are equivalent, inconsistently used, and not synonymous. I’m not suggesting that anything change in Erica’s proposal, but it might be worth a little bit of discussion to decide whether arm64 will be the one, and only, name for 64-bit arm in swift.

What do you mean by "not synonymous”?

-Chris

···

On Mar 14, 2016, at 1:41 PM, William Dillon via swift-evolution <swift-evolution@swift.org> wrote:

- Will

On Mar 14, 2016, at 1:05 PM, Dmitri Gribenko via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I'm afraid it is just the source code.

Dmitri

On Mon, Mar 14, 2016 at 1:04 PM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution >>>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>>*/

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>>*/
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

(didn’t reply all)

Synonymous is not the right word, you’re right. I mean that you can’t use them interchangeably.

For example, in Foundation TargetConditionals.h, only __arm64__ was tested for (I’m assuming the build system sets that somehow when Foundation is built for iOS). In Linux, it isn’t __aarch64__ is. So, I can’t just interchange them. Because of this, I end up with #elif __arm64__ || __aarch64__ and that feels a little silly.

- Will

···

On Mar 14, 2016, at 1:41 PM, Chris Lattner <clattner@apple.com> wrote:

On Mar 14, 2016, at 1:41 PM, William Dillon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

That reminds me, arm64 and aarch64 are equivalent, inconsistently used, and not synonymous. I’m not suggesting that anything change in Erica’s proposal, but it might be worth a little bit of discussion to decide whether arm64 will be the one, and only, name for 64-bit arm in swift.

What do you mean by "not synonymous”?

-Chris

- Will

On Mar 14, 2016, at 1:05 PM, Dmitri Gribenko via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I'm afraid it is just the source code.

Dmitri

On Mon, Mar 14, 2016 at 1:04 PM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution >>>>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>>*/

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com <mailto:gribozavr@gmail.com>>*/
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

The reference for build configuration statements[1] has a list of platforms and operating systems. If that list is out of date, it's a documentation bug — so thanks for pointing that out!

<rdar://problem/25244216> TSPL: Build configuration statements is missing Windows, FreeBSD, powerpc64, and powerpc64le

If you want to look in source, the list in lib/Basic/LangOptions.cpp reads as follows:

static const StringRef SupportedConditionalCompilationOSs = {
  "OSX",
  "tvOS",
  "watchOS",
  "iOS",
  "Linux",
  "FreeBSD",
  "Windows"
};

static const StringRef SupportedConditionalCompilationArches = {
  "arm",
  "arm64",
  "i386",
  "x86_64",
  "powerpc64",
  "powerpc64le"
};

1:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID538

···

On Mar 14, 2016, at 1:05 PM, Dmitri Gribenko via swift-evolution <swift-evolution@swift.org> wrote:

I'm afraid it is just the source code.

Dmitri

On Mon, Mar 14, 2016 at 1:04 PM, Erica Sadun <erica@ericasadun.com> wrote:

Can you point me to a reference on this so I can keep up to date, or is it all just source and accepted proposals?

Thanks, -- E

On Mar 14, 2016, at 1:58 PM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Mon, Mar 14, 2016 at 11:29 AM, Erica Sadun via swift-evolution >>> <swift-evolution@swift.org> wrote:

The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux

and Windows, FreeBSD.

The arch() function that tests for x86_64, arm, arm64, and i386

and powerpc64, powerpc64le.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution