From 69f903ee5574b63bd0a5f39c8d14a2bd8303a0f5 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2024 11:20:32 -0700 Subject: [PATCH 1/5] Adjust how the SDKROOT it set to not need updates each version --- CHANGELOG.md | 1 + evergreen/config.yml | 7 ++----- tools/cmake/xcode.toolchain.cmake | 16 ++++------------ 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97caa04c161..5b706fa55ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?) * Valgrind could report a branch on an uninitialized read when opening something that is not an encrypted Realm file as an encrypted Realm file ([PR #7789](https://github.com/realm/realm-core/pull/7789), since v14.10.0). * Opening an FLX realm asynchronously may not wait to download all data ([#7720](https://github.com/realm/realm-core/issues/7720), since FLX sync was introduced). +* Fix compilation with Xcode 16 ([PR #7802](https://github.com/realm/realm-core/pull/7802)) ### Breaking changes * None. diff --git a/evergreen/config.yml b/evergreen/config.yml index 672a1df5f04..6c3974c40fc 100644 --- a/evergreen/config.yml +++ b/evergreen/config.yml @@ -1674,7 +1674,6 @@ buildvariants: expansions: cmake_bindir: "/opt/homebrew/bin" cmake_toolchain_file: "./tools/cmake/xcode.toolchain.cmake" - extra_flags: "-DCMAKE_XCODE_ATTRIBUTE_SDKROOT=iphoneos" cmake_build_tool_options: "-sdk iphonesimulator -arch arm64" cmake_generator: Xcode max_jobs: $(sysctl -n hw.logicalcpu) @@ -1707,12 +1706,11 @@ buildvariants: expansions: cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-macos-universal.tar.gz" cmake_bindir: "./cmake_binaries/CMake.app/Contents/bin" - cmake_toolchain_file: "./tools/cmake/xcode.toolchain.cmake" cmake_generator: Xcode max_jobs: $(sysctl -n hw.logicalcpu) cmake_build_type: Release xcode_developer_dir: /Applications/Xcode13.1.app/Contents/Developer - extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=x86_64 + extra_flags: -DREALM_ENABLE_ASSERTIONS=ON tasks: - name: benchmarks - name: compile_test @@ -1724,12 +1722,11 @@ buildvariants: expansions: cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-macos-universal.tar.gz" cmake_bindir: "./cmake_binaries/CMake.app/Contents/bin" - cmake_toolchain_file: "./tools/cmake/xcode.toolchain.cmake" cmake_generator: Xcode max_jobs: $(sysctl -n hw.logicalcpu) cmake_build_type: Release xcode_developer_dir: /Applications/Xcode13.1.app/Contents/Developer - extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=arm64 + extra_flags: -DREALM_ENABLE_ASSERTIONS=ON tasks: - name: benchmarks diff --git a/tools/cmake/xcode.toolchain.cmake b/tools/cmake/xcode.toolchain.cmake index e903547d6a2..45922c8eb3f 100644 --- a/tools/cmake/xcode.toolchain.cmake +++ b/tools/cmake/xcode.toolchain.cmake @@ -15,19 +15,11 @@ set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator;-appletvos;-appl set(CMAKE_XCODE_ATTRIBUTE_SUPPORTS_MACCATALYST "YES") set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2,3,4,7") -# With Xcode 14+ the base SDK *mostly* doesn't matter any more, as it -# officially supports multi-platform builds from a single target. -# However, as of Xcode 15 beta 8 xcodebuild (but not Xcode itself) requires the -# visionOS SDK to build for visionOS. 15.0 final doesn't include the visionOS -# SDK, so the SDKROOT is explicitly set by the invoker when building with the -# beta Xcode rather than here. -# Xcode 13 requires using the correct SDK. We no longer support Xcode 13, but -# still use it on evergreen to build the macOS tests (and nothing else). +# As of Xcode 14 the iphoneos SDK supports building for all platforms to +# support multi-platform builds. However, we still have some Xcode 13 builds (for +# benchmarks) that need to set the SDKROOT to macosx. if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_SDKROOT) - set(CMAKE_XCODE_ATTRIBUTE_SDKROOT_1500 "iphoneos") - set(CMAKE_XCODE_ATTRIBUTE_SDKROOT_1400 "iphoneos") - set(CMAKE_XCODE_ATTRIBUTE_SDKROOT_1300 "macosx") - set(CMAKE_XCODE_ATTRIBUTE_SDKROOT "$(SDKROOT_$(XCODE_VERSION_MAJOR))") + set(CMAKE_XCODE_ATTRIBUTE_SDKROOT "iphoneos") endif() set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "12.0") From c2aa88690162f2bf5e7bf11f31e757dbf5978aa2 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2024 11:27:19 -0700 Subject: [PATCH 2/5] Switch to building the swift package and cocoa binaries as c++20 --- CHANGELOG.md | 2 +- CMakeLists.txt | 4 +++- Package.swift | 2 +- tools/cmake/xcode.toolchain.cmake | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b706fa55ce..349c52e3a75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ ----------- ### Internals -* None. +* Switch to building the Swift package and Cocoa binaries as C++20 ([PR #7802](https://github.com/realm/realm-core/pull/7802)). ---------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d5710f1077..e2401e4d5ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,9 @@ endif() set(PROJECT_VERSION ${DEP_VERSION}) # Project-wide build flags -set(CMAKE_CXX_STANDARD 17) +if (NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/Package.swift b/Package.swift index 5d8c2cd3311..9ba84104d10 100644 --- a/Package.swift +++ b/Package.swift @@ -565,5 +565,5 @@ let package = Package( .headerSearchPath("../"), ] + cxxSettings) as [CXXSetting]), ], - cxxLanguageStandard: .cxx17 + cxxLanguageStandard: .cxx20 ) diff --git a/tools/cmake/xcode.toolchain.cmake b/tools/cmake/xcode.toolchain.cmake index 45922c8eb3f..b0210786b68 100644 --- a/tools/cmake/xcode.toolchain.cmake +++ b/tools/cmake/xcode.toolchain.cmake @@ -31,3 +31,4 @@ set(CMAKE_XCODE_ATTRIBUTE_TVOS_DEPLOYMENT_TARGET "12.0") set(REALM_ENABLE_ASSERTIONS ON CACHE BOOL "Enable release assertions") set(REALM_XCODE_TOOLCHAIN TRUE) +set(CMAKE_CXX_STANDARD 20) From 24b096408f4f397d9afe1d9c946310d549803f3d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2024 11:35:01 -0700 Subject: [PATCH 3/5] Exclude the bson lib from REALM_BUILD_LIB_ONLY builds --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 754624671fe..5106b3c2fd0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(realm) add_subdirectory(external/IntelRDFPMathLib20U2) -add_subdirectory(external/bson EXCLUDE_FROM_ALL) +if (NOT REALM_BUILD_LIB_ONLY) + add_subdirectory(external/bson EXCLUDE_FROM_ALL) +endif() if (REALM_ENABLE_GEOSPATIAL) add_subdirectory(external/s2) From ea0b97c89fd2cc28dc2ae6960f91a10d16cfb19f Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2024 12:25:42 -0700 Subject: [PATCH 4/5] Work around u8path being deprecated in c++20 --- test/benchmark-larger/main.cpp | 2 +- test/test_util_file.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/benchmark-larger/main.cpp b/test/benchmark-larger/main.cpp index 481d5d08e88..98c461ca9db 100644 --- a/test/benchmark-larger/main.cpp +++ b/test/benchmark-larger/main.cpp @@ -163,7 +163,7 @@ int main() << std::endl; start = end; for (size_t i = 0; i < probe_size; ++i) { - sum += objects[i].get(col2); + sum = sum + objects[i].get(col2); } end = std::chrono::steady_clock::now(); diff = end - start; diff --git a/test/test_util_file.cpp b/test/test_util_file.cpp index 91c525a879a..57911e6da4a 100644 --- a/test/test_util_file.cpp +++ b/test/test_util_file.cpp @@ -117,9 +117,15 @@ TEST(Utils_File_dir) TEST(Utils_File_dir_unicode) { +#if __cplusplus < 202002L using std::filesystem::u8path; +#else + auto u8path = [](const std::string& str) { + return std::filesystem::path(reinterpret_cast(str.c_str())); + }; +#endif - constexpr char all_the_unicode[] = u8"фоо-бар Λορεμ ლორემ 植物 החלל جمعت søren"; + const char* all_the_unicode = (const char*)u8"фоо-бар Λορεμ ლორემ 植物 החלל جمعت søren"; std::string dir_name = File::resolve(all_the_unicode, test_util::get_test_path_prefix()); // Create directory From 9f3e7d3acca1084d8d7d2cf836035ae5e840cd5a Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2024 12:42:17 -0700 Subject: [PATCH 5/5] Fix compilation with Xcode 15.2 --- src/realm/util/time.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/realm/util/time.hpp b/src/realm/util/time.hpp index 1de835a462f..bfabd108abd 100644 --- a/src/realm/util/time.hpp +++ b/src/realm/util/time.hpp @@ -69,7 +69,7 @@ inline std::string format_utc_time(std::time_t time, const char* format) } // namespace realm::util -#if __cplusplus < 202002L +#if __cplusplus < 202002L || (defined(__apple_build_version__) && __apple_build_version__ < 15000309) // This is a C++17 version of https://en.cppreference.com/w/cpp/chrono/duration/operator_ltlt to make // logging and comparing durations easier - especially in tests. //