Skip to content

[Proposal] Deployment target conditional compilation - #3478

Merged
xwu merged 4 commits into
swiftlang:mainfrom
Jiaxu-Li:deployment-target-conditional-compilation
Sep 29, 2026
Merged

xwu merged 4 commits into
swiftlang:mainfrom
Jiaxu-Li:deployment-target-conditional-compilation

Conversation

@Jiaxu-Li

@Jiaxu-Li Jiaxu-Li commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This proposal introduces #if deploymentTargetAtLeast(...), a conditional compilation condition based on the minimum deployment target of the module being compiled.

Pitch discussion: https://forums.swift.org/t/pitch-conditional-compilation-for-the-deployment-target/89282

Prototype implementations:

@rjmccall rjmccall added LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document labels Sep 8, 2026

## Proposed solution

Introduce `deploymentTargetAtLeast(...)` as a condition accepted by `#if`:

@xwu xwu Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some question as to whether this terminology would be best aligned with existing usage as minDeploymentTarget, and/or if there might be confusion with "target" as it's used in SwiftPM and whether the use of "deployment" here breaks new ground within Swift itself. But this can all be discussed during review, so no need to hash it out at this point.

@Jiaxu-Li

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've pushed an update.

I fixed the wildcard wording and removed the trailing comma sentence, along with the anyAppleOS details.

For platform matching, a requirement now applies only when its platform names the target, with the most specific one winning when several match. I've written out where this differs from if #available(...) and why.

The Linux case also explains why it's diagnosed.

Happy to revisit the spelling during review.

@Jiaxu-Li
Jiaxu-Li force-pushed the deployment-target-conditional-compilation branch from 3385501 to 56301e9 Compare September 24, 2026 13:35
@xwu

xwu commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Great! Sorry last thing: would you mind creating pull requests against main with your prototypes. They can stay in draft mode and won't be merged as-is, but this would allow us to build test toolchains for people to try out. But I agree the proposal text looks ready! Thanks so much

@Jiaxu-Li

Copy link
Copy Markdown
Contributor Author

@xwu
xwu merged commit eba67f5 into swiftlang:main Sep 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LSG Contains topics under the domain of the Language Steering Group new proposal Adds a new proposal document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants