Skip to content

Commit

Permalink
Use a single Package.swift file (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed authored Jan 3, 2025
1 parent a0beadd commit 7ff0e08
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 114 deletions.
24 changes: 0 additions & 24 deletions CocoaPods/Package.resolved

This file was deleted.

50 changes: 0 additions & 50 deletions CocoaPods/Package.swift

This file was deleted.

1 change: 0 additions & 1 deletion CocoaPods/Plugins

This file was deleted.

1 change: 0 additions & 1 deletion CocoaPods/Sources

This file was deleted.

1 change: 0 additions & 1 deletion CocoaPods/Tests

This file was deleted.

2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "6913c2c432234297e806fc67a2ab63cfea9ec1458e079359fff74de8f80ee4ee",
"originHash" : "5bc17675d1aa3f88c956fc6d0dfd2370ad92a2c46f3cf83f74f4b153c85c4e77",
"pins" : [
{
"identity" : "jjliso8601dateformatter",
Expand Down
73 changes: 40 additions & 33 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import CompilerPluginSupport
import PackageDescription

// TODO: Once https://github.com/michaeleisel/ZippyJSON/pull/67 is in a release, remove this conditional.
let isBuildingForCocoaPods = Context.environment["SAFEDI_MACRO_COCOAPODS_BUILD"] != nil

let package = Package(
name: "SafeDI",
platforms: [
Expand All @@ -20,6 +23,7 @@ let package = Package(
name: "SafeDI",
targets: ["SafeDI"]
),
] + (isBuildingForCocoaPods ? [] : [
/// A SafeDI plugin that must be run on the root source module in a project.
.plugin(
name: "SafeDIGenerator",
Expand All @@ -29,14 +33,15 @@ let package = Package(
name: "InstallSafeDITool",
targets: ["InstallSafeDITool"]
),
],
]),
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.0"),
.package(url: "https://github.com/michaeleisel/ZippyJSON.git", from: "1.2.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing.git", from: "0.5.0"),
],
] + (isBuildingForCocoaPods ? [] : [
.package(url: "https://github.com/michaeleisel/ZippyJSON.git", from: "1.2.0"),
]),
targets: [
// Macros
.target(
Expand Down Expand Up @@ -84,35 +89,6 @@ let package = Package(
),

// Plugins
.plugin(
name: "SafeDIGenerator",
capability: .buildTool(),
dependencies: ["SafeDITool"]
),
.executableTarget(
name: "SafeDITool",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.byNameItem(name: "ZippyJSON", condition: .when(platforms: [.iOS, .tvOS, .macOS])),
"SafeDICore",
],
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
.testTarget(
name: "SafeDIToolTests",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.byNameItem(name: "ZippyJSON", condition: .when(platforms: [.iOS, .tvOS, .macOS])),
"SafeDITool",
],
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
.plugin(
name: "InstallSafeDITool",
capability: .command(
Expand Down Expand Up @@ -148,5 +124,36 @@ let package = Package(
.swiftLanguageMode(.v6),
]
),
]
] + (isBuildingForCocoaPods ? [] : [
// Plugins
.plugin(
name: "SafeDIGenerator",
capability: .buildTool(),
dependencies: ["SafeDITool"]
),
.executableTarget(
name: "SafeDITool",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.byNameItem(name: "ZippyJSON", condition: .when(platforms: [.iOS, .tvOS, .macOS])),
"SafeDICore",
],
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
.testTarget(
name: "SafeDIToolTests",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.byNameItem(name: "ZippyJSON", condition: .when(platforms: [.iOS, .tvOS, .macOS])),
"SafeDITool",
],
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
])
)
6 changes: 3 additions & 3 deletions SafeDI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Pod::Spec.new do |s|
s.visionos.deployment_target = '1.0'

s.source_files = 'Sources/SafeDI/**/*.{swift}'
s.preserve_paths = 'CocoaPods/', 'Sources/SafeDIMacros', 'Sources/SafeDICore'
s.preserve_paths = 'Sources/SafeDIMacros', 'Sources/SafeDICore'

# The below scripts and flags were inspired by https://soumyamahunt.medium.com/support-swift-macros-with-cocoapods-3911f9317042
script = <<-SCRIPT.squish
env -i PATH="$PATH" "$SHELL" -l -c
"set -x; swift build -c $(echo ${CONFIGURATION} | tr '[:upper:]' '[:lower:]') --product SafeDIMacros
"set -x; SAFEDI_MACRO_COCOAPODS_BUILD=1 swift build -c $(echo ${CONFIGURATION} | tr '[:upper:]' '[:lower:]') --product SafeDIMacros
--sdk \\"`xcrun --show-sdk-path`\\"
--package-path \\"${PODS_TARGET_SRCROOT}/CocoaPods\\"
--package-path \\"${PODS_TARGET_SRCROOT}\\"
--scratch-path \\"${PODS_BUILD_DIR}/Macros/SafeDIMacros\\""
SCRIPT

Expand Down

0 comments on commit 7ff0e08

Please sign in to comment.