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

Failed to consume XCFramework built for distribution #7313

Closed
dcacenabes opened this issue Jun 28, 2021 · 13 comments · Fixed by #7753
Closed

Failed to consume XCFramework built for distribution #7313

dcacenabes opened this issue Jun 28, 2021 · 13 comments · Fixed by #7753

Comments

@dcacenabes
Copy link

dcacenabes commented Jun 28, 2021

Goals

I am trying to build Realm as an XCFramework with ABI stability and use it in our app. For that, I am setting REALM_BUILD_LIBRARY_FOR_DISTRIBUTION = YES; in RealmSwift.xcconfig file and then building an xcframework with Xcode 12.5. After successfully generating the frameworks (Realm and RealmSwift), I am then importing them into my project and building the app with Xcode 13 beta.

Expected Results

My application successfully builds with a different version of the swift compiler.

Actual Results

We get errors:
Failed to build module 'RealmSwift'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.19.104 clang-1300.0.18.4)'). Please select a toolchain which matches the SDK.

Steps for others to Reproduce

  • Make sure Xcode 12.5 toolchain is selected for the command line build.
  • Set REALM_BUILD_LIBRARY_FOR_DISTRIBUTION to YES in RealmSwift.xcconfig file
  • Run script: ./build.sh xcframework ios
  • From the build/ folder, grab both Realm and RealmSwift xcframework files and drag them into the sample project
  • Build the app with Xcode 13

Code Sample

Sample project can be found at
https://github.com/dcacenabes/ABIDemo

Version of Realm and Tooling

Realm framework version: 10.8.0

Xcode version: 12.5 and 13.0 beta

iOS/OSX version: ios 14 and 15

Dependency manager + version: Tried both with Cocoapods and manually adding the framework to the project. Same result.

@ejm01
Copy link
Contributor

ejm01 commented Jun 30, 2021

If you're building the xcframeowrk with Xcode 12.5, which is using Swift 5.4 tools, is your xcframework building in an app using Xcode 12.5?
Are you able to build the xcframework with 13.0 beta so that it's built with Swift 5.5?

Sorry if I'm misunderstanding something.

@dcacenabes
Copy link
Author

If you're building the xcframeowrk with Xcode 12.5, which is using Swift 5.4 tools, is your xcframework building in an app using Xcode 12.5?
Are you able to build the xcframework with 13.0 beta so that it's built with Swift 5.5?

Sorry if I'm misunderstanding something.

That is exactly what happens, I build XCFramework with Xcode 12.5 with Swift 5.4.
I can use the framework in an app building with Xcode 12.5 and Swift 5.4

If I try to build the same App using Xcode 13 beta (Swift 5.5) I get the error mentioned above:

Failed to build module 'RealmSwift'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.19.104 clang-1300.0.18.4)'). Please select a toolchain which matches the SDK.

I am setting REALM_BUILD_LIBRARY_FOR_DISTRIBUTION to YES, so the XCFramework should be compatible with other versions of the swift compiler.

As stated in this comment, Realm supports library evolution:
#7258 (comment)

@ravikirankhareedi
Copy link

I am facing the same issue. Did you find any solution for this problem?

@dcacenabes
Copy link
Author

I am facing the same issue. Did you find any solution for this problem?

Unfortunately not

@leemaguire
Copy link
Contributor

@dcacenabes Does this issue happen for you with the latest Xcode beta?

@dcacenabes
Copy link
Author

@dcacenabes Does this issue happen for you with the latest Xcode beta?

Do you mean building the Realm SDK with BUILD_LIBRARY_FOR_DISTRIBUTION enabled or build the app that uses the library built in an older Xcode version ?

@dianaafanador3
Copy link
Contributor

@dcacenabes I think what @leemaguire is trying to ask is if you have tried to built the XCFramework with the REALM_BUILD_LIBRARY_FOR_DISTRIBUTION flag with the latest Xcode release (Xcode 13 as today).

@dcacenabes
Copy link
Author

@dcacenabes I think what @leemaguire is trying to ask is if you have tried to built the XCFramework with the REALM_BUILD_LIBRARY_FOR_DISTRIBUTION flag with the latest Xcode release (Xcode 13 as today).

