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

Build script does not create module for the arm64 simulator #6968

Closed
FelixLisczyk opened this issue Dec 2, 2020 · 6 comments
Closed

Build script does not create module for the arm64 simulator #6968

FelixLisczyk opened this issue Dec 2, 2020 · 6 comments

Comments

@FelixLisczyk
Copy link

FelixLisczyk commented Dec 2, 2020

Goals

I want to build Realm as a precompiled framework, embed it into an iOS app and run it in the simulator.

Important: I'm using a M1 MacBook Air and therefore need to compile code for the arm64 simulator.

Expected Results

Xcode compiles the app with Realm as an embedded binary.

Actual Results

Xcode compilation fails with the following error message:

Module 'RealmSwift' was created for incompatible target arm64-apple-ios9.0: /Users/<user>/Developer/realm-cocoa/build/ios/swift-12.2/RealmSwift.framework/Modules/RealmSwift.swiftmodule/arm64.swiftmodule

Steps for others to Reproduce

You need an Apple Silicon Mac to reproduce this issue.

  1. Compile Realm for iOS: ./build.sh ios-swift
  2. Create a new iOS project
  3. Add Realm and RealmSwift as an embedded binary and to the framework search paths
  4. Add import RealmSwift to your ViewController.swift
  5. Select an iOS simulator as the run target and build the app

Version of Realm and Tooling

Realm framework version: 10.1.4

Xcode version: 12.2

iOS/OSX version: 14.2

Notes

  • Realm integration works fine with CocoaPods. I would prefer to integrate Realm as a precompiled framework to accelerate local build and CI compilation time.
  • The RealmSwift.framework from CocoaPods contains swiftdoc andswiftmodule files for arm64 and arm64-apple-ios-simulator. The precompiled framework contains module files for arm, arm64 and arm64-apple-ios but is missing the arm64 simulator.
  • I've noticed that the Realm project has configured arm64 as an excluded architecture for the iOS simulator. I've tried to remove this setting, but that causes the Realm build script to fail with the following error message:

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/DerivedData/Realm/Build/Products/Release-iphonesimulator/Realm.framework/Realm and build/DerivedData/Realm/Build/Products/Release-iphoneos/Realm.framework/Realm have the same architectures (arm64) and can't be in the same fat output file

Related Issues

@tgoyne
Copy link
Member

tgoyne commented Dec 2, 2020

A fat framework cannot contain both arm64-for-simulator and arm64-for-device slices because the file format only distinguishes on architecture and not the platform, so they're both just "arm64". Instead you have to use a xcframework, which can be built with sh build.sh xcframework ios. Currently the xcframework build is a bit weird and different, but #6964 will resolve that and hopefully will be released today.

@FelixLisczyk
Copy link
Author

Thanks for your quick response. I've compiled the new Realm version 10.2.0 with ./build.sh xcframework ios and also tried the precompiled binaries from GitHub. In both cases I get the following error message when building my project for the arm64 simulator:

Could not find module 'RealmSwift' for target 'arm64-apple-ios-simulator'; found: i386, x86_64-apple-ios-simulator, x86_64, i386-apple-ios-simulator

Is there anything else I need to configure or is the arm64 simulator slice still missing in the new release?

@FelixLisczyk
Copy link
Author

FelixLisczyk commented Dec 7, 2020

If there is anything you want me to try, please let me know. I'm happy to help.

@FelixLisczyk
Copy link
Author

I think I've found the cause of this issue. The latest Realm version still defines arm64 as an excluded architecture for the iOS simulator:

https://github.com/realm/realm-cocoa/blob/af4b201bb955736f250f5af1c1b6bc335a43c385/Configuration/Base.xcconfig#L65

I've removed this value and rebuilt with ./build.sh xcframework ios. The arm64-apple-ios-simulator slice is now present and my example project builds successfully! 👍

@FelixLisczyk
Copy link
Author

I've found another minor issue with the build script: It does not accept more than three input parameters:

https://github.com/realm/realm-cocoa/blob/7a812029d05890f35501dcbcb00f346ac196a7d9/build.sh#L282-L285

This prevents calls like ./build.sh xcframework ios watchos tvos catalyst

@FelixLisczyk
Copy link
Author

FelixLisczyk commented Dec 11, 2020

The latest Realm version 10.4.0 has fixed the arm64-apple-ios-simulator compiler issue. Thank you!

@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

No branches or pull requests

2 participants