SE-0554
Deployment target conditional compilation
A proposal to add #if deploymentTargetAtLeast(…), a compile-time check of the minimum OS a module is built for.
Choose code by the deployment target.
The problem. if #available checks the operating system at run time, so it cannot choose between imports, type aliases, conformances or whole declarations. Projects work around this with custom build flags that have to be kept in sync with the deployment target by hand.
The proposal. A compilation condition that takes the same platform-and-version list as #available, ends with *, and combines with !, &&, || and conditions such as canImport. The compiler already knows the deployment target from the target triple.
One lock, the right import.
Use Mutex where the deployment target has it, and fall back everywhere else.
#if deploymentTargetAtLeast(macOS 15, iOS 18, *)
import Synchronization
typealias Lock<State> = Mutex<State>
#else
import os
typealias Lock<State> = OSAllocatedUnfairLock<State>
#endif
From pitch to review.
Pitch
Swift Forums. The idea and its design, discussed in public with the community. Read the pitch
Proposal
Merged. Into the swift-evolution repository as SE-0554, with prototype implementations. Read the proposal
Review
September 29 to October 12, 2026. The formal Swift Evolution review, run by a review manager on the Swift Forums. Follow the review
Details
- Proposal
- SE-0554
- Author
- Jiaxu Li
- Implementation
- Prototypes in the Swift compiler and swift-syntax, behind the experimental feature
DeploymentTargetCondition