Hi @dianaafanador3 , if I build with the latest Xcode 13 as of today, then I can not try if the XCFramework generated is ABI stable because I can not build with a newer version of the Swift compiler, since I'd be using the latest one to generate the framework.
If you use the same compiler for the framework and the app you are never going to get this error. In order to test this properly, you must build the framework for distribution with one version of Xcode and then build the sample app with a newer version.

@ravikirankhareedi
Copy link

@dianaafanador3 @leemaguire I confirm the issue with latest Xcode. My xcode version is 13.0 (Swift 5.5) where I build Realm XCframework with distribution flag enabled. (Realm version: 10.17.0). Everything is good.
But when I use the same xcframework to build and run my application on Xcode 12.5 (Swift 5.4), I get the error: Failed to build module 'RealmSwift' from its module interface; the compiler that produced it, 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)'

@kteman
Copy link

kteman commented Oct 25, 2021

@ravikirankhareedi Sorry to be the bearer of bad news, but according to Apple engineers distribution flag / library evolution support does not support backwards compatibility as you are describing. Read it from Apple engineer directly. The only thing it (supposedly) supports is forward compatibility (very misleading from Apple presentations). Forward meaning... if you build with the flag enabled in 12.5, then you should be able to consume it on 13.0 (not the other way around). However for me... I get the same error above even when setting up simple sample frameworks and tests. What I've discovered: library evolution / distribution flag works fine (with a lot of tweaking you can get it) if there are no embedded libraries. The moment your framework has an embedded static library of any kind, swift or Obj-C mixed, evolution support does not appear to be possible any longer. I could not get this working in my main project or any sub projects. Looks to be broken as of now. Filed formal bugs with Apple and using developer credit. Looks to me (and I've been working on iPhones for 13 years) like they biffed this one badly. If you have a project which has no dependencies (anyone? anyone? no?) you're fine, but if you have embedded libraries one of two results seems to occur in testing: the error above in this thread, or stuck build process around the swift module compiling operations during xcodebuild. It will never continue, and will not give any hints why because the parsing of .swiftinterface is occurring behind the scenes and not visible in logs even when using xcodebuild. The end, so sad.

@kteman
Copy link

kteman commented Oct 26, 2021

I've demonstrated that build for distribution does not work when used with a framework which contains a static library of any type (Swift, or Objective-C mixed), also built with distribution. Simply remove the static library and rebuild the framework to see that library evolution now works (by testing through different Xcode versions). If the static library is present in the distributed framework, it either reports the typical error, swift versions are unaligned, or freezes indefinitely early in the build process. Already filed with Apple. Did you find the same thing? Keep in mind forward compatibility (built by lower xcode, consumed by higher xcode) is the thing that matters. https://github.com/kteman/Testing/tree/main/Test%20Library%20Evolution

@leemaguire
Copy link
Contributor

leemaguire commented Apr 20, 2022

I think I've found the root cause of the issue. In my investigation I found myself getting these errors (in the below image) along with 'Failed to build module 'RealmSwift'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.4.2'
Screenshot 2022-04-20 at 09 50 53

I then removed all occurrences of Realm. before the obj-c types present in the swiftinterface file. After a clean and build it succeeded and ran on Xcode 13.3.1 with an XCFramework built on Xcode 12.5.1.

The next step is to figure out a way to avoid the name collision when building with older versions of Xcode. Ideally we could use -Xfrontend -module-interface-preserve-types-as-written but that will strip out all module names before types and we don't want that.

Update: this gist should help https://gist.github.com/leemaguire/02873487e24541e4ea7aa53c5702bd0a

@amirthytejeshwar-sc
Copy link

amirthytejeshwar-sc commented Jun 14, 2022

Hey @leemaguire
Thank you so much for all your contributions.
I'm just trying to use the library evolution on my local setup.
So I'm downloading the xcframework from the assets here v10.28.0, but getting the same error
Module compiled with Swift x.x.x cannot be imported by Swift x.x.x
Am I missing something. Can you point me in right way if possible?

Update: I even tried generating xcframework locally with library evolution flag enabled but no luck.
Any input on the same is highly appreciated :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants