Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: [SwiftPM] Swift Language Version Per Target #2392

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Swift Language Version Per Target

* Proposal: [SE-NNNN](NNNN-swiftpm-per-target-swift-language-version-setting.md)
* Authors: [Pavel Yaskevich](https://github.com/xedin)
* Review Manager: TBD
* Status: **Awaiting Review**
* Implementation: https://github.com/apple/swift-package-manager/pull/7439
xedin marked this conversation as resolved.
Show resolved Hide resolved

xedin marked this conversation as resolved.
Show resolved Hide resolved
## Introduction

The current Swift Package Manager manifest API for specifying Swift language version(s) applies to an entire package which is limiting when adopting new language versions that have implications for source compatibility.

Swift-evolution thread: [Pitch: [SwiftPM] Swift Language Version Per Target](https://forums.swift.org/t/pitch-swiftpm-swift-language-version-per-target/71067)

## Motivation

Adopting new language versions at the target granularity allows for gradual migration to prevent possible disruptions. Swift 6, for example, turns on strict concurrency by default, which can have major implications for the project in the form of new errors that were previously downgraded to warnings. SwiftPM should allow to specify a language version per target so that package authors can incrementally transition their project to the newer version.

## Proposed solution

Add a new Swift target setting API, similar to `enable{Upcoming, Experimental}Feature`, to specify a Swift language version that should be used to build the target, if such version is not specified, fallback to the current language version determination logic.

## Detailed design

Add a new `swiftLanguageVersion` API to `SwiftSetting` limited to manifests >= 6.0:

```
public struct SwiftSetting {
// ... other settings

@available(_PackageDescription, introduced: 6.0)
public static func swiftLanguageVersion(
_ version: SwiftVersion,
_ condition: BuildSettingCondition? = nil
) -> SwiftSetting {
...
}
}
```

## Security

New language version setting has no implications on security, safety or privacy.

## Impact on existing packages

Since this is a new API, all existing packages will use the default behavior - version specified at the package level when set or determined based on the tools version.

## Alternatives considered

- Add a new setting for 'known-safe' flags, of which `-swift-version` could be the first. This seems less user-friendly and error prone than re-using `SwiftLanguageVersion`, which has known language versions as its cases (with a plaintext escape hatch when necessary).

- Add new initializer parameter to `Target` API and all of the convenience static functions, this is less flexible because it would require a default value.