From 7c161ed0c7ea516535de8ff8ed2f180dce6846af Mon Sep 17 00:00:00 2001 From: giginet Date: Sun, 26 May 2024 22:19:45 +0900 Subject: [PATCH 1/2] Link all dependencies of targets --- .../ScipioKit/Producer/PIF/PIFGenerator.swift | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift b/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift index 0b34525e..4b6afdca 100644 --- a/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift +++ b/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift @@ -222,9 +222,11 @@ private struct PIFLibraryTargetModifier { // These values are required to ship built frameworks to AppStore as embedded frameworks settings[.MARKETING_VERSION] = "1.0" settings[.CURRENT_PROJECT_VERSION] = "1" + + let frameworkType = buildOptionsMatrix[pifTarget.name]?.frameworkType ?? buildOptions.frameworkType // Set framework type - switch buildOptions.frameworkType { + switch frameworkType { case .dynamic: settings[.MACH_O_TYPE] = "mh_dylib" case .static: @@ -268,9 +270,42 @@ private struct PIFLibraryTargetModifier { } configuration.buildSettings = settings + + linkAllDependencies(of: pifTarget) return configuration } + + /// Link all dependencies of the target + /// The original implementations of PIFBuilder links all dependencies to the PackageProduct targets + /// However, Scipio ignores PackageProduct so targets' dependencies haven't be linked + private func linkAllDependencies(of pifTarget: PIF.Target) { + let buildFiles = pifTarget.dependencies.enumerated().map { (index, dependency) in + PIF.BuildFile(guid: guid("FRAMEWORKS_BUILD_FILE_\(index)"), + targetGUID: dependency.targetGUID, + platformFilters: dependency.platformFilters) + } + + if let buildPhase = fetchBuildPhase(of: PIF.FrameworksBuildPhase.self, in: pifTarget) { + buildPhase.buildFiles.append(contentsOf: buildFiles) + } else { + let buildPhase = PIF.FrameworksBuildPhase( + guid: guid("FRAMEWORKS_BUILD_PHASE"), + buildFiles: buildFiles + ) + pifTarget.buildPhases.append(buildPhase) + } + } + + /// Fetch BuildPhase of the passed type + private func fetchBuildPhase(of buildPhasesType: BuildPhase.Type, in pifTarget: PIF.Target) -> BuildPhase? { + pifTarget.buildPhases.compactMap({ $0 as? BuildPhase }).first + } + + /// Build GUID with suffixes + private func guid(_ suffixes: String...) -> String { + "GUID::SCIPIO::\(pifTarget.name)::" + suffixes.joined(separator: "::") + } // Append extraFlags from BuildOptionsMatrix to each target settings private func appendExtraFlagsByBuildOptionsMatrix(to settings: inout PIF.BuildSettings) { From 947a7cdbec7a44926d4036ceaa231da0b070f1d1 Mon Sep 17 00:00:00 2001 From: giginet Date: Tue, 28 May 2024 18:43:21 +0900 Subject: [PATCH 2/2] Fix SwiftLint violations --- Sources/ScipioKit/Producer/PIF/PIFGenerator.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift b/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift index 4b6afdca..af05c7c2 100644 --- a/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift +++ b/Sources/ScipioKit/Producer/PIF/PIFGenerator.swift @@ -222,7 +222,7 @@ private struct PIFLibraryTargetModifier { // These values are required to ship built frameworks to AppStore as embedded frameworks settings[.MARKETING_VERSION] = "1.0" settings[.CURRENT_PROJECT_VERSION] = "1" - + let frameworkType = buildOptionsMatrix[pifTarget.name]?.frameworkType ?? buildOptions.frameworkType // Set framework type @@ -270,12 +270,12 @@ private struct PIFLibraryTargetModifier { } configuration.buildSettings = settings - + linkAllDependencies(of: pifTarget) return configuration } - + /// Link all dependencies of the target /// The original implementations of PIFBuilder links all dependencies to the PackageProduct targets /// However, Scipio ignores PackageProduct so targets' dependencies haven't be linked @@ -301,7 +301,7 @@ private struct PIFLibraryTargetModifier { private func fetchBuildPhase(of buildPhasesType: BuildPhase.Type, in pifTarget: PIF.Target) -> BuildPhase? { pifTarget.buildPhases.compactMap({ $0 as? BuildPhase }).first } - + /// Build GUID with suffixes private func guid(_ suffixes: String...) -> String { "GUID::SCIPIO::\(pifTarget.name)::" + suffixes.joined(separator: "::")