Skip to content

Commit

Permalink
Switch to SwiftPM conditional dependencies API (realm#4003)
Browse files Browse the repository at this point in the history
This API allows us to mostly remove `#if` conditionals which enables
cross compilation from macOS -> Linux. It also removes the thrashing of
Package.resolved if you compile in a docker image.
  • Loading branch information
keith authored Apr 16, 2023
1 parent 5aed7ce commit 3ef44cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "0.2.0"
}
},
{
"identity" : "cryptoswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "19b3c3ceed117c5cc883517c4e658548315ba70b",
"version" : "1.6.0"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
Expand Down
40 changes: 16 additions & 24 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// swift-tools-version:5.7
import PackageDescription

#if os(macOS)
private let addCryptoSwift = false
private let binaryPlugin = true
#else
private let addCryptoSwift = true
private let binaryPlugin = false
#endif

let frameworkDependencies: [Target.Dependency] = [
.product(name: "IDEUtils", package: "swift-syntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
"SwiftyTextTable",
"Yams",
]
+ (addCryptoSwift ? ["CryptoSwift"] : [])

let package = Package(
name: "SwiftLint",
platforms: [.macOS(.v12)],
Expand All @@ -35,14 +15,16 @@ let package = Package(
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.34.1")),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.5"),
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0")
] + (addCryptoSwift ? [.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.6.0"))] : []),
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit.git", from: "0.2.0"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.6.0"))
],
targets: [
.plugin(
name: "SwiftLintPlugin",
capability: .buildTool(),
dependencies: [
.target(name: binaryPlugin ? "SwiftLintBinary" : "swiftlint")
.target(name: "SwiftLintBinary", condition: .when(platforms: [.macOS])),
.target(name: "swiftlint", condition: .when(platforms: [.linux]))
]
),
.executableTarget(
Expand All @@ -62,7 +44,17 @@ let package = Package(
),
.target(
name: "SwiftLintFramework",
dependencies: frameworkDependencies
dependencies: [
.product(name: "IDEUtils", package: "swift-syntax"),
.product(name: "SourceKittenFramework", package: "SourceKitten"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
"SwiftyTextTable",
"Yams",
.product(name: "CryptoSwift", package: "CryptoSwift", condition: .when(platforms: [.linux]))
]
),
.target(
name: "SwiftLintTestHelpers",
Expand Down

0 comments on commit 3ef44cf

Please sign in to comment.