Repository navigation
packer: fix framework names and fat static archives in binary targets - #198
guitaripod wants to merge 2 commits into
Conversation
eabc6df to
e4c1959
Compare
chintan100
left a comment
There was a problem hiding this comment.
Tested this on macOS (Xcode 27 / Swift 6.4) with sentry-cocoa 8.53.0, building with xtool dev build --triple arm64-apple-ios-simulator and running on an iOS 26.5 simulator, comparing main (d802c71) with main + this PR:
Sentry (static) |
Sentry-Dynamic |
|
|---|---|---|
main |
static Sentry.framework gets embedded, so the simulator install fails: Failed to iterate on macho slices … Frameworks/Sentry.framework/Sentry |
Sentry.framework isn't embedded, so launch crashes: Library not loaded: @rpath/Sentry.framework/Sentry |
| this PR | not embedded; app launches, SentrySDK.isEnabled == true |
dynamic Sentry.framework embedded; app launches, SentrySDK.isEnabled == true |
So both packaging bugs from #130 are fixed for Sentry (the SourceKit-LSP point in #130 isn't covered by this PR).
One thing I noticed: findFrameworkName(for:in:) runs for every binary target, since the Planner always passes frameworkName: nil, not only when \(name).framework is missing as the description says. With several binary targets whose names share a prefix (say Foo and FooBar), the prefix match plus the unordered directory listing could resolve Foo to FooBar.framework. Checking for \(name).framework first and scanning only as a fallback would avoid that; reading LibraryPath from the xcframework's Info.plist would give an exact mapping.
|
Another real-world case for the FAT detection half of this PR, in case it helps it land: MPVKit 1.1.0-n9.0.2 (libmpv, FFmpeg and their dependencies, 38 xcframeworks). Every framework binary I checked in it (37) is a universal file whose slices are static archives, the same shape as the static Sentry build described here:
On current main these are taken for dynamic frameworks and copied into I measured this with a local patch that checks every slice rather than with this branch. All slices are archives here, so the first-slice check in this PR should classify them the same way. #383 reported the same shape for |
Some xcframeworks wrap static archives in a universal (fat) Mach-O, such as the static Sentry framework and the MPVKit frameworks. Only the outer magic was checked, so these were taken for dynamic frameworks and embedded, and installing the app then failed with "contained no image slices". Treat a binary as static when every slice of a universal binary is an archive. Refs xtool-org#130
A binary target can ship a framework named differently from the target: Sentry-Dynamic.xcframework contains Sentry.framework, and SentryObjC-Dynamic.xcframework contains SentryObjC.framework. Looking for <target>.framework missed them, so they were never embedded and the app crashed at launch with "Library not loaded". Read the LibraryPath that the xcframework's Info.plist lists for the build triple, matched by platform, variant and architecture the way SwiftPM picks the library it links. The xcframework comes from the package for local binary targets and from .build/artifacts for remote or zipped ones. When none is found, the <target>.framework convention still applies. Refs xtool-org#130
e4c1959 to
f3e164e
Compare
Walkthrough
Pre-merge checks:
|
|
I rebased this onto current main and reworked both halves:
I re-tested with sentry-cocoa 9.34.0 ( |
What does this PR do?
Fixes the two packaging bugs from #130. The SourceKit-LSP point in that issue is not covered here.
Sentry-Dynamic.xcframeworkcontainsSentry.framework, andSentryObjC-Dynamic.xcframeworkcontainsSentryObjC.framework. The packer now reads theLibraryPaththat the xcframework'sInfo.plistlists for the build triple, matched by platform, variant and architecture the way SwiftPM picks the library it links. Remote and zipped xcframeworks are read from.build/artifacts/<package>/<target>/, local ones from the target path thatswift package describereports. When no xcframework is found,<target>.frameworkis used as before. There is no prefix matching or directory scan.fat_archorfat_arch_64) counts as static when every slice is anararchive. Only the outer magic was checked before, so the static Sentry framework (and the MPVKit andGoogleAdsOnDeviceConversionframeworks) got embedded and the install failed.How was it tested?
Unit tests in
PackerTests.swiftcover theLibraryPathselection (device, simulator, Mac Catalyst, macOS, tvOS, visionOS, an unmatched architecture, an invalid plist) and the archive check (bare and thin archives,fat_archandfat_arch_64with archive slices, mixed slices, plain Mach-O, truncated and bogus headers). The full suite passes on macOS and Linux (Swift 6.4.2), andmake lintis clean.End to end on macOS 27.3 with Xcode 27.3 and sentry-cocoa 9.34.0:
xtool dev buildforarm64-apple-ios-simulatorandarm64-apple-ios, then a launch on an iOS 27.3 simulator,main(a2875dd) against this branch:mainSentry-DynamicLibrary not loaded: @rpath/Sentry.framework/SentrySentry.frameworkembedded, launches,SentrySDK.isEnabled == trueSentry(static)Frameworks/Sentry.framework/Sentry contained no image slicesSentrySDK.isEnabled == trueSentryObjC-DynamicLibrary not loaded: @rpath/SentryObjC.framework/SentryObjCSentryObjC.frameworkembedded, launches,SentryObjCSDK.isEnabled == true.binaryTarget(name: "VendoredSentry", path: "Frameworks/Sentry-Dynamic.xcframework")Library not loaded: @rpath/Sentry.framework/SentrySentry.frameworkembedded, launches,SentrySDK.isEnabled == trueThe device builds embed the arm64 iOS slices of the same frameworks (not installed on a device). I ran the matrix with the default SwiftBuild build system and again with the native one. The results match, except that native SwiftPM linked the
Sentry-Dynamicapp against the static Sentry slice, so that app also launches onmainthere, and this branch correctly leaves the static copy out of the bundle.AI tool usage
How much of the code in this PR was AI-assisted? (check one)
Summary by CodeRabbit