Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 2118f4a

Browse files
authored
Merge pull request #20 from unsignedapps/catalyst
Added support for Catalyst
2 parents c6d46cf + 78ad9cb commit 2118f4a

File tree

8 files changed

+82
-42
lines changed

8 files changed

+82
-42
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
path: Vexil
3535

3636
- name: 📦 Package Vexil
37-
run: cd Vexil && ../.build/release/swift-create-xcframework --zip --zip-version 1.2.2 --platform ios --platform macos --platform tvos --platform watchos Vexil Vexillographer
37+
run: cd Vexil && ../.build/release/swift-create-xcframework --zip --zip-version 1.2.2 --platform ios --platform macos --platform tvos --platform watchos
3838

3939
tests-xcode-12:
4040
name: Test Builds - Xcode 12
@@ -57,4 +57,4 @@ jobs:
5757
path: Vexil
5858

5959
- name: 📦 Package Vexil
60-
run: cd Vexil && ../.build/release/swift-create-xcframework --zip --zip-version 1.2.2 --platform ios --platform macos --platform tvos --platform watchos Vexil Vexillographer
60+
run: cd Vexil && ../.build/release/swift-create-xcframework --zip --zip-version 1.2.2 --platform ios --platform macos --platform tvos --platform watchos

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ You can specify a subset of the platforms to build using the `--platform` option
6363
swift create-xcframework --platform ios --platform macos ...
6464
```
6565

66+
#### Catalyst
67+
68+
You can build your XCFrameworks with support for Mac Catalyst by specifying `--platform maccatalyst` on the command line. As you can't include or exclude Catalyst support in your `Package.swift` we don't try to build it automatically.
69+
6670
### Choosing Products
6771

6872
Because we wrap `xcodebuild`, you can actually build XCFrameworks from anything that will be mapped to an Xcode project as a Framework target. This includes all of the dependencies your Package has.
@@ -126,7 +130,7 @@ jobs:
126130
- uses: actions/checkout@v2
127131

128132
- name: Create XCFramework
129-
uses: unsignedapps/swift-create-xcframework@v1
133+
uses: unsignedapps/swift-create-xcframework@v1.3
130134

131135
# Create a release
132136
# Upload those artifacts to the release
@@ -137,7 +141,7 @@ jobs:
137141
You can install using mint:
138142

139143
```shell
140-
mint install unsignedapps/swift-create-xcframework@1.0.5
144+
mint install unsignedapps/swift-create-xcframework@1.3.0
141145
```
142146

143147
Or manually:

Sources/CreateXCFramework/Command+Options.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension Command {
4444
valueName: TargetPlatform.allCases.map({ $0.rawValue }).joined(separator: "|")
4545
)
4646
)
47-
var platform: [TargetPlatform]
47+
var platform: [TargetPlatform] = []
4848

4949
@Option(help: ArgumentHelp("Where to place the compiled .xcframework(s)", valueName: "directory"))
5050
var output = "."
@@ -69,7 +69,7 @@ extension Command {
6969
// MARK: - Targets
7070

7171
@Argument(help: "An optional list of products (or targets) to build. Defaults to building all `.library` products")
72-
var products: [String]
72+
var products: [String] = []
7373
}
7474
}
7575

Sources/CreateXCFramework/Command.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Command: ParsableCommand {
2727
2828
Supported platforms: \(TargetPlatform.allCases.map({ $0.rawValue }).joined(separator: ", "))
2929
""",
30-
version: "1.2.1"
30+
version: "1.3.0"
3131
)
3232

3333

Sources/CreateXCFramework/PackageInfo.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ struct PackageInfo {
160160
/// check if our command line platforms are supported by the package definition
161161
func supportedPlatforms () throws -> [TargetPlatform] {
162162

163-
let supported = self.options.platform.nonEmpty ?? TargetPlatform.allCases
163+
// if they have specified platforms all good, if not go everything except catalyst
164+
let supported = self.options.platform.nonEmpty ?? TargetPlatform.allCases.filter { $0 != .maccatalyst }
164165

165166
// do we have package platforms defined?
166167
guard let packagePlatforms = self.manifest.platforms.nonEmpty else {
@@ -169,11 +170,11 @@ struct PackageInfo {
169170

170171
// filter our package platforms to make sure everything is supported
171172
let target = packagePlatforms
172-
.compactMap { platform -> TargetPlatform? in
173-
return supported.first(where: { $0.rawValue == platform.platformName })
173+
.compactMap { platform -> [TargetPlatform]? in
174+
return supported.filter({ $0.platformName == platform.platformName })
174175
}
176+
.flatMap { $0 }
175177

176-
// are they different then?
177178
return target
178179
}
179180

Sources/CreateXCFramework/Platforms.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import PackageModel
1111
enum TargetPlatform: String, ExpressibleByArgument, CaseIterable {
1212
case ios
1313
case macos
14+
case maccatalyst
1415
case tvos
1516
case watchos
1617

@@ -19,36 +20,52 @@ enum TargetPlatform: String, ExpressibleByArgument, CaseIterable {
1920
}
2021

2122

23+
var platformName: String {
24+
switch self {
25+
case .ios: return "ios"
26+
case .macos: return "macos"
27+
case .maccatalyst: return "macos"
28+
case .tvos: return "tvos"
29+
case .watchos: return "watchos"
30+
}
31+
}
32+
2233
// MARK: - Target SDKs
2334

2435
struct SDK {
25-
let sdkName: String
26-
let directorySuffix: String
36+
let destination: String
37+
let archiveName: String
38+
let buildSettings: [String: String]?
2739
}
2840

2941
var sdks: [SDK] {
3042
switch self {
3143
case .ios:
3244
return [
33-
SDK(sdkName: "iphoneos", directorySuffix: "-iphoneos"),
34-
SDK(sdkName: "iphonesimulator", directorySuffix: "-iphonesimulator")
45+
SDK(destination: "generic/platform=iOS", archiveName: "iphoneos.xcarchive", buildSettings: nil),
46+
SDK(destination: "generic/platform=iOS Simulator", archiveName: "iphonesimulator.xcarchive", buildSettings: nil)
3547
]
3648

3749
case .macos:
3850
return [
39-
SDK(sdkName: "macosx", directorySuffix: "")
51+
SDK(destination: "platform=macOS", archiveName: "macos.xcarchive", buildSettings: nil)
52+
]
53+
54+
case .maccatalyst:
55+
return [
56+
SDK(destination: "platform=macOS,variant=Mac Catalyst", archiveName: "maccatalyst.xcarchive", buildSettings: [ "SUPPORTS_MACCATALYST": "YES" ])
4057
]
4158

4259
case .tvos:
4360
return [
44-
SDK(sdkName: "appletvos", directorySuffix: "-appletvos"),
45-
SDK(sdkName: "appletvsimulator", directorySuffix: "-appletvsimulator")
61+
SDK(destination: "generic/platform=tvOS", archiveName: "appletvos.xcarchive", buildSettings: nil),
62+
SDK(destination: "generic/platform=tvOS Simulator", archiveName: "appletvsimulator.xcarchive", buildSettings: nil)
4663
]
4764

4865
case .watchos:
4966
return [
50-
SDK(sdkName: "watchos", directorySuffix: "-watchos"),
51-
SDK(sdkName: "watchsimulator", directorySuffix: "-watchsimulator")
67+
SDK(destination: "generic/platform=watchOS", archiveName: "watchos.xcarchive", buildSettings: nil),
68+
SDK(destination: "generic/platform=watchOS Simulator", archiveName: "watchsimulator.xcarchive", buildSettings: nil)
5269
]
5370
}
5471
}

Sources/CreateXCFramework/ProjectGenerator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ struct ProjectGenerator {
7373
graph: self.package.graph,
7474
extraDirs: [],
7575
extraFiles: [],
76-
options: XcodeprojOptions(xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { AbsolutePath($0) }),
76+
options: XcodeprojOptions (
77+
xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { AbsolutePath($0) },
78+
useLegacySchemeGenerator: true
79+
),
7780
diagnostics: self.package.diagnostics
7881
)
7982

Sources/CreateXCFramework/XcodeBuilder.swift

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,23 @@ struct XcodeBuilder {
6868
// MARK: - Build
6969

7070
func build (targets: [String], sdk: TargetPlatform.SDK) throws -> [String: Foundation.URL] {
71-
let process = TSCBasic.Process (
72-
arguments: try self.buildCommand(targets: targets, sdk: sdk),
73-
outputRedirection: .none
74-
)
75-
76-
try process.launch()
77-
let result = try process.waitUntilExit()
78-
79-
switch result.exitStatus {
80-
case let .terminated(code: code):
81-
if code != 0 {
82-
throw Error.nonZeroExit(code)
71+
for target in targets {
72+
let process = TSCBasic.Process (
73+
arguments: try self.buildCommand(target: target, sdk: sdk),
74+
outputRedirection: .none
75+
)
76+
77+
try process.launch()
78+
let result = try process.waitUntilExit()
79+
80+
switch result.exitStatus {
81+
case let .terminated(code: code):
82+
if code != 0 {
83+
throw Error.nonZeroExit(code)
84+
}
85+
case let .signalled(signal: signal):
86+
throw Error.signalExit(signal)
8387
}
84-
case let .signalled(signal: signal):
85-
throw Error.signalExit(signal)
8688
}
8789

8890
return targets
@@ -91,29 +93,40 @@ struct XcodeBuilder {
9193
}
9294
}
9395

94-
private func buildCommand (targets: [String], sdk: TargetPlatform.SDK) throws -> [String] {
96+
private func buildCommand (target: String, sdk: TargetPlatform.SDK) throws -> [String] {
9597
var command: [String] = [
9698
"xcrun",
9799
"xcodebuild",
98100
"-project", self.path.pathString,
99101
"-configuration", self.options.configuration.xcodeConfigurationName,
100-
"-sdk", sdk.sdkName,
101-
"BUILD_DIR=\(self.buildDirectory.path)"
102+
"-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path,
103+
"-destination", sdk.destination,
104+
"BUILD_DIR=\(self.buildDirectory.path)",
105+
"SKIP_INSTALL=NO"
102106
]
103107

108+
// add any build settings
109+
if let settings = sdk.buildSettings {
110+
for setting in settings {
111+
command.append("\(setting.key)=\(setting.value)")
112+
}
113+
}
114+
104115
// add our targets
105-
command += targets.flatMap { [ "-target", $0 ] }
116+
command += [ "-scheme", target ]
106117

107118
// and the command
108-
command += [ "build" ]
119+
command += [ "archive" ]
109120

110121
return command
111122
}
112123

113124
// we should probably pull this from the build output but we just make assumptions here
114125
private func frameworkPath (target: String, sdk: TargetPlatform.SDK) -> Foundation.URL {
115126
return self.buildDirectory
116-
.appendingPathComponent(self.options.configuration.xcodeConfigurationName + sdk.directorySuffix)
127+
.appendingPathComponent(self.productName(target: target))
128+
.appendingPathComponent(sdk.archiveName)
129+
.appendingPathComponent("Products/Library/Frameworks")
117130
.appendingPathComponent("\(self.productName(target: target)).framework")
118131
.absoluteURL
119132
}
@@ -124,6 +137,9 @@ struct XcodeBuilder {
124137
func merge (target: String, frameworks: [Foundation.URL]) throws -> Foundation.URL {
125138
let outputPath = self.xcframeworkPath(target: target)
126139

140+
// try to remove it if its already there, otherwise we're going to get errors
141+
try? FileManager.default.removeItem(at: outputPath)
142+
127143
let process = TSCBasic.Process (
128144
arguments: self.mergeCommand(outputPath: outputPath, frameworks: frameworks),
129145
outputRedirection: .none
@@ -156,7 +172,6 @@ struct XcodeBuilder {
156172

157173
// and the output
158174
command += [ "-output", outputPath.path ]
159-
160175
return command
161176
}
162177

0 commit comments

Comments
 (0)