mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
<rdar://problem/46548531> Extend @available to support PackageDescription This introduces a new private availability kind "_PackageDescription" to allow availability testing by an arbitary version that can be passed using a new command-line flag "-swiftpm-manifest-version". The semantics are exactly same as Swift version specific availability. In longer term, it maybe possible to remove this enhancement once there is a language-level availability support for 3rd party libraries. Motivation: Swift packages are configured using a Package.swift manifest file. The manifest file uses a library called PackageDescription, which contains various settings that can be configured for a package. The new additions in the PackageDescription APIs are gated behind a "tools version" that every manifest must declare. This means, packages don't automatically get access to the new APIs. They need to update their declared tools version in order to use the new API. This is basically similar to the minimum deployment target version we have for our OSes. This gating is important for allowing packages to maintain backwards compatibility. SwiftPM currently checks for API usages at runtime in order to implement this gating. This works reasonably well but can lead to a poor experience with features like code-completion and module interface generation in IDEs and editors (that use sourcekit-lsp) as SwiftPM has no control over these features.
20 lines
1.0 KiB
Swift
20 lines
1.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/PackageDescription.swiftmodule -module-name PackageDescription %S/Inputs/PackageDescription.swift
|
|
// RUN: not %target-swift-frontend -typecheck -I %t -package-description-version 4.2 %s 2>&1 | %FileCheck -check-prefix FOURTWO %s
|
|
// RUN: not %target-swift-frontend -typecheck -I %t -package-description-version 5 %s 2>&1 | %FileCheck -check-prefix FIVE %s
|
|
// RUN: %target-swift-ide-test -print-module -module-to-print PackageDescription -source-filename x -I %t | %FileCheck %S/Inputs/PackageDescription.swift
|
|
|
|
import PackageDescription
|
|
|
|
// FOURTWO: warning: 'v3' is deprecated
|
|
// FOURTWO: error: 'v5' is unavailable
|
|
// FOURTWO: note: 'v5' was introduced in PackageDescription 5.0
|
|
// FIVE: error: 'v3' is unavailable
|
|
// FIVE: note: 'v3' was obsoleted in PackageDescription 5.0
|
|
let package = Package(
|
|
swiftVersion: [ .v3, .v4, .v5 ]
|
|
)
|
|
|
|
// FOURTWO: note: 'buildSettings' was introduced in PackageDescription 4.3
|
|
package.buildSettings = ["Foo": "Bar"]
|