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

type alias redefinition for Realm_Config #113

Open
adamski opened this issue Nov 10, 2023 · 13 comments · May be fixed by #232
Open

type alias redefinition for Realm_Config #113

adamski opened this issue Nov 10, 2023 · 13 comments · May be fixed by #232

Comments

@adamski
Copy link

adamski commented Nov 10, 2023

SDK: 0.4.0-preview
macOS 13.4

I'm getting the following build error when integrating Realm into an existing C++ CMake project:

cmake-build-debug/_deps/cpprealm-build/src/cpprealm/internal/bridge/bridge_types.hpp:46:8: error: type alias redefinition with different types ('std::aligned_storage<312, 8>::type' vs 'std::aligned_storage<368, 16>::type')
;using Realm_Config = std::aligned_storage<312, 8>::type;
       ^
cmake-build-debug/_deps/cpprealm-build/src/cpprealm/internal/bridge/bridge_types.hpp:9:8: note: previous definition is here
;using Realm_Config = std::aligned_storage<368, 16>::type;
@adamski
Copy link
Author

adamski commented Nov 11, 2023

The error went away for a while, and now it's back. Not sure what is causing it. Any clues?

@adamski
Copy link
Author

adamski commented Nov 11, 2023

It seems to be caused by this block of CMake settings, that set the build to be universal x86_64 and arm64:

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version" FORCE)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Architectures" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64] "11.0" CACHE STRING "arm 64 minimum deployment target" FORCE)

@leemaguire
Copy link
Contributor

@adamski I see your issue, it's trying to compile a universal binary, and that is something our bridging code that talks to RealmCore is not handling correctly. You should be able to build successfully by setting your target architecture on your machine for now while we look into this. E.g set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Architectures" FORCE) in the case you are working from an Arm based Mac.

@adamski
Copy link
Author

adamski commented Nov 11, 2023

Yes it works correctly after removing the universal binary settings.
@leemaguire can you please confirm the minimum target SDK required too? I was getting some errors after setting the min to 11.0 on macOS on arm.

@leemaguire
Copy link
Contributor

@adamski the minimum macOS version we support is 12.

@adamski
Copy link
Author

adamski commented Dec 1, 2023

