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

Building for Windows using C++20 #7841

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* 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)
* Upload completion is now tracked in a multiprocess-compatible manner ([PR #7796](https://github.com/realm/realm-core/pull/7796)).
* 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))
* Building using C++20 on Windows.

----------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ if(MSVC)
# We use these in our AtomicSharedPtr implementation and it can't move
# to atomic<shared_ptr<T>> because NotificationToken relies on movability.
add_compile_options(/D_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING)

# Enable __cplusplus macro
add_compile_options(/Zc:__cplusplus)
else()
add_compile_options(-Wall -Wextra -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code -Wunused-parameter -Wno-missing-field-initializers)
# TODO: Remove this when fixed
Expand Down
27 changes: 19 additions & 8 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ functions:
script: |-
if ls crash-*> /dev/null 2>&1; then
echo "Found crash file"
#Rename the crash file and the realm file.
#Rename the crash file and the realm file.
#If there is a crash, this will signal that something needs to be uploaded.
mv crash-* realm-fuzzer-crash.txt
mv fuzz-realm.realm fuzzer_realm.realm
Expand Down Expand Up @@ -459,7 +459,7 @@ functions:
bucket: mciuploads
permissions: public-read
content_type: application/x-binary
display_name: Realm File
display_name: Realm File
optional: true

- command: shell.exec
Expand Down Expand Up @@ -515,7 +515,7 @@ functions:
set -o verbose

TOP_DIR=$(pwd)

HANG_ANALYZER_PATH=$TOP_DIR/evergreen/hang_analyzer
REQUIREMENTS_PATH=$HANG_ANALYZER_PATH/requirements.txt

Expand Down Expand Up @@ -1166,7 +1166,7 @@ tasks:
./build/test/${cmake_build_type|Debug}-iphonesimulator/realm-combined-tests.app \
'io.realm.CombinedTests' \
$TEST_RESULTS_FILE

- name: generate-sync-corpus
tags: [ "for_nightly_tests" ]
exec_timeout_secs: 1800
Expand Down Expand Up @@ -1393,6 +1393,19 @@ buildvariants:
- name: compile_test
- name: lint

- name: ubuntu-cpp20
display_name: "Ubuntu C++20"
run_on: ubuntu2404-arm64-large
expansions:
fetch_missing_dependencies: On
c_compiler: "/opt/clang+llvm/bin/clang"
cxx_compiler: "/opt/clang+llvm/bin/clang++"
clang_format: "/opt/clang+llvm/bin/clang-format"
extra_flags: -DCMAKE_CXX_STANDARD=20
tasks:
- name: compile_test
- name: lint

- name: ubuntu-no-session-multiplexing
display_name: "Ubuntu (Sync Multiplexing Disabled)"
run_on: ubuntu2204-arm64-large
Expand Down Expand Up @@ -1469,7 +1482,7 @@ buildvariants:
fetch_missing_dependencies: On
c_compiler: "/opt/clang+llvm/bin/clang"
cxx_compiler: "/opt/clang+llvm/bin/clang++"
run_with_encryption: 1
run_with_encryption: 1
enable_asan: On
cmake_build_type: RelWithDebInfo
tasks:
Expand All @@ -1492,7 +1505,7 @@ buildvariants:
cxx_compiler: "./clang_binaries/bin/clang++"
python3: /opt/mongodbtoolchain/v3/bin/python3
tasks:
- name: compile_test_and_package
- name: compile_test_and_package
- name: benchmarks
- name: generate-sync-corpus

Expand Down Expand Up @@ -1979,5 +1992,3 @@ buildvariants:
# no_tests: On
# tasks:
# - name: compile_only


