Skip to content

Commit

Permalink
Merge pull request #124 from giginet/link-dependencies-of-targets
Browse files Browse the repository at this point in the history
Link all dependencies of targets
  • Loading branch information
giginet authored May 29, 2024
2 parents 4e0c4b7 + 947a7cd commit d029413
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion Sources/ScipioKit/Producer/PIF/PIFGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ private struct PIFLibraryTargetModifier {
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:
Expand Down Expand Up @@ -269,9 +271,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<BuildPhase: PIF.BuildPhase>(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) {
func createOrUpdateFlags(for key: PIF.BuildSettings.MultipleValueSetting, to keyPath: KeyPath<ExtraFlags, [String]?>) {
Expand Down

0 comments on commit d029413

Please sign in to comment.