Realm-cocoa: Cannot compile using RealmSwift via Swift Package Manager in Xcode 12

Created on 10 Nov 2020  路  12Comments  路  Source: realm/realm-cocoa

Goals

Integrate RealmSwift using Swift Package Manager

Expected Results

Project will compile

Actual Results

Compilation errors

Steps for others to Reproduce

Add Realm via swift package manager to a project (possibly that previously had Realm added via cocoapods)

Code Sample

Compile warnings

found duplicate sources declaration in the package manifest: /Users/felip/Library/Developer/Xcode/DerivedData/CashBack-eywfvhinxnkbqvaftrufrscenkit/SourcePackages/checkouts/realm-cocoa/Realm/ObjectStore/src/util/scheduler.cpp

ignoring broken symlink /Users/felip/Library/Developer/Xcode/DerivedData/CashBack-eywfvhinxnkbqvaftrufrscenkit/SourcePackages/checkouts/realm-cocoa/include/Realm/RLMUsernamePasswordProviderClient.h

ignoring broken symlink /Users/felip/Library/Developer/Xcode/DerivedData/CashBack-eywfvhinxnkbqvaftrufrscenkit/SourcePackages/checkouts/realm-cocoa/include/Realm/RLMAppCredentials.h

ignoring broken symlink /Users/felip/Library/Developer/Xcode/DerivedData/CashBack-eywfvhinxnkbqvaftrufrscenkit/SourcePackages/checkouts/realm-cocoa/include/Realm/RLMSyncUser.h

ignoring broken symlink /Users/felip/Library/Developer/Xcode/DerivedData/CashBack-eywfvhinxnkbqvaftrufrscenkit/SourcePackages/checkouts/realm-cocoa/include/Realm/RLMUserAPIKeyProviderClient.h

Version of Realm and Tooling

Realm framework version: 10.1.2

Xcode version: Version 12.1 (12A7403)

iOS/OSX version: 14

Dependency manager + version: swift package manager

O-Community

Most helpful comment

@FaultyJuggler , we're currently working on a full SPM release that supports Sync. We'll update this ticket when that occurs.

All 12 comments

Hi @FaultyJuggler ,
Could you please give me more details? Is the problem happened because of the Compile warnings above or is it something else? Another kind of error?

@pavel-ship-it I've been having blocking issues with using Cocoapods and have also found cocoapods very fragile once you start using more than a single library. I removed all cocoapods from the project, imported everything via Swift Package Manager, and when I went to compile and have following errors (I assume related to the warnings above):

SceneDelegate.swift:12:11: Cannot find 'App' in scope
LoginViewController.swift:113:32: Cannot find 'Credentials' in scope
GroupsTableViewController.swift:31:52: Value of type 'SyncConfiguration' has no member 'partitionValue'
PricesViewController.swift:39:52: Value of type 'SyncConfiguration' has no member 'partitionValue'
RetailersViewController.swift:28:48: Value of type 'SyncConfiguration' has no member 'partitionValue'

Also for more context, my app code was written against RealmSwift 10beta4, so possible these variable names have changed when 10.1.0 came out?

@FaultyJuggler I think the sync parts of Realm just don't work with SPM, I've had the same issue for a while (wanting to switch away from Cocoapods). I assumed now with the official release that SPM was supported but seems it's not the case.

Yes, it is not supported in SPM configuration yet.
@FaultyJuggler taking in account the issue with cocoapod binaries you've mentioned in previous ticket I'd recommend to try Carthage.

I am also trying to build a dynamic library of v4.4.1 for Xcode 12 with Carthage but when I run carthage update nothing gets built. Is there a problem with using Carthage and Xcode 12.2 ?

I am not familiar with either Carthage or Cocoapods so please let me know if there is some additional configuration required to get Carthage to work.

Is it somehow possible to build just the dynamic libraries (Realm.framework and RealmSwift.framework) in the exact same manner as the binaries distributed here on GitHub ? If so what is the procedures to do so ? Ideally I don't want them linked to any application project at all.

MY BAD - "sh build.sh build" - sorry clean forgot that you can just build it from the command line - but that also fails to complete. Is there a way to fix this so it will not try and build an arm64 version of the library.

The following build commands failed:
Ld /Users/duncangroenewald/Development/realm-cocoa/build/DerivedData/Realm/Build/Intermediates.noindex/Realm.build/Release/Realm.build/Objects-normal/arm64/Binary/Realm normal arm64

I solved this by opening the Xcode project and setting the build to "active architecture only" on the targets.

@FaultyJuggler , we're currently working on a full SPM release that supports Sync. We'll update this ticket when that occurs.

@jsflax - I see there is a v10.1.3 build that includes arm64, can you confirm this includes the sync component and can you also confirm that there is a v5.5.x build coming that will include arm64 and Sync.

Thanks

@duncangroenewald our latest version of Realm v10.5.0 has full arm64 & Sync support via SPM. We have no plans on retrofitting support to the v5.5.x versions, and recommend to always use the latest version of Realm.

Closing this as the original issue has been solved with full SPM support.

@leemaguire Is this Xcode 12.3 only? I just tried compiling in 12.2 and hit a few issues.

@duncangroenewald our latest version of Realm v10.5.0 has full arm64 & Sync support via SPM. We have no plans on retrofitting support to the v5.5.x versions, and recommend to always use the latest version of Realm.

But in practice v10.5.0 does not support Realm Cloud and MongoDB Realm is not ready for production use yet!!

@leemaguire This still doesn't build with Xcode 12.3 and SPM

<unknown>:0: error: module map file '/RealmSwift/RealmSwift.modulemap' not found
<unknown>:0: error: module map file '/RealmSwift/RealmSwift.modulemap' not found
<unknown>:0: error: missing required module 'SwiftShims'

Edit: my bad there was something from cocoa pods still in my build settings, compiles now.

Was this page helpful?
0 / 5 - 0 ratings