4 changes: 2 additions & 2 deletions src/external/bson/bson-decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ _mul_64x64 (uint64_t left, /* IN */
* Returns:
* The lowercased character.
*/
char
static char
_dec128_tolower (char c)
{
if (isupper (c)) {
Expand All @@ -395,7 +395,7 @@ _dec128_tolower (char c)
* Returns:
* true if the strings are equal, false otherwise.
*/
bool
static bool
_dec128_istreq (const char *a, /* IN */
const char *b /* IN */)
{
Expand Down
2 changes: 1 addition & 1 deletion src/external/bson/bson-iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ _bson_iter_next_internal (bson_iter_t *iter, /* INOUT */
subtype = *(iter->raw + iter->d2);

if (subtype == BSON_SUBTYPE_BINARY_DEPRECATED) {
int32_t binary_len;
uint32_t binary_len;

if (l < 4) {
iter->err_off = o;
Expand Down
25 changes: 20 additions & 5 deletions src/realm/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,22 @@ struct WindowsFileHandleHolder {
#endif

#if REALM_HAVE_STD_FILESYSTEM
#if __cplusplus < 202002L
using std::filesystem::u8path;
inline std::string path_to_string(const std::filesystem::path& path)
{
return path.u8string();
}
#else
inline std::string path_to_string(const std::filesystem::path& path)
{
return reinterpret_cast<const char*>(path.u8string().c_str());
}
inline auto u8path(const std::string& str)
{
return std::filesystem::path(reinterpret_cast<const char8_t*>(str.c_str()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit concerned that this converts using the constructor that terminates at the first null byte, regardless of the length of the original string. But I suppose this is not actually a problem because null bytes cannot be in a file path.

};
#endif

void throwIfCreateDirectoryError(std::error_code error, const std::string& path)
{
Expand Down Expand Up @@ -340,7 +355,7 @@ std::string make_temp_dir()
}
break;
}
return path.u8string();
return path_to_string(path);

#else // POSIX.1-2008 version

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

return std::filesystem::path(buffer).u8string();
return path_to_string(std::filesystem::path(buffer));

#else // POSIX.1-2008 version

Expand Down Expand Up @@ -1573,7 +1588,7 @@ std::string File::get_path() const
std::string File::resolve(const std::string& path, const std::string& base_dir)
{
#if REALM_HAVE_STD_FILESYSTEM
return (u8path(base_dir) / u8path(path)).lexically_normal().u8string();
return path_to_string((u8path(base_dir) / u8path(path)).lexically_normal());
#else
char dir_sep = '/';
std::string path_2 = path;
Expand Down Expand Up @@ -1615,7 +1630,7 @@ std::string File::resolve(const std::string& path, const std::string& base_dir)
std::string File::parent_dir(const std::string& path)
{
#if REALM_HAVE_STD_FILESYSTEM
return u8path(path).parent_path().u8string(); // Throws
return path_to_string(u8path(path).parent_path()); // Throws
#else
auto is_sep = [](char c) -> bool {
return c == '/' || c == '\\';
Expand Down Expand Up @@ -1864,7 +1879,7 @@ bool DirScanner::next(std::string& name)
const std::filesystem::directory_iterator end;
if (m_iterator == end)
return false;
name = m_iterator->path().filename().u8string();
name = path_to_string(m_iterator->path().filename());
m_iterator++;
return true;
}
Expand Down
16 changes: 8 additions & 8 deletions test/benchmark-common-tasks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ template <typename Type>
struct BenchmarkMixedCaseInsensitiveEqual : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkMixedCaseInsensitiveEqual<Type>()
BenchmarkMixedCaseInsensitiveEqual()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("QueryInsensitiveEqual");
Expand Down Expand Up @@ -610,7 +610,7 @@ template <typename Type>
struct BenchmarkRangeForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkRangeForType<Type>()
BenchmarkRangeForType()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("QueryRange");
Expand Down Expand Up @@ -647,7 +647,7 @@ template <typename Type>
struct BenchmarkCreateIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkCreateIndexForType<Type>()
BenchmarkCreateIndexForType()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("CreateIndexFor");
Expand All @@ -669,7 +669,7 @@ template <typename Type>
struct BenchmarkInsertToIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkInsertToIndexForType<Type>()
BenchmarkInsertToIndexForType()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("InsertWithIndex");
Expand Down Expand Up @@ -706,7 +706,7 @@ template <typename Type>
struct BenchmarkInsertPKToIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkInsertPKToIndexForType<Type>()
BenchmarkInsertPKToIndexForType()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("InsertPK");
Expand Down Expand Up @@ -739,7 +739,7 @@ template <typename Type>
struct BenchmarkEraseObjectForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkEraseObjectForType<Type>()
BenchmarkEraseObjectForType()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("EraseObject");
Expand All @@ -760,7 +760,7 @@ template <typename Type, size_t NUM_CONDITIONS>
struct BenchmarkParsedChainedOrEquality : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkParsedChainedOrEquality<Type, NUM_CONDITIONS>()
BenchmarkParsedChainedOrEquality()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix(util::format("QueryChainedOrEquality_%1", NUM_CONDITIONS));
Expand Down Expand Up @@ -803,7 +803,7 @@ template <typename Type, size_t NUM_CONDITIONS>
struct BenchmarkParsedIn : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkParsedIn<Type, NUM_CONDITIONS>()
BenchmarkParsedIn()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix(util::format("QueryParsedIN_%1", NUM_CONDITIONS));
Expand Down
2 changes: 1 addition & 1 deletion test/util/test_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool initialize_test_path(int argc, const char* argv[])
}
PathCchRemoveFileSpec(path, MAX_PATH);
SetCurrentDirectory(path);
g_path_prefix = std::filesystem::path(path).u8string();
g_path_prefix = std::string(reinterpret_cast<const char*>(std::filesystem::path(path).u8string().c_str()));
g_resource_path = g_path_prefix + "\\resources\\";
#else
char executable[PATH_MAX];
Expand Down
Loading