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

Added checksum computation #9

Merged
merged 3 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(

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

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ If the target you are creating an XCFramework happens to be a dependency, swift-

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

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

## GitHub Action

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

The action produces one XCFramework artifact for every target specified.
The action produces one zipped XCFramework and checksum artifact for every target specified.

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

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

## License

swift-create-xcframework is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
swift-create-xcframework is available under the MIT license. See the [LICENSE](LICENSE) file for more info.

[apple-docs]: https://developer.apple.com/documentation/swift_packages/distributing_binary_frameworks_as_swift_packages
5 changes: 3 additions & 2 deletions Sources/CreateXCFramework/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ struct Command: ParsableCommand {
if self.options.zip {
let zipper = Zipper(package: package)
let zipped = try xcframeworkFiles
.map { pair -> Foundation.URL in
.flatMap { pair -> [Foundation.URL] in
let zip = try zipper.zip(target: pair.0, version: self.options.zipVersion, file: pair.1)
let checksum = try zipper.checksum(file: zip)
try zipper.clean(file: pair.1)

return zip
return [ zip, checksum ]
}

// notify the action if we have one
Expand Down
15 changes: 11 additions & 4 deletions Sources/CreateXCFramework/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Build
import Foundation
import PackageModel
import PackageLoading
import SPMBuildCore
import Workspace
import Xcodeproj

Expand Down Expand Up @@ -40,6 +41,7 @@ struct PackageInfo {
let graph: PackageGraph
let manifest: Manifest
let toolchain: Toolchain
let workspace: Workspace


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

let root = AbsolutePath(self.rootDirectory.path)

self.toolchain = try UserToolchain(destination: try .hostDestination())
self.package = try PackageBuilder.loadPackage(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, diagnostics: self.diagnostics)
self.graph = try Workspace.loadGraph(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, diagnostics: self.diagnostics)

let resources = try UserManifestResources(swiftCompiler: self.toolchain.swiftCompiler)
let loader = ManifestLoader(manifestResources: resources)
self.workspace = Workspace.create(forRootPackage: root, manifestLoader: loader)

self.package = try PackageBuilder.loadPackage(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, xcTestMinimumDeploymentTargets: [:], diagnostics: self.diagnostics)
self.graph = self.workspace.loadPackageGraph(root: root, diagnostics: self.diagnostics)
self.manifest = try ManifestLoader.loadManifest(packagePath: root, swiftCompiler: self.toolchain.swiftCompiler, packageKind: .root)
}


// MARK: - Product/Target Names

Expand Down
13 changes: 8 additions & 5 deletions Sources/CreateXCFramework/Zipper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ struct Zipper {

return zipURL
}

func checksum (file: Foundation.URL) throws -> Foundation.URL {
let sum = self.package.workspace.checksum(forBinaryArtifactAt: AbsolutePath(file.path), diagnostics: self.package.diagnostics)
let checksumFile = file.deletingPathExtension().appendingPathExtension("sha256")
try Data(sum.utf8).write(to: checksumFile)
return checksumFile
}

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

// ok lets ask the workspace for that package's version
guard let resources = try? UserManifestResources(swiftCompiler: self.package.toolchain.swiftCompiler) else { return nil }
let workspace = Workspace.create(forRootPackage: AbsolutePath(self.package.rootDirectory.path), manifestLoader: ManifestLoader(manifestResources: resources))

guard
let dependency = try? workspace.managedDependencies.dependency(forNameOrIdentity: packageRef.name),
let dependency = self.package.workspace.state.dependencies[forNameOrIdentity: packageRef.name],
case let .checkout(checkout) = dependency.state,
let version = checkout.version
else {
Expand Down