Skip to content

Instantly share code, notes, and snippets.

@erica
Last active June 19, 2016 04:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save erica/f53fa6cfef9e5cf17ab139f7528edde2 to your computer and use it in GitHub Desktop.

Aliasing the OS X Platform Configuration Test

  • Proposal: TBD
  • Author: Erica Sadun
  • Status: TBD
  • Review manager: TBD

Introduction

Starting in Sierra, Apple's Mac-based OS (OS X) is renamed to macOS. All user-facing Swift APIs must go through Swift Evolution. While this is a trivial API change, I have put together a formal proposal as is normal and usual for this process.

This proposal adds the #if os(macos) platform configuration test to Swift that acts like the current if os(osx)

Swift Evolution Discussion: [DRAFT] Aliasing the OS X Platform Configuration Test

Motivation

Apple renamed its Mac operating system from OSX to macOS, starting in macOS Sierra. Adding rather than replacing "OSX" enables API adoption to be purely additive and supports the notion that Swift-based applications can and may be deployed to operating systems earlier than Sierrra.

Choosing to use both names originates from the following rationale:

  • The configuration test should not remain as #if os(OSX). That's the wrong name for Sierra's now-supported operating system.
  • Developers can and will still deploy to OS X for Yosemite and El Capitan using Swift.
  • Forcing developers to migrate OSX to macOS places an undue burden on existing code.
  • While aliasing the two may cause issues down the road ("Why does this test have two names?"), I believe Swift developers can easily reason why both variations exist.

Current Art

Swift currently supports the following platform configuration tests, defined in lib/Basic/LangOptions.cpp.

  • The literals true and false
  • The os() function that tests for OSX, iOS, watchOS, tvOS, Linux, Windows, Android, and FreeBSD
  • The arch() function that tests for x86_64, arm, arm64, i386, powerpc64, s390x, and powerpc64le
  • The swift() function that tests for specific Swift language releases, e.g. swift(>=2.2)

Detailed Design

  if (Target.isMacOSX()) {
    addPlatformConditionValue("os", "OSX");
    addPlatformConditionValue("os", "macOS");
  }

Use:

#if os(macOS) 
    // Code specific to macOS or OS X
#endif

Impact on Existing Code

This proposal is purely additive. It will not affect existing code other than adding another way to refer to OS X/macOS. Some developers could potentially find this confusing.

Alternatives Considered

Instead of retaining and aliasing os(OSX), it can be fully replaced by os(macOS). This mirrors the situation with the phoneOS to iOS rename.

Charlie Monroe points out: "Since Swift 3.0 is a code-breaking change my guess is that there is no burden if the Xcode migration assistent automatically changes all #if os(OSX) to #if os(macOS), thus deprecating the term OSX, not burdening the developer at all. If iOS was renamed to phoneOS and kept versioning, you'd still expect #if os(iOS) to be matched when targetting phoneOS and vice-versa."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment