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

Commit da4be8f

Browse files
committed
Added the --zip-version option
1 parent a3658c9 commit da4be8f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# swift-create-xcframework
22

3-
`swift-create-xcframework` is a very simple tool designed to wrap `xcodebuild` and the process of creating multiple frameworks for a Swift Package and merging them into a single XCFramework.
3+
swift-create-xcframework is a very simple tool designed to wrap `xcodebuild` and the process of creating multiple frameworks for a Swift Package and merging them into a single XCFramework.
44

55
## Usage
66

@@ -10,9 +10,9 @@ Inside your Swift Package folder you can just run:
1010
swift create-xcframework
1111
```
1212

13-
By default `swift-create-xcframework` will build XCFrameworks for all library products in your Package.swift, or any targets you specify on the command line (this can be for any dependencies you include as well).
13+
By default swift-create-xcframework will build XCFrameworks for all library products in your Package.swift, or any targets you specify on the command line (this can be for any dependencies you include as well).
1414

15-
Then for every target or product specified, `swift-create-xcframework` will:
15+
Then for every target or product specified, swift-create-xcframework will:
1616

1717
1. Generate an Xcode Project for your package (in `.build/swift-create-xcframework`).
1818
2. Build a `.framework` for each supported platform/SDK.
@@ -42,14 +42,14 @@ var package = Package(
4242
)
4343
```
4444

45-
By default `swift-create-xcframework` will build `ExampleGenerator.xcframework` that supports: macosx, iphoneos, iphonesimulator. Additional `.library` products would be built automatically as well.
45+
By default swift-create-xcframework will build `ExampleGenerator.xcframework` that supports: macosx, iphoneos, iphonesimulator. Additional `.library` products would be built automatically as well.
4646

4747
### Choosing Platforms
4848

4949
You can narrow down what gets built
5050
If you omit the platforms specification, we'll build for all platforms that support Swift Binary Frameworks, which at the time of writing is just the Apple SDKs: macosx, iphoneos, iphonesimulator, watchos, watchsimulator, appletvos, appletvsimulator.
5151

52-
**Note:** Because only Apple's platforms are supported at this time, `swift-create-xcframework` will ignore Linux and other platforms in the Package.swift.
52+
**Note:** Because only Apple's platforms are supported at this time, swift-create-xcframework will ignore Linux and other platforms in the Package.swift.
5353

5454
You can specify a subset of the platforms to build using the `--platform` option, for example:
5555

@@ -79,6 +79,14 @@ By default it builds all top-level library products in your Package.swift.
7979

8080
Because of the low-friction to adding command line options with [swift-argument-parser](https://github.com/apple/swift-argument-parser), there are a number of useful command line options available, so `--help` should be your first port of call.
8181

82+
## Packaging for distribution
83+
84+
swift-create-xcframework provides a `--zip` option to automatically zip up your newly created XCFrameworks ready for upload to GitHub as a release artefact, or anywhere you choose.
85+
86+
If the target you are creating an XCFramework happens to be a dependency, swift-create-xcframework will look back into the package graph, locate the version that dependency resolved to, and append the version number to your zip file name. eg: `ArgumentParser-0.0.6.zip`
87+
88+
If the target you are creating is a product from the root package, unfortunately there is no standard way to identify the version number. For those cases you can specify one with `--zip-version`.
89+
8290
## Installation
8391

8492
You can install using mint:
@@ -95,7 +103,7 @@ cd swift-create-xcframework
95103
make install
96104
```
97105

98-
Either should pop the `swift-create-xcframework` binary into `/usr/local/bin`. And because the `swift` binary is extensible, you can then call it as a subcommand of `swift` itself:
106+
Either should pop the swift-create-xcframework binary into `/usr/local/bin`. And because the `swift` binary is extensible, you can then call it as a subcommand of `swift` itself:
99107

100108
```shell
101109
swift create-xcframework --help

Sources/CreateXCFramework/Command+Options.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extension Command {
4343
@Flag(help: "Whether to wrap the .xcframework(s) up in a versioned zip file ready for deployment")
4444
var zip: Bool
4545

46+
@Option(help: ArgumentHelp("The version number to append to the name of the zip file\n\nIf the target you are packaging is a dependency, swift-create-xcframework will look into the package graph and locate the version number the dependency resolved to. As there is no standard way to specify the version inside your Swift Package, --zip-version lets you specify it manually.", valueName: "version"))
47+
var zipVersion: String?
48+
4649

4750
// MARK: - Targets
4851

Sources/CreateXCFramework/Command.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct Command: ParsableCommand {
9696
let zipper = Zipper(package: package)
9797
try xcframeworkFiles
9898
.forEach { pair in
99-
try zipper.zip(target: pair.0, file: pair.1)
99+
try zipper.zip(target: pair.0, version: self.options.zipVersion, file: pair.1)
100100
try zipper.clean(file: pair.1)
101101
}
102102
}

Sources/CreateXCFramework/Zipper.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ struct Zipper {
2323

2424
// MARK: - Zippering
2525

26-
func zip (target: String, file: Foundation.URL) throws {
26+
func zip (target: String, version: String?, file: Foundation.URL) throws {
2727

28-
let suffix = self.versionSuffix(target: target) ?? ""
28+
let suffix = self.versionSuffix(target: target, default: version) ?? ""
2929
let zipPath = file.path.replacingOccurrences(of: "\\.xcframework$", with: "\(suffix).zip", options: .regularExpression)
3030
let zipURL = URL(fileURLWithPath: zipPath)
3131

@@ -58,7 +58,7 @@ struct Zipper {
5858
]
5959
}
6060

61-
private func versionSuffix (target: String) -> String? {
61+
private func versionSuffix (target: String, default fallback: String?) -> String? {
6262

6363
// find the package that contains our target
6464
guard let packageRef = self.package.graph.packages.first(where: { $0.targets.contains(where: { $0.name == target } ) }) else { return nil }
@@ -72,7 +72,7 @@ struct Zipper {
7272
case let .checkout(checkout) = dependency.state,
7373
let version = checkout.version
7474
else {
75-
return nil
75+
return fallback.flatMap { "-" + $0 }
7676
}
7777

7878
return "-" + version.description

0 commit comments

Comments
 (0)