scinfu/SwiftSoup

Crash-on-launch with Mac Catalyst and Hardened Runtime

nsands opened this issue · 4 comments

For my iOS/Mac-Catalyst app, building and running for iOS works fine. However, when building the same project for macOS, it crashes on launch with the following linking errors:

dyld: warning, LC_RPATH @loader_path/../Frameworks in /Users/me/Library/Developer/Xcode/DerivedData/SomeThing-dgiyxowwnvkddybvtaotntgetcmr/Build/Products/Debug-maccatalyst/Some Thing.app/Contents/MacOS/Some Thing being ignored in restricted program because of @loader_path (Codesign main executable with Library Validation to allow @ paths)
dyld: warning, LC_RPATH @executable_path/Frameworks in /Users/me/Library/Developer/Xcode/DerivedData/SomeThing-dgiyxowwnvkddybvtaotntgetcmr/Build/Products/Debug-maccatalyst/Some Thing.app/Contents/MacOS/Some Thing being ignored in restricted program because of @executable_path (Codesign main executable with Library Validation to allow @ paths)
dyld: Library not loaded: @rpath/SwiftSoup.framework/Versions/A/SwiftSoup
  Referenced from: /Users/me/Library/Developer/Xcode/DerivedData/SomeThing-dgiyxowwnvkddybvtaotntgetcmr/Build/Products/Debug-maccatalyst/Some Thing.app/Contents/MacOS/Some Thing
  Reason: image not found

Note that "Hardened Runtime' is enabled (as per default) but I've selected the exception for "Disable Library Validation".

I believe this may be similar to the issue discussed at: https://forums.developer.apple.com/message/365393#365393

However, I'm not sure if the same solution is suited to a Mac-Catalyst app.

How did you import swift soup in your project?
can you share a demo project?

Here's a detailed, step-by-step procedure to reproduce a SwiftSoup library linking error by creating a new iOS/Mac-Catalyst app from scratch.

  • Download ZIP from Git Hub and unzip
  • Create new XCode project for an iOS "Single View" app
  • In project "General" settings, select the checkbox for "Mac" in the Deployment Info "Devices" list
  • Drag "SwiftSoup.xcodeproj" from the unzipped "SwiftSoup-master" folder into the new XCode project, immediately below the project icon in the project contents
  • In the project build phases, add a Dependency for "SwiftSoup-iOS"
  • In the project build phases, add a Link Binary With Libraries (from SwiftSoup-iOS target)
  • Optionally, select the checkbox for "Disable Library Validation" in the "Hardened Runtime" section of the "Signing & Capabilities" project settings
  • Select the "My Mac" build scheme
  • Build and Run

The error is a little different to the one above, due to an unsigned new app:

dyld: Library not loaded: @rpath/SwiftSoup.framework/Versions/A/SwiftSoup
  Referenced from: /Users/me/Library/Developer/Xcode/DerivedData/Some_Thing-brwhqjlawvhjaxdqzobpdlhddeoy/Build/Products/Debug-maccatalyst/Some Thing.app/Contents/MacOS/Some Thing
  Reason: no suitable image found.  Did find:
	/Users/me/Library/Developer/Xcode/DerivedData/Some_Thing-brwhqjlawvhjaxdqzobpdlhddeoy/Build/Products/Debug-maccatalyst/SwiftSoup.framework/SwiftSoup: code signature in (/Users/me/Library/Developer/Xcode/DerivedData/Some_Thing-brwhqjlawvhjaxdqzobpdlhddeoy/Build/Products/Debug-maccatalyst/SwiftSoup.framework/SwiftSoup) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
	/Users/me/Library/Developer/Xcode/DerivedData/Some_Thing-brwhqjlawvhjaxdqzobpdlhddeoy/Build/Products/Debug-maccatalyst/SwiftSoup.framework/Versions/A/SwiftSoup: code signature in (/Users/me/Library/Developer/Xcode/DerivedData/Some_Thing-brwhqjlawvhjaxdqzobpdlhddeoy/Build/Products/Debug-maccatalyst/SwiftSoup.framework/Versions/A/SwiftSoup) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

NB: If I disable "Hardened Runtime" completely, then the app links SwiftSoup successfully, and runs just fine.

You know what... in my actual real app, I have now got it to build and run successfully including linking SwiftSoup. By some strange combination of removing "Hardened Runtime" completely, then re-adding it (and NOT selecting "Disable Library Validation") it is now working. These are the settings for which the problem originally occurred, but now it does not. So I'm confused, but at least now it's working. Thanks for taking the time to look into it. I'll close this issue.