Skip to content

Add an "upward" link library type for BuildDependencyInfo #456

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

Merged
merged 1 commit into from
May 1, 2025
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
7 changes: 5 additions & 2 deletions Sources/SWBBuildService/BuildDependencyInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ package struct BuildDependencyInfo: Codable {
package enum LibraryType: String, Codable, Sendable {
case dynamic
case `static`
case upward
case unknown
}

Expand Down Expand Up @@ -434,9 +435,11 @@ extension BuildDependencyInfo {
/// - remark: This is written somewhat generically (with the callback blocks) in the hopes that `LinkageDependencyResolver.dependencies(for:...)` can someday adopt it, as the general approach was stolen from there.
package static func findLinkedInputsFromBuildSettings(_ settings: Settings, addFramework: @Sendable (TargetDependencyInfo.Input) async -> Void, addLibrary: @Sendable (TargetDependencyInfo.Input) async -> Void, addError: @Sendable (String) async -> Void) async {
await LdLinkerSpec.processLinkerSettingsForLibraryOptions(settings: settings) { macro, flag, stem in
await addFramework(TargetDependencyInfo.Input(inputType: .framework, name: .stem(stem), linkType: .searchPath, libraryType: .dynamic))
let libType: TargetDependencyInfo.Input.LibraryType = (flag == "-upward_framework") ? .upward : .dynamic
await addFramework(TargetDependencyInfo.Input(inputType: .framework, name: .stem(stem), linkType: .searchPath, libraryType: libType))
} addLibrary: { macro, flag, stem in
await addLibrary(TargetDependencyInfo.Input(inputType: .library, name: .stem(stem), linkType: .searchPath, libraryType: .unknown))
let libType: TargetDependencyInfo.Input.LibraryType = (flag == "-upward-l") ? .upward : .unknown
await addLibrary(TargetDependencyInfo.Input(inputType: .library, name: .stem(stem), linkType: .searchPath, libraryType: libType))
} addError: { error in
await addError(error)
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/SWBBuildServiceTests/BuildDependencyInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ import Foundation
"-merge_framework MergeFwk",
"-no_merge_framework NoMergeFwk",
"-lazy_framework LazyFwk",
"-upward_framework UpwardFwk",

// Apparently both of these uses of -Xlinker are valid
"-Xlinker -reexport_framework -Xlinker XlinkXlinkFwk",
Expand All @@ -328,6 +329,7 @@ import Foundation
"-merge-lMergeLib",
"-no_merge-lNoMergeLib",
"-lazy-lLazyLib",
"-upward-lUpwardLib",

"-Xlinker -reexport-lXlinkerLib",
"-Wl,-reexport-lQuoteLib",
Expand Down Expand Up @@ -397,6 +399,15 @@ import Foundation
}
}

// Check upward framework
for fwkStem in ["UpwardFwk"] {
results.checkTargetInputName(target, .stem(fwkStem)) { input in
#expect(input.inputType == .framework)
#expect(input.linkType == .searchPath)
#expect(input.libraryType == .upward)
}
}

// Check library linkage
for fwkStem in ["Lib", "WeakLib", "ReexportLib", "MergeLib", "NoMergeLib", "LazyLib"] {
results.checkTargetInputName(target, .stem(fwkStem)) { input in
Expand All @@ -413,6 +424,15 @@ import Foundation
}
}

// Check upward library
for fwkStem in ["UpwardLib"] {
results.checkTargetInputName(target, .stem(fwkStem)) { input in
#expect(input.inputType == .library)
#expect(input.linkType == .searchPath)
#expect(input.libraryType == .upward)
}
}

results.checkNoMoreTargetInputs(target)

results.checkTargetOutputPath(target, "/Applications/AppTarget.app")
Expand Down