From 3326feab3dac120c16af63243615592990d33516 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Wed, 26 Jun 2024 17:08:59 +0200 Subject: [PATCH] Enable SwiftConcurrency feature in new compilers (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Enable SwiftConcurrency feature in new compilers ## :recycle: Current situation & Problem This PR makes sure to enabled the `SwiftConcurrency` feature also with Swift 6 compilers. Further, we add SwiftLint if requested from the environment. ## :gear: Release Notes * Support SwiftConcurrency in Swift 6 compilers´ * Add SwiftLint build tool if `SPEZI_DEVELOPMENT_SWIFTLINT` environment variable is set. ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md). --- Package.swift | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index dc2732a..7c361a5 100644 --- a/Package.swift +++ b/Package.swift @@ -8,9 +8,17 @@ // SPDX-License-Identifier: MIT // +import class Foundation.ProcessInfo import PackageDescription +#if swift(<6) +let swiftConcurrency: SwiftSetting = .enableExperimentalFeature("SwiftConcurrency") +#else +let swiftConcurrency: SwiftSetting = .enableUpcomingFeature("SwiftConcurrency") +#endif + + let package = Package( name: "SpeziFoundation", defaultLocalization: "en", @@ -24,6 +32,7 @@ let package = Package( products: [ .library(name: "SpeziFoundation", targets: ["SpeziFoundation"]) ], + dependencies: swiftLintPackage(), targets: [ .target( name: "SpeziFoundation", @@ -31,14 +40,37 @@ let package = Package( .process("Resources") ], swiftSettings: [ - .enableExperimentalFeature("StrictConcurrency") - ] + swiftConcurrency + ], + plugins: [] + swiftLintPlugin() ), .testTarget( name: "SpeziFoundationTests", dependencies: [ .target(name: "SpeziFoundation") - ] + ], + swiftSettings: [ + swiftConcurrency + ], + plugins: [] + swiftLintPlugin() ) ] ) + + +func swiftLintPlugin() -> [Target.PluginUsage] { + // Fully quit Xcode and open again with `open --env SPEZI_DEVELOPMENT_SWIFTLINT /Applications/Xcode.app` + if ProcessInfo.processInfo.environment["SPEZI_DEVELOPMENT_SWIFTLINT"] != nil { + [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")] + } else { + [] + } +} + +func swiftLintPackage() -> [PackageDescription.Package.Dependency] { + if ProcessInfo.processInfo.environment["SPEZI_DEVELOPMENT_SWIFTLINT"] != nil { + [.package(url: "https://github.com/realm/SwiftLint.git", .upToNextMinor(from: "0.55.1"))] + } else { + [] + } +}