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

Erica Sadun erica at ericasadun.com
Mon Mar 14 13:29:06 CDT 2016

Gist: https://gist.github.com/erica/6c3892fe603659b6e5ab

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>
Status: TBD
Review manager: TBD

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.


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))

// More restrictive test for iOS simulator
// Adjust the os test for watchOS, tvOS
#if (arch(i386) || arch(x86_64)) && os(iOS)
    // iOS simulator code
 <https://gist.github.com/erica/6c3892fe603659b6e5ab#detail-design>Detail 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.

 <https://gist.github.com/erica/6c3892fe603659b6e5ab#impact-on-existing-code>Impact 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.

 <https://gist.github.com/erica/6c3892fe603659b6e5ab#current-art>Current 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)
 <https://gist.github.com/erica/6c3892fe603659b6e5ab#alternatives-considered>Alternatives Considered

There are no alternatives considered.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160314/85afffeb/attachment.html>

More information about the swift-evolution mailing list