Skip to content

Commit 0710653

Browse files
authored
Handle static xcframeworks not being unpacked (#156)
SwiftPM may not unpack static xcframeworks. Handle this gracefully, if SwiftPM doesn't need the framework we don't either. Fixes #155.
1 parent 836fca8 commit 0710653

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/PackLib/Packer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ public struct Packer: Sendable {
147147
let src = URL(fileURLWithPath: "\(name).framework/\(name)", relativeTo: binDir)
148148
let magic = Data("!<arch>\n".utf8)
149149
let thinMagic = Data("!<thin>\n".utf8)
150-
let bytes = try FileHandle(forReadingFrom: src).read(upToCount: magic.count)
150+
guard let bytes = try? FileHandle(forReadingFrom: src).read(upToCount: magic.count) else {
151+
// if we can't find the binary, it might be a static framework that SwiftPM
152+
// did not copy into the .build directory. we don't need to pack it anyway.
153+
break
154+
}
151155
// if the magic matches one of these it's a static archive; don't embed it.
152156
// https://github.com/apple/llvm-project/blob/e716ff14c46490d2da6b240806c04e2beef01f40/llvm/include/llvm/Object/Archive.h#L33
153157
// swiftlint:disable:previous line_length

Sources/XToolSupport/XTool.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ extension ParsableCommand where Self: SendableMetatype {
6666
print("Cancelled.")
6767
self.exit()
6868
} catch {
69+
if ProcessInfo.processInfo.environment["XTL_DEBUG_ERRORS"] != nil {
70+
print("ERROR DETAILS:")
71+
print(String(reflecting: error))
72+
}
6973
self.exit(withError: error)
7074
}
7175
}

0 commit comments

Comments
 (0)