Skip to content

Commit dbea3ab

Browse files
committed
Improve search paths for XCFrameworks
When packaging a Swift dylib as an XCFramework, its modules will be at the top-level, so that directory needs to become part of search paths. fixes #5723
1 parent 256c682 commit dbea3ab

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
22722272
if case .xcframework = target.kind {
22732273
let libraries = try self.parseXCFramework(for: target)
22742274
for library in libraries {
2275-
if let headersPath = library.headersPath {
2276-
clangTarget.additionalFlags += ["-I", headersPath.pathString]
2275+
library.headersPaths.forEach {
2276+
clangTarget.additionalFlags += ["-I", $0.pathString]
22772277
}
22782278
clangTarget.libraryBinaryPaths.insert(library.libraryPath)
22792279
}
@@ -2309,8 +2309,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
23092309
if case .xcframework = target.kind {
23102310
let libraries = try self.parseXCFramework(for: target)
23112311
for library in libraries {
2312-
if let headersPath = library.headersPath {
2313-
swiftTarget.additionalFlags += ["-Xcc", "-I", "-Xcc", headersPath.pathString]
2312+
library.headersPaths.forEach {
2313+
swiftTarget.additionalFlags += ["-I", $0.pathString, "-Xcc", "-I", "-Xcc", $0.pathString]
23142314
}
23152315
swiftTarget.libraryBinaryPaths.insert(library.libraryPath)
23162316
}

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public struct LibraryInfo: Equatable {
2323
/// The path to the binary.
2424
public let libraryPath: AbsolutePath
2525

26-
/// The path to the headers directory, if one exists.
27-
public let headersPath: AbsolutePath?
26+
/// The paths to the headers directories.
27+
public let headersPaths: [AbsolutePath]
2828
}
2929

3030

@@ -54,8 +54,8 @@ extension BinaryTarget {
5454
// Construct a LibraryInfo for the library.
5555
let libraryDir = self.artifactPath.appending(component: library.libraryIdentifier)
5656
let libraryFile = try AbsolutePath(validating: library.libraryPath, relativeTo: libraryDir)
57-
let headersDir = try library.headersPath.map { try AbsolutePath(validating: $0, relativeTo: libraryDir) }
58-
return [LibraryInfo(libraryPath: libraryFile, headersPath: headersDir)]
57+
let headersDirs = try library.headersPath.map({ [try AbsolutePath(validating: $0, relativeTo: libraryDir)] }) ?? [] + [libraryDir]
58+
return [LibraryInfo(libraryPath: libraryFile, headersPaths: headersDirs)]
5959
}
6060

6161
public func parseArtifactArchives(for triple: Triple, fileSystem: FileSystem) throws -> [ExecutableInfo] {

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,7 @@ final class BuildPlanTests: XCTestCase {
41214121

41224122
let exeCompileArguments = try result.target(for: "exe").swiftTarget().compileArguments()
41234123
XCTAssertMatch(exeCompileArguments, [.anySequence, "-F", "\(buildPath)", .anySequence])
4124+
XCTAssertMatch(exeCompileArguments, [.anySequence, "-I", "\(Pkg.appending(components: "Framework.xcframework", "\(platform)-\(arch)"))", .anySequence])
41244125

41254126
let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments()
41264127
XCTAssertMatch(exeLinkArguments, [.anySequence, "-F", "\(buildPath)", .anySequence])

0 commit comments

Comments
 (0)