GEOSwift / geos

GEOS packaging for SPM & CocoaPods
GNU General Public License v2.0
14 stars 22 forks source link

Dynamic linking causes SwiftUI Previews to crash #18

Open sena-mike opened 1 year ago

sena-mike commented 1 year ago

When previewing a module that links against geos SwiftUI previews will fail to link with Cannot preview in this file and Update failed. Tapping on the diagnostic icon reveals a dynamic linker failure at runtime

LoadingError: failed to load library at path ".../Debug-iphonesimulator/PackageFrameworks/AppFeature_-763FCD0D750E0A09_PackageProduct.framework/AppFeature_-763FCD0D750E0A09_PackageProduct": Optional(dlopen(/Users/sena/Library/Developer/Xcode/DerivedData/Modules-dzuyxirpdnkkyqbokjvjlomldapx/Build/Intermediates.noindex/Previews/AppFeature/Products/Debug-iphonesimulator/PackageFrameworks/AppFeature_-763FCD0D750E0A09_PackageProduct.framework/AppFeature_-763FCD0D750E0A09_PackageProduct, 0x0000): Library not loaded: @rpath/geos.framework/geos
|    Referenced from: <1B72

see Library not loaded: @rpath/geos.framework/geos

When I disable dynamic linking in Package.swift the package still builds successfully and SwiftUI previews work again.

Is the reason for .dynamic linking of the upstream libgeos/geos C++ codebase solely for the LGPL license requirements? If so, it should be possible to create a static version of the library for the simulator while maintaining dynamic linking when not targeting the simulator.

The c++ code could be moved into a common module and two new modules be created geos and staticGeos. Both new modules would depend on common, geos would preserve backwards compatibility and be dynamically linked. staticGeos would be available for SwiftUI Previews use cases.

macdrevx commented 1 year ago

Thanks for the suggestion. I'd be happy to review a PR if you want to propose a patch.