Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link all dependencies of targets #124

Merged
merged 2 commits into from
May 29, 2024
Merged
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
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
Loading