realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.34k stars 2.15k forks source link

Linker errors in Xcode 13.2.1. Can't compile my app using Realm as an xcframework dependency in SPM since v10.21.0 #7615

Closed miguelkennedy closed 2 years ago

miguelkennedy commented 2 years ago

How frequently does the bug occur?

All the time

Description

Good day everyone.

I'm using realm as a precompiled xcframework dependency in several spm targets.

Realm is added to my Package.swift file as follows:

.binaryTarget(
    name: "Realm",
    path: "Frameworks/Realm/10.21.1/Realm.xcframework"
),
.binaryTarget(
    name: "RealmSwift",
    path: "Frameworks/RealmSwift/10.21.1/RealmSwift.xcframework"
)

and as a dependency to my targets as follows:

.target(
    name: "DatabaseClient",
    dependencies: [
    "Realm",
    "RealmSwift",
    ] ,
    path: "Sources/Clients/DatabaseClient"
)

Everything works fine up until v10.21.0. Since upgrading I'm getting compilation errors (undefined symbols). I'll attach the compilation log down below.

Important to notice that this only happens with the xcframework version of Realm. If I add v10.21.0 or higher as a standard package dependency as follows I get no compilation errors.

.package(
    name: "Realm",
    url: "https://github.com/realm/realm-swift.git",
    from: "10.21.0"
)

and then added to targets as follows:

dependencies: [
    .product(name: "Realm", package: "Realm"),
    .product(name: "RealmSwift", package: "Realm")
]

The issue is exclusive to the xcframework and it's present both in v10.21.0 and v10.21.1. I successfully compiled the xcframework myself using the build.sh script available in the repo but Xcode still fails to compile with it. Compilation fails in both the simulator and a physical device.

When I downgrade the xcframwork to 10.20.2 everything starts compiling again.

Stacktrace & log output

Undefined symbols for architecture x86_64:
  "static (extension in RealmSwift):RealmSwift.RealmCollectionImpl.== infix(A, A) -> Swift.Bool", referenced from:
      static GlucoseManager.GlucoseManagerState.__derived_struct_equals(GlucoseManager.GlucoseManagerState, GlucoseManager.GlucoseManagerState) -> Swift.Bool in GlucoseManager.o
  "protocol conformance descriptor for RealmSwift.Results<A> : RealmSwift.RealmCollectionImpl in RealmSwift", referenced from:
      lazy protocol witness table accessor for type RealmSwift.Results<SharedModels.BGReading> and conformance RealmSwift.Results<A> : RealmSwift.RealmCollectionImpl in RealmSwift in GlucoseManager.o
      lazy protocol witness table accessor for type RealmSwift.Results<SharedModels.Treatment> and conformance RealmSwift.Results<A> : RealmSwift.RealmCollectionImpl in RealmSwift in GlucoseManager.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

10.21.0 and upwards

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 14

Build environment

Xcode version: 13.2.1 Dependency manager and version: SPM (swift-tools-version:5.5)

dianaafanador3 commented 2 years ago

Hi @miguelkennedy would you mind sharing the code on GlucoseManager and your objects schema so we can reproduce this issue.

miguelkennedy commented 2 years ago

Hi, @dianaafanador3

I can't because it's a commercial project...

I will try and create a sample project that has the same issue and will post it here for you.

Will post it as soon as I can.

miguelkennedy commented 2 years ago

@dianaafanador3 here's a sample project that you can use to reproduce the compilation bug https://github.com/cala4/realm-bug/tree/main

Let me know if you need anything else from me.

miguelkennedy commented 2 years ago

Just to make sure, anyone working on this issue? I would love to try the flexible sync beta feature but unfortunately I can't upgrade to v10.22.0 due to the compilation issue mentioned above 😞

dianaafanador3 commented 2 years ago

Hi @miguelkennedy it looks like it is not finding the definition of == on RealmCollectionImpl, and it is triggered by conforming GlucoseManagerState to Equatable. This is something required on your side?, If not removing the conformance will remove the build error. We'll keep investigating why this is happening on our side and why this is only happening when using an xcframework.

miguelkennedy commented 2 years ago

Hi @dianaafanador3

Sorry for the late reply, was away on vacation.

Unfortunately I must conform GlucoseManagerState to Equatable because it's a requirement by The Composable Architecture that powers the app. So, removing the Equatable conformance is not an option for me 😞

I hope you guys can find the culprit and fix it.

Thank for the update πŸ‘πŸΌ