swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.71k stars 1.33k forks source link

[SR-13366] Package Manager fails to install XCFrameworks with Dynamic Library #4511

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13366
Radar rdar://problem/67361241
Original Reporter seanreinhardtapps (JIRA User)
Type Bug

Attachment: Download

Environment Version 12.0 beta 4 (12A8179i)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 75c780fed553462cf37e12e5ee11694c

Issue Description:

Closely associated with SR-13343, cannot install a signed XCFramework containing a Dynamic Library MachO type. The application builds and fails to launch with a Provisioning Profile error.

The error is not reproducible when the XCFramework is manually installed and Signed by the App (Embed & Sign setting).

We normally ship the XCFramework with instruction to set the embed setting to Embed and Sign, which as far as I could tell is not a possible configuration through the package manager.

swift-ci commented 4 years ago

Comment by Sean Reinhardt (JIRA)

Issue reproduced on Xcode Version 12.0 beta 5 (12A8189h)

typesanitizer commented 4 years ago

@swift-ci create

swift-ci commented 4 years ago

Comment by Sean Reinhardt (JIRA)

Package manager continues to fail to install XCFrameworks with dynamic libraries on Version 12.0 beta 6 (12A8189n).

It has actually become worse now. Instead of being a code sign issue, Xcode is now not even copying the dylib into the app bundle. When running, the app crashed with a dyld error:

dyld: Library not loaded: @rpath/HyprMX.framework/HyprMX
  Referenced from: /private/var/containers/Bundle/Application/DA46E1D4-863A-4688-9F37-4298CB27832B/180-D.app/180-D
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

I also check the build product, and the .app does not have a Frameworks folder, let alone the expected binary in it.

swift-ci commented 4 years ago

Comment by Sean Reinhardt (JIRA)

Package manager is still broken on Xcode 12 GM Version 12.0 (12A7209), although now the behavior looks like it did with beta 4/5 again.

Swift Packages, containing XCFrameworks that are dynamic libraries fail to install on device:

Unable to install "182-D"
Domain: com.apple.dt.MobileDeviceErrorDomain
Code: -402620395
--
A valid provisioning profile for this executable was not found.
Domain: com.apple.dt.MobileDeviceErrorDomain
Code: -402620395
User Info: {
    DVTRadarComponentKey = 487925;
    MobileDeviceErrorCode = "(0xE8008015)";
    "com.apple.dtdevicekit.stacktrace" = (
    0   DTDeviceKitBase                     0x000000012b9d993f DTDKCreateNSErrorFromAMDErrorCode + 220
    1   DTDeviceKitBase                     0x000000012ba18124 __90-[DTDKMobileDeviceToken installApplicationBundleAtPath:withOptions:andError:withCallback:]_block_invoke + 155
    2   DVTFoundation                       0x000000010f211b53 DVTInvokeWithStrongOwnership + 71
    3   DTDeviceKitBase                     0x000000012ba17e65 -[DTDKMobileDeviceToken installApplicationBundleAtPath:withOptions:andError:withCallback:] + 1440
    4   IDEiOSSupportCore                   0x000000012b888d28 __118-[DVTiOSDevice(DVTiPhoneApplicationInstallation) processAppInstallSet:appUninstallSet:installOptions:completionBlock:]_block_invoke.292 + 3513
    5   DVTFoundation                       0x000000010f3402ba __DVT_CALLING_CLIENT_BLOCK__ + 7
    6   DVTFoundation                       0x000000010f341edc __DVTDispatchAsync_block_invoke + 1191
    7   libdispatch.dylib                   0x00007fff6b9a06c4 _dispatch_call_block_and_release + 12
    8   libdispatch.dylib                   0x00007fff6b9a1658 _dispatch_client_callout + 8
    9   libdispatch.dylib                   0x00007fff6b9a6c44 _dispatch_lane_serial_drain + 597
    10  libdispatch.dylib                   0x00007fff6b9a75d6 _dispatch_lane_invoke + 363
    11  libdispatch.dylib                   0x00007fff6b9b0c09 _dispatch_workloop_worker_thread + 596
    12  libsystem_pthread.dylib             0x00007fff6bbfba3d _pthread_wqthread + 290
    13  libsystem_pthread.dylib             0x00007fff6bbfab77 start_wqthread + 15
);
}
--

System Information

macOS Version 10.15.6 (Build 19G2021)
Xcode 12.0 (17219)
swift-ci commented 4 years ago

Comment by Sean Reinhardt (JIRA)

Determined I was able to deploy an unsigned version of the XCFramework to a device.

Previous tests have been conducted with an XCFramework that had been signed with a distribution certificate.

swift-ci commented 2 years ago

Comment by Elena Gordienko (JIRA)

I've run into the very same issue using Xcode 13.1 (Swift 5.5.1)

There is a module in my project, which has a package dependency with a binary target – an xcframework containing a dylib. The module itself isn't a package and it is linked to the project binary as a dynamic library.

It works fine on a simulator, but when it comes to running on a real device, there is an error indicating that the framework from the package could not be found:

dyld[676]: Library not loaded: @rpath/SomeFramework.framework/SomeFramework
Referenced from:
/private/var/containers/Bundle/Application/<hash>/MyApp.app/Frameworks/MyModule.framework/MyModule
<path> (no such file), ...

It seems that the framework with dylib isn't even copied to the app bundle (meaning MyApp.app/Frameworks). So when I modify Runpath Search Path in Build Settings to include path, where it is located (that is MyApp.app/Frameworks/MyModule.framework/Frameworks/), I get another error:

dyld[586]: Library not loaded: @rpath/SomeFramework.framework/SomeFramework
Referenced from: /private/var/containers/Bundle/Application/<hash>/MyApp.app/Frameworks/MyModule.framework/MyModule
Reason: tried: 
'/private/var/containers/Bundle/Application/<hash>/MyApp.app/Frameworks/MyModule.framework/Frameworks/SomeFramework.framework/SomeFramework' 
(code signature in <hash> '/private/var/containers/Bundle/Application/<hash>/MyApp.app/Frameworks/MyModule.framework/Frameworks/SomeFramework.framework/SomeFramework' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), ...

I believe this could be a bug in SwiftPM and not a project configuration issue.