Skip to content
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
2 changes: 1 addition & 1 deletion Sources/CreateXCFramework/BuildSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct BuildSetting: ExpressibleByArgument {
let value: String

init?(argument: String) {
let components = argument.components(separatedBy: "=")
let components = argument.split(separator: "=", maxSplits: 1)
guard components.count == 2 else { return nil }
self.name = components[0].trimmingCharacters(in: .whitespacesAndNewlines)
self.value = components[1].trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down
3 changes: 3 additions & 0 deletions Sources/CreateXCFramework/Command+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ extension Command {
@Option(help: ArgumentHelp("Build with a specific configuration", valueName: "debug|release"))
var configuration = PackageModel.BuildConfiguration.release

@Option(help: ArgumentHelp("Action used to create artifact", valueName: "archive|build"))
var action: XcodeBuildAction = .archive

@Flag(inversion: .prefixedNo, help: "Whether to clean before we build")
var clean = true

Expand Down
13 changes: 13 additions & 0 deletions Sources/CreateXCFramework/XcodeBuildAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// XcodeBuildAction.swift
// swift-create-xcframework
//
// Created by Hanley Lee on 2024/6/1.
//

import ArgumentParser

enum XcodeBuildAction: String, ExpressibleByArgument {
case build
case archive
}
32 changes: 24 additions & 8 deletions Sources/CreateXCFramework/XcodeBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ struct XcodeBuilder {
"xcodebuild",
"-project", self.path.pathString,
"-configuration", self.options.configuration.xcodeConfigurationName,
"-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path,
"-destination", sdk.destination,
"BUILD_DIR=\(self.buildDirectory.path)",
"SKIP_INSTALL=NO"
]

if self.options.action == .archive {
command += [
"-archivePath", self.buildDirectory.appendingPathComponent(self.productName(target: target)).appendingPathComponent(sdk.archiveName).path,
]
}

// add SDK-specific build settings
if let settings = sdk.buildSettings {
for setting in settings {
Expand All @@ -136,19 +141,30 @@ struct XcodeBuilder {
command += [ "-scheme", target ]

// and the command
command += [ "archive" ]
if self.options.action == .build {
command += [ "build" ]
} else {
command += [ "archive" ]
}

return command
}

// we should probably pull this from the build output but we just make assumptions here
private func frameworkPath (target: String, sdk: TargetPlatform.SDK) -> Foundation.URL {
return self.buildDirectory
.appendingPathComponent(self.productName(target: target))
.appendingPathComponent(sdk.archiveName)
.appendingPathComponent("Products/Library/Frameworks")
.appendingPathComponent("\(self.productName(target: target)).framework")
.absoluteURL
if self.options.action == .build {
return self.buildDirectory
.appendingPathComponent(sdk.releaseFolder)
.appendingPathComponent("\(self.productName(target: target)).framework")
.absoluteURL
} else {
return self.buildDirectory
.appendingPathComponent(self.productName(target: target))
.appendingPathComponent(sdk.archiveName)
.appendingPathComponent("Products/Library/Frameworks")
.appendingPathComponent("\(self.productName(target: target)).framework")
.absoluteURL
}
}

// MARK: - Debug Symbols
Expand Down