Skip to content

Commit 1f8d809

Browse files
authored
Set explicit file types in PIF for binary artifacts (#9479)
This ensures that even if an artifact bundle is downloaded and unpacked without a file extension, the underlying build system can identify it correctly. Closes #9471 Depends on swiftlang/swift-build#962 I wasn't able to add a test for this because I can only reproduce it with remote packages
1 parent 7ee2e09 commit 1f8d809

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ extension PackagePIFProjectBuilder {
227227
case macro
228228
}
229229

230+
static func createBinaryModuleFileReference(_ binaryModule: BinaryModule, id: ProjectModel.GUID) -> FileReference {
231+
let fileTypeIdentifier: String?
232+
switch binaryModule.kind {
233+
case .artifactsArchive:
234+
fileTypeIdentifier = "wrapper.artifactbundle"
235+
case .xcframework:
236+
fileTypeIdentifier = "wrapper.xcframework"
237+
case .unknown:
238+
fileTypeIdentifier = nil
239+
}
240+
return FileReference(id: id, path: binaryModule.artifactPath.pathString, fileType: fileTypeIdentifier)
241+
}
242+
230243
/// Constructs a *PIF target* for building a *module* as a particular type.
231244
/// An optional target identifier suffix is passed when building variants of a target.
232245
@discardableResult
@@ -659,7 +672,7 @@ extension PackagePIFProjectBuilder {
659672
break
660673
}
661674
let binaryReference = self.binaryGroup.addFileReference { id in
662-
FileReference(id: id, path: (binaryModule.artifactPath.pathString))
675+
return Self.createBinaryModuleFileReference(binaryModule, id: id)
663676
}
664677
if shouldLinkProduct {
665678
self.project[keyPath: sourceModuleTargetKeyPath].addLibrary { id in

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Products.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ extension PackagePIFProjectBuilder {
346346
break
347347
}
348348
let binaryFileRef = self.binaryGroup.addFileReference { id in
349-
FileReference(id: id, path: binaryModule.artifactPath.pathString)
349+
Self.createBinaryModuleFileReference(binaryModule, id: id)
350350
}
351351
let toolsVersion = self.package.manifest.toolsVersion
352352
self.project[keyPath: mainModuleTargetKeyPath].addLibrary { id in

0 commit comments

Comments
 (0)