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

Added the --stack-evolution option #56

Merged
merged 3 commits into from
Nov 4, 2021
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
3 changes: 3 additions & 0 deletions Sources/CreateXCFramework/Command+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ extension Command {
@Option(help: "The path to a .xcconfig file that can be used to override Xcode build settings. Relative to the package path.")
var xcconfig: String?

@Flag(help: "Enables Library Evolution for the whole build stack. Normally we apply it only to the targets listed to be built to work around issues with projects that don't support it.")
var stackEvolution: Bool = false

@Option(help: ArgumentHelp("Arbitrary Xcode build settings that are passed directly to the `xcodebuild` invocation. Can be specified multiple times.", valueName: "NAME=VALUE"))
var xcSetting: [BuildSetting] = []

Expand Down
4 changes: 3 additions & 1 deletion Sources/CreateXCFramework/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ struct Command: ParsableCommand {

// we've applied the xcconfig to everything, but some dependencies (*cough* swift-nio)
// have build errors, so we remove it from targets we're not building
try project.enableDistribution(targets: productNames, xcconfig: AbsolutePath(package.distributionBuildXcconfig.path).relative(to: AbsolutePath(package.rootDirectory.path)))
if self.options.stackEvolution == false {
try project.enableDistribution(targets: productNames, xcconfig: AbsolutePath(package.distributionBuildXcconfig.path).relative(to: AbsolutePath(package.rootDirectory.path)))
}

// save the project
try project.save(to: generator.projectPath)
Expand Down
6 changes: 5 additions & 1 deletion Sources/CreateXCFramework/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct PackageInfo {
.absoluteURL
}

var hasDistributionBuildXcconfig: Bool {
self.overridesXcconfig != nil || self.options.stackEvolution == false
}

var distributionBuildXcconfig: Foundation.URL {
return self.projectBuildDirectory
.appendingPathComponent("Distribution.xcconfig")
Expand Down Expand Up @@ -232,7 +236,7 @@ enum SupportedPlatforms {
case packageValid (plan: [SupportedPlatform])
}

extension SupportedPlatform: Equatable, Comparable {
extension SupportedPlatform: Comparable {
public static func == (lhs: SupportedPlatform, rhs: SupportedPlatform) -> Bool {
return lhs.platform == rhs.platform && lhs.version == rhs.version
}
Expand Down
12 changes: 4 additions & 8 deletions Sources/CreateXCFramework/ProjectGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ struct ProjectGenerator {

/// Writes out the Xcconfig file
func writeDistributionXcconfig () throws {
guard self.package.hasDistributionBuildXcconfig else {
return
}

try makeDirectories(self.projectPath)

let path = AbsolutePath(self.package.distributionBuildXcconfig.path)
Expand All @@ -56,14 +60,6 @@ struct ProjectGenerator {
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
"""
)

if package.options.platform.contains(.maccatalyst) {
stream (
"""
SUPPORTS_MACCATALYST=YES
"""
)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Sources/CreateXCFramework/XcodeBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ struct XcodeBuilder {
}
}

// enable evolution for the whole stack
if self.options.stackEvolution {
command.append("BUILD_LIBRARY_FOR_DISTRIBUTION=YES")
}

// add build settings provided in the invocation
options.xcSetting.forEach { setting in
self.options.xcSetting.forEach { setting in
command.append("\(setting.name)=\(setting.value)")
}

Expand Down
16 changes: 15 additions & 1 deletion Sources/CreateXCFramework/Zipper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct Zipper {
guard let packageRef = self.package.graph.packages.first(where: { $0.targets.contains(where: { $0.name == target }) }) else { return nil }

guard
let dependency = self.package.workspace.state.dependencies[forNameOrIdentity: packageRef.name],
let dependency = self.package.workspace.state.dependencies[forNameOrIdentity: packageRef.packageName],
case let .checkout(checkout) = dependency.state,
let version = checkout.version
else {
Expand All @@ -91,3 +91,17 @@ struct Zipper {
try FileManager.default.removeItem(at: file)
}
}

#if swift(>=5.5)
private extension ResolvedPackage {
var packageName: String {
self.manifestName
}
}
#else
private extension ResolvedPackage {
var packageName: String {
self.name
}
}
#endif