realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
878 stars 52 forks source link

[RKOTLIN-877] Avoid exporting Core's symbols to allow mixing multiple SDKs #1780

Open nhachicha opened 2 weeks ago

nhachicha commented 2 weeks ago

The cinterop KLIB includes compiled core's static libraries that will be used by the linker to build the final app. This PR will avoid exporting Core's symbols so if the user adds another SDK like Swift to their app then build/link statically the Swift app the two versions of Core will not conflicts

Most of the work was testing with MultiplatformDemo and MultiplatformDemoWithSync while adding a POD dependency to Swift SDK and using two Realms using two version of Core inside the same iOS app.

when building such app the dynamic framweork build from Kotlin/Native should not include any Core symbols like the following:

xcrun dyldinfo  ../shared/build/bin/ios/podDebugFramework/shared.framework/shared -weak_bind  | c++filt
weak binding information:
segment section          address       type     addend symbol
__DATA  __la_symbol_ptr  0x00A3C168    pointer       0 _Konan_DebugBuffer
__DATA  __la_symbol_ptr  0x00A3C170    pointer       0 _Konan_DebugBufferSize
__DATA  __la_symbol_ptr  0x00A3C178    pointer       0 _Konan_DebugObjectToUtf8Array
__DATA_CONST __got            0x0090C1C0    pointer       0 typeinfo for std::length_error
__DATA_CONST __got            0x0090C1C8    pointer       0 typeinfo for std::out_of_range
__DATA_CONST __got            0x0090C1D8    pointer       0 typeinfo for std::overflow_error
__DATA_CONST __const          0x009FB878    pointer       0 typeinfo for std::overflow_error
__DATA_CONST __got            0x0090C1E0    pointer       0 typeinfo for std::invalid_argument
__DATA_CONST __const          0x00A0FCC0    pointer       0 typeinfo for std::invalid_argument
__DATA  __la_symbol_ptr  0x00A3C700    pointer       0 operator delete[](void*)
__DATA  __la_symbol_ptr  0x00A3C708    pointer       0 operator delete(void*)
__DATA  __la_symbol_ptr  0x00A3C710    pointer       0 operator new[](unsigned long)
__DATA  __la_symbol_ptr  0x00A3C718    pointer       0 operator new(unsigned long)
__DATA  __la_symbol_ptr  0x00A3C720    pointer       0 operator new(unsigned long, std::nothrow_t const&)
rorbech commented 1 week ago

You mention that it was tested by adding the Swift SDK to a sample project. Could we add this project to our examples to track any regression?

Yeah, sound like something that would be cool to put in the test suite similarly to https://github.com/realm/realm-kotlin/tree/main/examples/realm-java-compatibility