SwiftyRSA icon indicating copy to clipboard operation
SwiftyRSA copied to clipboard

Remove type: .dynamic from Package.swift because it breaks SwiftUI previews

Open plindberg opened this issue 2 years ago • 2 comments

Hi!

I’m not sure about the decision to make the library use dynamic linking in #231 (b315992). In a comment of earlier PR #197 upon which the accepted PR was based, @bednarj4 writes:

Because for my own purposes I had to make the library dynamic it has to be explicitly marked as delivered with the application

In our project, we switched from building an XCFramework of SwiftyRSA and using it using a binaryTarget in our Package.swift, to adding it as a package depency for one of our packages.

Later, we found that this broke SwiftUI previews, with a confusing error message about SwiftyRSA.framework not being found, despite the package compiling without any problems.

PotentialCrashError: Update failed

XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/igs838/Library/Developer/Xcode/DerivedData/SwiftUIPreviewTest-dxlkrksehotjktfjrrlfmsapgtgx/Build/Intermediates.noindex/Previews/SomeModule/Products/Debug-iphonesimulator/PackageFrameworks/SomeModule_-370F8FE6BBB70CFC_PackageProduct.framework/SomeModule_-370F8FE6BBB70CFC_PackageProduct": Optional(dlopen(/Users/igs838/Library/Developer/Xcode/DerivedData/SwiftUIPreviewTest-dxlkrksehotjktfjrrlfmsapgtgx/Build/Intermediates.noindex/Previews/SomeModule/Products/Debug-iphonesimulator/PackageFrameworks/SomeModule_-370F8FE6BBB70CFC_PackageProduct.framework/SomeModule_-370F8FE6BBB70CFC_PackageProduct, 0x0000): Library not loaded: @rpath/SwiftyRSA.framework/SwiftyRSA
|    Referenced from: <45253A62-F7DC-35D8-A81C-4560C60AD9C7> /Users/igs838/Library/Developer/Xcode/DerivedData/SwiftUIPreviewTest-dxlkrksehotjktfjrrlfmsapgtgx/Build/Intermediates.noindex/Previews/SomeModule/Products/Debug-iphonesimulator/PackageFrameworks/SomeModule_-370F8FE6BBB70CFC_PackageProduct.framework/SomeModule_-370F8FE6BBB70CFC_PackageProduct
|    Reason: tried: '/Users/igs838/Library/Developer/Xcode/DerivedData/SwiftUIPreviewTest-dxlkrksehotjktfjrrlfmsapgtgx/Build/Intermediates.noindex/Previews/SomeModule/Products/Debug-iphonesimulator/SwiftyRSA.framework/SwiftyRSA' (errno=2), '/Applications/Xcode-14.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/SwiftyRSA.framework/SwiftyRSA' (errno=2), '/usr/lib/swift/SwiftyRSA.framework/SwiftyRSA' (errno=2, not in dyld cache), '/Applications/Xcode-14.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/SwiftyRSA.framework/SwiftyRSA' (errno=2), '/usr/lib/swift/SwiftyRSA.framework/SwiftyRSA' (errno=2, not in dyld cache), '/Applications/Xcode-14.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftyRSA.framework/SwiftyRSA' (errno=2))
|  
|  ==================================
|  
|  |  MessageSendFailure: Message send failure for <ServiceMessage 159: update>

I verified this by creating a project from scratch with just a Swift package with a SwiftUI view. Previews were broken when adding SwiftyRSA (1.8.0) as a (package) dependency, but worked when I instead referenced this fork where I had removed the type argument.

If I understand correctly, Apple’s position is that you typically should not use this parameter. The Swift Package Manager documentation says:

It’s recommended that you don’t explicitly declare the type of library, so Swift Package Manager can choose between static or dynamic linking based on the preference of the package’s consumer.

Unless there’s some specific reason why this must use dynamic linking, perhaps this can be removed?

plindberg avatar May 05 '23 11:05 plindberg

I experience exactly the same thing. Could someone please review this?

igashev avatar May 30 '23 16:05 igashev

The dynamic type also leads to a runtime crash in my tests, if you won't correctly embed it to the product. As well as misleading errors on upload to app store connect.. Would also suggest to remove the type.

Patrick-Remy avatar Aug 14 '23 13:08 Patrick-Remy

@plindberg Thanks so much for this contribution!

pc-scoop avatar Mar 04 '24 15:03 pc-scoop