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

Commit f344957

Browse files
authored
Merge pull request #9 from unsignedapps/feature/compute-checksum
Added checksum computation
2 parents 7578d21 + 14456d6 commit f344957

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

Package.resolved

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717

1818
dependencies: [
1919
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "0.0.6"),
20-
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .revision("swift-5.2.3-RELEASE")),
20+
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("release/5.3")),
2121
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.1.3"),
2222
],
2323

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ If the target you are creating an XCFramework happens to be a dependency, swift-
8787

8888
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`.
8989

90+
Because you're probably wanting to [distribute your binary frameworks as Swift Packages][apple-docs] `swift create-xcframework --zip` will also calculate the necessary SHA256 checksum and place it alongside the zip. eg: `ArgumentParser-0.0.6.sha256`.
91+
9092
## GitHub Action
9193

9294
swift-create-xcframework includes a GitHub Action that can kick off and automatically create an XCFramework when you tag a release in your project.
9395

94-
The action produces one XCFramework artifact for every target specified.
96+
The action produces one zipped XCFramework and checksum artifact for every target specified.
9597

9698
**Note:** You MUST use a macOS-based runner (such as `macos-latest`) as xcodebuild doesn't run on Linux.
9799

@@ -152,4 +154,6 @@ Please read the [Contribution Guide](CONTRIBUTING.md) for details on how to cont
152154

153155
## License
154156

155-
swift-create-xcframework is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
157+
swift-create-xcframework is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
158+
159+
[apple-docs]: https://developer.apple.com/documentation/swift_packages/distributing_binary_frameworks_as_swift_packages

Sources/CreateXCFramework/Command.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ struct Command: ParsableCommand {
106106
if self.options.zip {
107107
let zipper = Zipper(package: package)
108108
let zipped = try xcframeworkFiles
109-
.map { pair -> Foundation.URL in
109+
.flatMap { pair -> [Foundation.URL] in
110110
let zip = try zipper.zip(target: pair.0, version: self.options.zipVersion, file: pair.1)
111+
let checksum = try zipper.checksum(file: zip)
111112
try zipper.clean(file: pair.1)
112113

113-
return zip
114+
return [ zip, checksum ]
114115
}
115116

116117
// notify the action if we have one

Sources/CreateXCFramework/PackageInfo.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Build
1010
import Foundation
1111
import PackageModel
1212
import PackageLoading
13+
import SPMBuildCore
1314
import Workspace
1415
import Xcodeproj
1516

@@ -40,6 +41,7 @@ struct PackageInfo {
4041
let graph: PackageGraph
4142
let manifest: Manifest
4243
let toolchain: Toolchain
44+
let workspace: Workspace
4345

4446

4547
// MARJ: - Initialisation
@@ -50,13 +52,18 @@ struct PackageInfo {
5052
self.buildDirectory = self.rootDirectory.appendingPathComponent(options.buildPath, isDirectory: true).absoluteURL
5153

5254
let root = AbsolutePath(self.rootDirectory.path)
53-
55+
5456
self.toolchain = try UserToolchain(destination: try .hostDestination())
55-
self.package = try PackageBuilder.loadPackage(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, diagnostics: self.diagnostics)
56-
self.graph = try Workspace.loadGraph(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, diagnostics: self.diagnostics)
57+
58+
let resources = try UserManifestResources(swiftCompiler: self.toolchain.swiftCompiler)
59+
let loader = ManifestLoader(manifestResources: resources)
60+
self.workspace = Workspace.create(forRootPackage: root, manifestLoader: loader)
61+
62+
self.package = try PackageBuilder.loadPackage(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, xcTestMinimumDeploymentTargets: [:], diagnostics: self.diagnostics)
63+
self.graph = self.workspace.loadPackageGraph(root: root, diagnostics: self.diagnostics)
5764
self.manifest = try ManifestLoader.loadManifest(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, packageKind: .root)
5865
}
59-
66+
6067

6168
// MARK: - Product/Target Names
6269

Sources/CreateXCFramework/Zipper.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ struct Zipper {
4949

5050
return zipURL
5151
}
52+
53+
func checksum (file: Foundation.URL) throws -> Foundation.URL {
54+
let sum = self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path), diagnostics: self.package.diagnostics)
55+
let checksumFile = file.deletingPathExtension().appendingPathExtension("sha256")
56+
try Data(sum.utf8).write(to: checksumFile)
57+
return checksumFile
58+
}
5259

5360
private func zipCommand (source: Foundation.URL, target: Foundation.URL) -> [String] {
5461
return [
@@ -66,12 +73,8 @@ struct Zipper {
6673
// find the package that contains our target
6774
guard let packageRef = self.package.graph.packages.first(where: { $0.targets.contains(where: { $0.name == target } ) }) else { return nil }
6875

69-
// ok lets ask the workspace for that package's version
70-
guard let resources = try? UserManifestResources(swiftCompiler: self.package.toolchain.swiftCompiler) else { return nil }
71-
let workspace = Workspace.create(forRootPackage: AbsolutePath(self.package.rootDirectory.path), manifestLoader: ManifestLoader(manifestResources: resources))
72-
7376
guard
74-
let dependency = try? workspace.managedDependencies.dependency(forNameOrIdentity: packageRef.name),
77+
let dependency = self.package.workspace.state.dependencies[forNameOrIdentity: packageRef.name],
7578
case let .checkout(checkout) = dependency.state,
7679
let version = checkout.version
7780
else {

0 commit comments

Comments
 (0)