Skip to content

Commit 8259932

Browse files
knethjedelbo
andauthored
Building for Windows using C++20 (#7841)
* Building using C++20 on Windows * Building and testing on Linux with C++20 --------- Co-authored-by: Jørgen Edelbo <[email protected]>
1 parent dd4992e commit 8259932

File tree

8 files changed

+55
-25
lines changed

8 files changed

+55
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Fixed `Table::remove_object_recursive` which wouldn't recursively follow links through a single `Mixed` property. This feature is exposed publicly on `Table` but no SDK currently uses it, so this is considered internal. ([#7829](https://github.com/realm/realm-core/issues/7829), likely since the introduction of Mixed)
2525
* Upload completion is now tracked in a multiprocess-compatible manner ([PR #7796](https://github.com/realm/realm-core/pull/7796)).
2626
* The local realm will assume the the client file ident of the fresh realm during a client reset. ([PR #7850](https://github.com/realm/realm-core/pull/7850))
27+
* Building using C++20 on Windows.
2728

2829
----------------------------------------------
2930

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ if(MSVC)
129129
# We use these in our AtomicSharedPtr implementation and it can't move
130130
# to atomic<shared_ptr<T>> because NotificationToken relies on movability.
131131
add_compile_options(/D_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING)
132+
133+
# Enable __cplusplus macro
134+
add_compile_options(/Zc:__cplusplus)
132135
else()
133136
add_compile_options(-Wall -Wextra -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code -Wunused-parameter -Wno-missing-field-initializers)
134137
# TODO: Remove this when fixed

evergreen/config.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ functions:
430430
script: |-
431431
if ls crash-*> /dev/null 2>&1; then
432432
echo "Found crash file"
433-
#Rename the crash file and the realm file.
433+
#Rename the crash file and the realm file.
434434
#If there is a crash, this will signal that something needs to be uploaded.
435435
mv crash-* realm-fuzzer-crash.txt
436436
mv fuzz-realm.realm fuzzer_realm.realm
@@ -459,7 +459,7 @@ functions:
459459
bucket: mciuploads
460460
permissions: public-read
461461
content_type: application/x-binary
462-
display_name: Realm File
462+
display_name: Realm File
463463
optional: true
464464

465465
- command: shell.exec
@@ -515,7 +515,7 @@ functions:
515515
set -o verbose
516516
517517
TOP_DIR=$(pwd)
518-
518+
519519
HANG_ANALYZER_PATH=$TOP_DIR/evergreen/hang_analyzer
520520
REQUIREMENTS_PATH=$HANG_ANALYZER_PATH/requirements.txt
521521
@@ -1166,7 +1166,7 @@ tasks:
11661166
./build/test/${cmake_build_type|Debug}-iphonesimulator/realm-combined-tests.app \
11671167
'io.realm.CombinedTests' \
11681168
$TEST_RESULTS_FILE
1169-
1169+
11701170
- name: generate-sync-corpus
11711171
tags: [ "for_nightly_tests" ]
11721172
exec_timeout_secs: 1800
@@ -1393,6 +1393,19 @@ buildvariants:
13931393
- name: compile_test
13941394
- name: lint
13951395

1396+
- name: ubuntu-cpp20
1397+
display_name: "Ubuntu C++20"
1398+
run_on: ubuntu2404-arm64-large
1399+
expansions:
1400+
fetch_missing_dependencies: On
1401+
c_compiler: "/opt/clang+llvm/bin/clang"
1402+
cxx_compiler: "/opt/clang+llvm/bin/clang++"
1403+
clang_format: "/opt/clang+llvm/bin/clang-format"
1404+
extra_flags: -DCMAKE_CXX_STANDARD=20
1405+
tasks:
1406+
- name: compile_test
1407+
- name: lint
1408+
13961409
- name: ubuntu-no-session-multiplexing
13971410
display_name: "Ubuntu (Sync Multiplexing Disabled)"
13981411
run_on: ubuntu2204-arm64-large
@@ -1469,7 +1482,7 @@ buildvariants:
14691482
fetch_missing_dependencies: On
14701483
c_compiler: "/opt/clang+llvm/bin/clang"
14711484
cxx_compiler: "/opt/clang+llvm/bin/clang++"
1472-
run_with_encryption: 1
1485+
run_with_encryption: 1
14731486
enable_asan: On
14741487
cmake_build_type: RelWithDebInfo
14751488
tasks:
@@ -1492,7 +1505,7 @@ buildvariants:
14921505
cxx_compiler: "./clang_binaries/bin/clang++"
14931506
python3: /opt/mongodbtoolchain/v3/bin/python3
14941507
tasks:
1495-
- name: compile_test_and_package
1508+
- name: compile_test_and_package
14961509
- name: benchmarks
14971510
- name: generate-sync-corpus
14981511

@@ -1979,5 +1992,3 @@ buildvariants:
19791992
# no_tests: On
19801993
# tasks:
19811994
# - name: compile_only
1982-
1983-

src/external/bson/bson-decimal128.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ _mul_64x64 (uint64_t left, /* IN */
374374
* Returns:
375375
* The lowercased character.
376376
*/
377-
char
377+
static char
378378
_dec128_tolower (char c)
379379
{
380380
if (isupper (c)) {
@@ -395,7 +395,7 @@ _dec128_tolower (char c)
395395
* Returns:
396396
* true if the strings are equal, false otherwise.
397397
*/
398-
bool
398+
static bool
399399
_dec128_istreq (const char *a, /* IN */
400400
const char *b /* IN */)
401401
{

src/external/bson/bson-iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ _bson_iter_next_internal (bson_iter_t *iter, /* INOUT */
631631
subtype = *(iter->raw + iter->d2);
632632

633633
if (subtype == BSON_SUBTYPE_BINARY_DEPRECATED) {
634-
int32_t binary_len;
634+
uint32_t binary_len;
635635

636636
if (l < 4) {
637637
iter->err_off = o;

src/realm/util/file.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,22 @@ struct WindowsFileHandleHolder {
128128
#endif
129129

130130
#if REALM_HAVE_STD_FILESYSTEM
131+
#if __cplusplus < 202002L
131132
using std::filesystem::u8path;
133+
inline std::string path_to_string(const std::filesystem::path& path)
134+
{
135+
return path.u8string();
136+
}
137+
#else
138+
inline std::string path_to_string(const std::filesystem::path& path)
139+
{
140+
return reinterpret_cast<const char*>(path.u8string().c_str());
141+
}
142+
inline auto u8path(const std::string& str)
143+
{
144+
return std::filesystem::path(reinterpret_cast<const char8_t*>(str.c_str()));
145+
};
146+
#endif
132147

133148
void throwIfCreateDirectoryError(std::error_code error, const std::string& path)
134149
{
@@ -340,7 +355,7 @@ std::string make_temp_dir()
340355
}
341356
break;
342357
}
343-
return path.u8string();
358+
return path_to_string(path);
344359

345360
#else // POSIX.1-2008 version
346361

@@ -374,7 +389,7 @@ std::string make_temp_file(const char* prefix)
374389
throw SystemError(error, get_last_error_msg("GetTempFileName() failed: ", error));
375390
}
376391

377-
return std::filesystem::path(buffer).u8string();
392+
return path_to_string(std::filesystem::path(buffer));
378393

379394
#else // POSIX.1-2008 version
380395

@@ -1573,7 +1588,7 @@ std::string File::get_path() const
15731588
std::string File::resolve(const std::string& path, const std::string& base_dir)
15741589
{
15751590
#if REALM_HAVE_STD_FILESYSTEM
1576-
return (u8path(base_dir) / u8path(path)).lexically_normal().u8string();
1591+
return path_to_string((u8path(base_dir) / u8path(path)).lexically_normal());
15771592
#else
15781593
char dir_sep = '/';
15791594
std::string path_2 = path;
@@ -1615,7 +1630,7 @@ std::string File::resolve(const std::string& path, const std::string& base_dir)
16151630
std::string File::parent_dir(const std::string& path)
16161631
{
16171632
#if REALM_HAVE_STD_FILESYSTEM
1618-
return u8path(path).parent_path().u8string(); // Throws
1633+
return path_to_string(u8path(path).parent_path()); // Throws
16191634
#else
16201635
auto is_sep = [](char c) -> bool {
16211636
return c == '/' || c == '\\';
@@ -1864,7 +1879,7 @@ bool DirScanner::next(std::string& name)
18641879
const std::filesystem::directory_iterator end;
18651880
if (m_iterator == end)
18661881
return false;
1867-
name = m_iterator->path().filename().u8string();
1882+
name = path_to_string(m_iterator->path().filename());
18681883
m_iterator++;
18691884
return true;
18701885
}

test/benchmark-common-tasks/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ template <typename Type>
581581
struct BenchmarkMixedCaseInsensitiveEqual : public BenchmarkWithType<Type> {
582582
using Base = BenchmarkWithType<Type>;
583583
using underlying_type = typename Type::underlying_type;
584-
BenchmarkMixedCaseInsensitiveEqual<Type>()
584+
BenchmarkMixedCaseInsensitiveEqual()
585585
: BenchmarkWithType<Type>()
586586
{
587587
BenchmarkWithType<Type>::set_name_with_prefix("QueryInsensitiveEqual");
@@ -610,7 +610,7 @@ template <typename Type>
610610
struct BenchmarkRangeForType : public BenchmarkWithType<Type> {
611611
using Base = BenchmarkWithType<Type>;
612612
using underlying_type = typename Type::underlying_type;
613-
BenchmarkRangeForType<Type>()
613+
BenchmarkRangeForType()
614614
: BenchmarkWithType<Type>()
615615
{
616616
BenchmarkWithType<Type>::set_name_with_prefix("QueryRange");
@@ -647,7 +647,7 @@ template <typename Type>
647647
struct BenchmarkCreateIndexForType : public BenchmarkWithType<Type> {
648648
using Base = BenchmarkWithType<Type>;
649649
using underlying_type = typename Type::underlying_type;
650-
BenchmarkCreateIndexForType<Type>()
650+
BenchmarkCreateIndexForType()
651651
: BenchmarkWithType<Type>()
652652
{
653653
BenchmarkWithType<Type>::set_name_with_prefix("CreateIndexFor");
@@ -669,7 +669,7 @@ template <typename Type>
669669
struct BenchmarkInsertToIndexForType : public BenchmarkWithType<Type> {
670670
using Base = BenchmarkWithType<Type>;
671671
using underlying_type = typename Type::underlying_type;
672-
BenchmarkInsertToIndexForType<Type>()
672+
BenchmarkInsertToIndexForType()
673673
: BenchmarkWithType<Type>()
674674
{
675675
BenchmarkWithType<Type>::set_name_with_prefix("InsertWithIndex");
@@ -706,7 +706,7 @@ template <typename Type>
706706
struct BenchmarkInsertPKToIndexForType : public BenchmarkWithType<Type> {
707707
using Base = BenchmarkWithType<Type>;
708708
using underlying_type = typename Type::underlying_type;
709-
BenchmarkInsertPKToIndexForType<Type>()
709+
BenchmarkInsertPKToIndexForType()
710710
: BenchmarkWithType<Type>()
711711
{
712712
BenchmarkWithType<Type>::set_name_with_prefix("InsertPK");
@@ -739,7 +739,7 @@ template <typename Type>
739739
struct BenchmarkEraseObjectForType : public BenchmarkWithType<Type> {
740740
using Base = BenchmarkWithType<Type>;
741741
using underlying_type = typename Type::underlying_type;
742-
BenchmarkEraseObjectForType<Type>()
742+
BenchmarkEraseObjectForType()
743743
: BenchmarkWithType<Type>()
744744
{
745745
BenchmarkWithType<Type>::set_name_with_prefix("EraseObject");
@@ -760,7 +760,7 @@ template <typename Type, size_t NUM_CONDITIONS>
760760
struct BenchmarkParsedChainedOrEquality : public BenchmarkWithType<Type> {
761761
using Base = BenchmarkWithType<Type>;
762762
using underlying_type = typename Type::underlying_type;
763-
BenchmarkParsedChainedOrEquality<Type, NUM_CONDITIONS>()
763+
BenchmarkParsedChainedOrEquality()
764764
: BenchmarkWithType<Type>()
765765
{
766766
BenchmarkWithType<Type>::set_name_with_prefix(util::format("QueryChainedOrEquality_%1", NUM_CONDITIONS));
@@ -803,7 +803,7 @@ template <typename Type, size_t NUM_CONDITIONS>
803803
struct BenchmarkParsedIn : public BenchmarkWithType<Type> {
804804
using Base = BenchmarkWithType<Type>;
805805
using underlying_type = typename Type::underlying_type;
806-
BenchmarkParsedIn<Type, NUM_CONDITIONS>()
806+
BenchmarkParsedIn()
807807
: BenchmarkWithType<Type>()
808808
{
809809
BenchmarkWithType<Type>::set_name_with_prefix(util::format("QueryParsedIN_%1", NUM_CONDITIONS));

test/util/test_path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool initialize_test_path(int argc, const char* argv[])
134134
}
135135
PathCchRemoveFileSpec(path, MAX_PATH);
136136
SetCurrentDirectory(path);
137-
g_path_prefix = std::filesystem::path(path).u8string();
137+
g_path_prefix = std::string(reinterpret_cast<const char*>(std::filesystem::path(path).u8string().c_str()));
138138
g_resource_path = g_path_prefix + "\\resources\\";
139139
#else
140140
char executable[PATH_MAX];

0 commit comments

Comments
 (0)