Just FYI (and forgive me if I'm stating the obvious) this issue also blocks iOS simulator builds, with the same error as above:

Type alias redefinition with different types ('std::aligned_storage<312, 8>::type' vs 'std::aligned_storage<368, 16>::type')

Device-only builds are not affected.

@adamski
Copy link
Author

adamski commented Jul 12, 2024

@leemaguire thanks for adding the REALM_DISABLE_ALIGNED_STORAGE option, which looks like it should fix this issue.

Just to let you know I'm still getting the above error:

FAILED: _deps/cpprealm-build/src/CMakeFiles/cpprealm.dir/cpprealm/db.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DBUILD_NUMBER=99 -DREALM_APP_SERVICES=1 -DREALM_BUILD_LIB_ONLY -DREALM_DEBUG=1 -DREALM_DISABLE_ALIGNED_STORAGE=1 -DREALM_ENABLE_ENCRYPTION -DREALM_ENABLE_SYNC -DREALM_ENABLE_SYNC=1 -DREALM_INSTALL_LIBEXECDIR -DREALM_NO_CONFIG -DVERSION_LONG=\"1.0.0-dev-2024-07-12T20:07:57Z\" -DVERSION_NUMBER=\"1.0.0\" -DVERSION_SHORT=\"1.0.0-dev\" -I/Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/src -I/Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/include -I/Users/adamwilson/dev/node-audio/entonal-studio/cmake-build-debug/_deps/cpprealm-build/src -I/Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/realm-core/src -I/Users/adamwilson/dev/node-audio/entonal-studio/cmake-build-debug/_deps/cpprealm-build/realm-core/src -g -std=c++17 -arch x86_64 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=10.15 -fPIC -fcolor-diagnostics -Wall -Wextra -pedantic -Werror -MD -MT _deps/cpprealm-build/src/CMakeFiles/cpprealm.dir/cpprealm/db.cpp.o -MF _deps/cpprealm-build/src/CMakeFiles/cpprealm.dir/cpprealm/db.cpp.o.d -o _deps/cpprealm-build/src/CMakeFiles/cpprealm.dir/cpprealm/db.cpp.o -c /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/src/cpprealm/db.cpp
In file included from /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/src/cpprealm/db.cpp:1:
In file included from /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/include/cpprealm/db.hpp:22:
In file included from /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/include/cpprealm/accessors.hpp:22:
In file included from /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/include/cpprealm/internal/bridge/lnklst.hpp:24:
In file included from /Users/adamwilson/dev/node-audio/entonal-studio/Cache/cpprealm/fae215951a53a55e913bfa1ad06e2cf046568156/include/cpprealm/internal/bridge/utils.hpp:41:
/Users/adamwilson/dev/node-audio/entonal-studio/cmake-build-debug/_deps/cpprealm-build/src/cpprealm/internal/bridge/bridge_types.hpp:49:11: error: type alias redefinition with different types ('std::aligned_storage<312, 8>::type' vs 'std::aligned_storage<368, 16>::type')
    using Realm_Config = std::aligned_storage<312, 8>::type;
          ^
/Users/adamwilson/dev/node-audio/entonal-studio/cmake-build-debug/_deps/cpprealm-build/src/cpprealm/internal/bridge/bridge_types.hpp:9:11: note: previous definition is here
    using Realm_Config = std::aligned_storage<368, 16>::type;
          ^

@leemaguire
Copy link
Contributor

@adamski cleaning your build folder should resolve that as the fresh build won't generate a bridge_types.hpp header.

The fix here on my side is to group all of the type definitions by architecture inside of bridge_types.hpp.

@adamski
Copy link
Author

adamski commented Jul 12, 2024

Thanks @leemaguire - it seems that both with the flag set and without I'm still getting the error, also after cleaning the build folder. This is the contents of my bridge_types.hpp when building a universal binary for macOS, with duplicated definitions.

#pragma once

#include <type_traits>

#define CPPREALM_HAVE_GENERATED_BRIDGE_TYPES

namespace realm::internal::bridge::storage {
    using OwnedBinaryData = std::aligned_storage<16, 8>::type;
    using Realm_Config = std::aligned_storage<368, 16>::type;
    using ColKey = std::aligned_storage<8, 8>::type;
    using Decimal128 = std::aligned_storage<16, 8>::type;
    using Dictionary = std::aligned_storage<80, 8>::type;
    using CoreDictionary = std::aligned_storage<248, 8>::type;
    using List = std::aligned_storage<80, 8>::type;
    using LnkLst = std::aligned_storage<232, 8>::type;
    using Mixed = std::aligned_storage<24, 8>::type;
    using ObjKey = std::aligned_storage<8, 8>::type;
    using ObjLink = std::aligned_storage<16, 8>::type;
    using Obj = std::aligned_storage<64, 8>::type;
    using ObjectId = std::aligned_storage<12, 1>::type;
    using ObjectSchema = std::aligned_storage<128, 8>::type;
    using Object = std::aligned_storage<104, 8>::type;
    using IndexSet = std::aligned_storage<24, 8>::type;
    using CollectionChangeSet = std::aligned_storage<192, 8>::type;
    using IndexSet_IndexIterator = std::aligned_storage<32, 8>::type;
    using IndexSet_IndexIteratableAdaptor = std::aligned_storage<8, 8>::type;
    using NotificationToken = std::aligned_storage<24, 8>::type;
    using Property = std::aligned_storage<120, 8>::type;
    using Query = std::aligned_storage<128, 8>::type;
    using Results = std::aligned_storage<704, 8>::type;
    using Schema = std::aligned_storage<24, 8>::type;
    using Set = std::aligned_storage<80, 8>::type;
    using SyncError = std::aligned_storage<120, 8>::type;
    using TableRef = std::aligned_storage<16, 8>::type;
    using TableView = std::aligned_storage<376, 8>::type;
    using ThreadSafeReference = std::aligned_storage<8, 8>::type;
    using Timestamp = std::aligned_storage<16, 8>::type;
    using UUID = std::aligned_storage<16, 1>::type;
    using Status = std::aligned_storage<8, 8>::type;
    using ErrorCategory = std::aligned_storage<4, 4>::type;
    using AppCredentials = std::aligned_storage<16, 8>::type;
    using AppError = std::aligned_storage<72, 8>::type;
    using SyncSubscriptionSet = std::aligned_storage<104, 8>::type;
    using MutableSyncSubscriptionSet = std::aligned_storage<184, 8>::type;
    using Bson = std::aligned_storage<40, 8>::type;
    using BsonIndexedMap = std::aligned_storage<64, 8>::type;
    using BsonDocument = std::aligned_storage<64, 8>::type;
    using OwnedBinaryData = std::aligned_storage<16, 8>::type;
    using Realm_Config = std::aligned_storage<312, 8>::type;
    using ColKey = std::aligned_storage<8, 8>::type;
    using Decimal128 = std::aligned_storage<16, 8>::type;
    using Dictionary = std::aligned_storage<80, 8>::type;
    using CoreDictionary = std::aligned_storage<248, 8>::type;
    using List = std::aligned_storage<80, 8>::type;
    using LnkLst = std::aligned_storage<232, 8>::type;
    using Mixed = std::aligned_storage<24, 8>::type;
    using ObjKey = std::aligned_storage<8, 8>::type;
    using ObjLink = std::aligned_storage<16, 8>::type;
    using Obj = std::aligned_storage<64, 8>::type;
    using ObjectId = std::aligned_storage<12, 1>::type;
    using ObjectSchema = std::aligned_storage<128, 8>::type;
    using Object = std::aligned_storage<104, 8>::type;
    using IndexSet = std::aligned_storage<24, 8>::type;
    using CollectionChangeSet = std::aligned_storage<192, 8>::type;
    using IndexSet_IndexIterator = std::aligned_storage<32, 8>::type;
    using IndexSet_IndexIteratableAdaptor = std::aligned_storage<8, 8>::type;
    using NotificationToken = std::aligned_storage<24, 8>::type;
    using Property = std::aligned_storage<120, 8>::type;
    using Query = std::aligned_storage<128, 8>::type;
    using Results = std::aligned_storage<704, 8>::type;
    using Schema = std::aligned_storage<24, 8>::type;
    using Set = std::aligned_storage<80, 8>::type;
    using SyncError = std::aligned_storage<120, 8>::type;
    using TableRef = std::aligned_storage<16, 8>::type;
    using TableView = std::aligned_storage<376, 8>::type;
    using ThreadSafeReference = std::aligned_storage<8, 8>::type;
    using Timestamp = std::aligned_storage<16, 8>::type;
    using UUID = std::aligned_storage<16, 1>::type;
    using Status = std::aligned_storage<8, 8>::type;
    using ErrorCategory = std::aligned_storage<4, 4>::type;
    using AppCredentials = std::aligned_storage<16, 8>::type;
    using AppError = std::aligned_storage<72, 8>::type;
    using SyncSubscriptionSet = std::aligned_storage<104, 8>::type;
    using MutableSyncSubscriptionSet = std::aligned_storage<184, 8>::type;
    using Bson = std::aligned_storage<40, 8>::type;
    using BsonIndexedMap = std::aligned_storage<64, 8>::type;
    using BsonDocument = std::aligned_storage<64, 8>::type;

}

@leemaguire
Copy link
Contributor

leemaguire commented Jul 12, 2024

I can archive successfully with -DREALM_DISABLE_ALIGNED_STORAGE=1, I have however managed to reproduce the duplicate alias issue when the flag is not present.

Did you delete your cmake-build-debug/_deps/cpprealm-build folder before rebuilding? It's likely the generated header is hanging around in there from the old builds before -DREALM_DISABLE_ALIGNED_STORAGE=1 was enabled.

@adamski
Copy link
Author

adamski commented Jul 12, 2024

Ok thanks @leemaguire it looks like I was setting the definition in the wrong place. Setting it in the cmake command line works, I'm now figuring out where to set it in the CMakeLists.txt so it sticks..

@leemaguire leemaguire linked a pull request Jul 19, 2024 that will close this issue
@adamski
Copy link
Author

adamski commented Jul 30, 2024

@leemaguire do you have any tips on how to add this to a CMakeLists.txt?

If I add add_definitions(-DREALM_DISABLE_ALIGNED_STORAGE=1) to the top level CMakeLists, I get the build error. I also get the error if I add it with target_compile_definitions:

target_compile_definitions(cpprealm PUBLIC REALM_DISABLE_ALIGNED_STORAGE=1)

If I add it to the cmake command, it works. Ideally I would keep it in the CMakeLists.txt only.

@leemaguire
Copy link
Contributor

leemaguire commented Jul 30, 2024

@adamski add set(REALM_DISABLE_ALIGNED_STORAGE 1 CACHE STRING "Disable aligned storage in Realm") at the top of your CMakeLists.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants