Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Change FRAMEWORK_SEARCH_PATH for xcframeworks (#1015)" #1081

Conversation

elliottwilliams
Copy link
Contributor

Hey! Sorry if there's a better way to propose this, but I think there are some issues with #1015 that slipped into production:

As implemented, if you declare a dependency on an XCFramework, then XcodeGen will add every framework bundle inside the XCFramework to the target's FRAMEWORK_SEARCH_PATHS. For example, if I declare

- framework: Carthage/Build/Dwifft.xcframework

the resulting compile command looks like

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift \
… \
-F /Users/emw/Library/Developer/Xcode/DerivedData/project-fwonskwjwimmihaeflmjkuwijxnn/Build/Products/Debug-iphonesimulator \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7 \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/BCSymbolMaps \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/dSYMs \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator/dSYMs \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/dSYMs/Dwifft.framework.dSYM \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator/dSYMs/Dwifft.framework.dSYM \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/dSYMs/Dwifft.framework.dSYM/Contents \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator/dSYMs/Dwifft.framework.dSYM/Contents \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/dSYMs/Dwifft.framework.dSYM/Contents/Resources \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator/dSYMs/Dwifft.framework.dSYM/Contents/Resources \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/dSYMs/Dwifft.framework.dSYM/Contents/Resources/DWARF \
-F /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_i386_x86_64-simulator/dSYMs/Dwifft.framework.dSYM/Contents/Resources/DWARF

This is suboptimal for a number of reasons:

  1. Xcode doesn't need any of these search paths, and if you add an xcframework to a project manually, these search paths are not present. When Xcode builds a target that links an XCFramework, it extracts the appropriate framework from the .xcframework bundle into BUILT_PRODUCTS_DIR. This shows up in build logs as a "ProcessXCFramework" step. So the framework we actually want the compiler to use is not in any of these paths, it's in DerivedData.

  2. If for some reason the extracted framework in DerivedData is missing, these search paths do not provide a useful fallback, because the compiler will attempt to link the first framework it finds, and the framework inside the .xcframework bundle are target-specific. So if I were building for a simulator (target: arm64-apple-ios13.0-simulator), in the above scenario the compiler would find the framework at Dwifft.xcframework/ios-arm64_armv7/Dwifft.framework˙ (target: arm64-apple-ios8.0), and emit an error:

    error: module 'Dwifft' was created for incompatible target arm64-apple-ios8.0: /Users/emw/project/Carthage/Build/Dwifft.xcframework/ios-arm64_armv7/Dwifft.framework/Modules/Dwifft.swiftmodule/arm64.swiftmodule
    
  3. The extra search paths amount to ~1.5KB of arguments per xcframework in many circumstances. This is a bit of a scalability issue, since the compile command is limited by ARG_MAX (1MB on most macs) and the length of the command scales with the number of xcframeworks.

This change reverts that PR and clarifies how to integrate XCFrameworks in the docs.

I think a preferable solution to the issue described in #1015 would have been to reconfigure the target to reference the xcframework directly (not indirectly via something like OTHER_LDFLAGS), and to make sure that target was building to the same BUILT_PRODUCTS_DIR as the rest of the project.

@yonaskolb
Copy link
Owner

@FranzBusch as the original PR author what are your thoughts on this?

@FranzBusch
Copy link
Contributor

Thanks for opening this up @elliottwilliams. When I created the previous PR, we saw some very weird build errors in Xcode when integrating xcframeworks via XcodeGen. The only solution we found was to introduce this frame work search paths setting.

However, we just tested our project based on this PR and the latest Xcode version and saw that these build errors are gone now. Probably Xcode fixed them somewhere between 12.3-12.5.

So from my side, we can go forward and revert this @yonaskolb

@yonaskolb
Copy link
Owner

yonaskolb commented May 21, 2021

Cool, thanks both. @elliottwilliams, if you could just rebase/merge in master, for the conflicts and to fix Linux

@elliottwilliams
Copy link
Contributor Author

Done. Thank you both!

@yonaskolb yonaskolb merged commit 8bfa2f3 into yonaskolb:master May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants