realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.72k stars 564 forks source link

Use shared frameworks with LTO in the React Native iOS prebuild #3652

Open fealebenpae opened 3 years ago

fealebenpae commented 3 years ago

In #3649 we moved to prebuilding the RN iOS source code and shipping it as a set of static libraries packaged in an xcframework. That has a downside in that the static libraries are too big. We should instead build a shared framework, which is smaller, and allows us to use link-time optimization to boot.

It's definitely possible to build a shared framework for iOS from CMake, that's what we do over in the .NET SDK. The main difference is that we don't have to ship headers in the framework in .NET, but here our framework needs to ship a couple of header files, and I wasn't able to figure out the CMake incantation to get it to copy these headers in the final framework bundle.

Once CMake builds frameworks (with the proper headers) for device and simulator xcodebuild -create-xcframework can stitch them together just like it does the static libraries.

kraenhansen commented 1 month ago

I wonder where this stands with https://github.com/realm/realm-js/pull/6650 merged. When we're combining library files using libtool https://github.com/realm/realm-js/blob/13e70d7bd694b7c310f6278b8d04100f8fe333a3/packages/realm/src/scripts/build/xcode.ts#L114 we use -static instead of -dynamic and I wonder if that would address this issue?