diff --git a/CMakeLists.txt b/CMakeLists.txt index 28a320e5d..1610e0fbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY) add_library(build_version OBJECT ${BUILD_VERSION_CC}) target_include_directories(build_version PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/util) -if(WIN32) +if(MSVC) if (${USE_AVX2} EQUAL 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /arch:AVX2 /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue") else () @@ -126,6 +126,9 @@ if(WIN32) else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers") + if(MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format") + endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") @@ -187,7 +190,7 @@ else() set(OPTIMIZE_DEBUG ${OPTIMIZE_DEBUG_DEFAULT}) endif() -if(WIN32) +if(MSVC) if((${OPTIMIZE_DEBUG} EQUAL 1)) message(STATUS "Debug optimization is enabled") set(CMAKE_CXX_FLAGS_DEBUG "/Oxt /MDd") @@ -235,6 +238,9 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Android") add_definitions(-DOS_ANDROID) elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DNOMINMAX) + if(MINGW) + add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA) + endif() endif() if(NOT WIN32) @@ -514,18 +520,18 @@ add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES}) target_link_libraries(${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) -if(WIN32) - set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES - COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb") -endif() - if(WIN32) add_library(${ROCKSDB_IMPORT_LIB} SHARED ${SOURCES}) target_link_libraries(${ROCKSDB_IMPORT_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES - COMPILE_FLAGS "-DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb") -else() + COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS") + if(MSVC) + set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES + COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb") + set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES + COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb") + endif() endif() option(WITH_JNI "build with JNI" OFF) @@ -692,7 +698,7 @@ enable_testing() add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX}) add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE}) -if(WIN32) +if(MSVC) set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb") endif() set_target_properties(${TESTUTILLIB} diff --git a/db/write_batch_test.cc b/db/write_batch_test.cc index 5a4bfb691..3006d19f2 100644 --- a/db/write_batch_test.cc +++ b/db/write_batch_test.cc @@ -478,7 +478,7 @@ TEST_F(WriteBatchTest, DISABLED_LargeKeyValue) { // Insert key and value of 3GB and push total batch size to 12GB. static const size_t kKeyValueSize = 3221225472u; std::string raw(kKeyValueSize, 'A'); - WriteBatch batch(12884901888u + 1024u); + WriteBatch batch(size_t(12884901888ull + 1024u)); for (char i = 0; i < 2; i++) { raw[0] = 'A' + i; raw[raw.length() - 1] = 'A' - i; diff --git a/include/rocksdb/iostats_context.h b/include/rocksdb/iostats_context.h index 632fe44c8..d9880136e 100644 --- a/include/rocksdb/iostats_context.h +++ b/include/rocksdb/iostats_context.h @@ -47,7 +47,7 @@ struct IOStatsContext { }; #ifndef IOS_CROSS_COMPILE -# ifdef _WIN32 +# ifdef _MSC_VER extern __declspec(thread) IOStatsContext iostats_context; # else extern __thread IOStatsContext iostats_context; diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index 2b2d6851a..7d20c846b 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -129,7 +129,7 @@ struct PerfContext { #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) extern PerfContext perf_context; -#elif _WIN32 +#elif defined(_MSC_VER) extern __declspec(thread) PerfContext perf_context; #else extern __thread PerfContext perf_context; diff --git a/port/win/env_win.cc b/port/win/env_win.cc index ced56f7fe..ee136cc62 100644 --- a/port/win/env_win.cc +++ b/port/win/env_win.cc @@ -647,7 +647,7 @@ uint64_t WinEnvIO::NowMicros() { if (GetSystemTimePreciseAsFileTime_ != NULL) { // all std::chrono clocks on windows proved to return // values that may repeat that is not good enough for some uses. - const int64_t c_UnixEpochStartTicks = 116444736000000000i64; + const int64_t c_UnixEpochStartTicks = 116444736000000000LL; const int64_t c_FtToMicroSec = 10; // This interface needs to return system time and not diff --git a/port/win/port_win.cc b/port/win/port_win.cc index dd87c3577..3a0535bd4 100644 --- a/port/win/port_win.cc +++ b/port/win/port_win.cc @@ -142,7 +142,7 @@ DIR* opendir(const char* name) { return nullptr; } - strncpy_s(dir->entry_.d_name, dir->data_.name, strlen(dir->data_.name)); + strcpy_s(dir->entry_.d_name, sizeof(dir->entry_.d_name), dir->data_.name); return dir.release(); } @@ -164,7 +164,7 @@ struct dirent* readdir(DIR* dirp) { return nullptr; } - strncpy_s(dirp->entry_.d_name, dirp->data_.name, strlen(dirp->data_.name)); + strcpy_s(dirp->entry_.d_name, sizeof(dirp->entry_.d_name), dirp->data_.name); return &dirp->entry_; } diff --git a/port/win/port_win.h b/port/win/port_win.h index a3860cde7..2b00819f6 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -47,7 +47,9 @@ #undef GetCurrentTime #undef DeleteFile +#ifndef _SSIZE_T_DEFINED typedef SSIZE_T ssize_t; +#endif // size_t printf formatting named in the manner of C99 standard formatting // strings such as PRIu64 @@ -56,6 +58,7 @@ typedef SSIZE_T ssize_t; #define ROCKSDB_PRIszt "Iu" #endif +#ifdef _MSC_VER #define __attribute__(A) // Thread local storage on Linux @@ -64,6 +67,8 @@ typedef SSIZE_T ssize_t; #define __thread __declspec(thread) #endif +#endif + #ifndef PLATFORM_IS_LITTLE_ENDIAN #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) #endif diff --git a/port/win/win_logger.cc b/port/win/win_logger.cc index 3c4ae1f88..3d1d94b63 100644 --- a/port/win/win_logger.cc +++ b/port/win/win_logger.cc @@ -31,12 +31,12 @@ namespace port { WinLogger::WinLogger(uint64_t (*gettid)(), Env* env, HANDLE file, const InfoLogLevel log_level) : Logger(log_level), + file_(file), gettid_(gettid), log_size_(0), last_flush_micros_(0), env_(env), - flush_pending_(false), - file_(file) {} + flush_pending_(false) {} void WinLogger::DebugWriter(const char* str, int len) { DWORD bytesWritten = 0; diff --git a/port/win/win_logger.h b/port/win/win_logger.h index 84971363d..9e423d434 100644 --- a/port/win/win_logger.h +++ b/port/win/win_logger.h @@ -40,6 +40,7 @@ class WinLogger : public rocksdb::Logger { void Flush() override; + using rocksdb::Logger::Logv; void Logv(const char* format, va_list ap) override; size_t GetLogFileSize() const override; diff --git a/third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc b/third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc index 154ec6f26..e5c094583 100644 --- a/third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc +++ b/third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc @@ -8676,8 +8676,8 @@ void Notification::WaitForNotification() { } Mutex::Mutex() - : type_(kDynamic), - owner_thread_id_(0), + : owner_thread_id_(0), + type_(kDynamic), critical_section_init_phase_(0), critical_section_(new CRITICAL_SECTION) { ::InitializeCriticalSection(critical_section_); diff --git a/util/arena.cc b/util/arena.cc index 93d79d2b6..2fa225a77 100644 --- a/util/arena.cc +++ b/util/arena.cc @@ -26,7 +26,7 @@ namespace rocksdb { // MSVC complains that it is already defined since it is static in the header. -#ifndef OS_WIN +#ifndef _MSC_VER const size_t Arena::kInlineSize; #endif diff --git a/util/iostats_context.cc b/util/iostats_context.cc index a3c72db96..ecb6a1582 100644 --- a/util/iostats_context.cc +++ b/util/iostats_context.cc @@ -10,7 +10,7 @@ namespace rocksdb { #ifndef IOS_CROSS_COMPILE -# ifdef _WIN32 +# ifdef _MSC_VER __declspec(thread) IOStatsContext iostats_context; # else __thread IOStatsContext iostats_context; diff --git a/util/perf_context.cc b/util/perf_context.cc index c18413d17..2eff8c192 100644 --- a/util/perf_context.cc +++ b/util/perf_context.cc @@ -11,7 +11,7 @@ namespace rocksdb { #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) PerfContext perf_context; -#elif _WIN32 +#elif defined(_MSC_VER) __declspec(thread) PerfContext perf_context; #else __thread PerfContext perf_context; diff --git a/util/thread_local.cc b/util/thread_local.cc index 4971dde8b..1b076b862 100644 --- a/util/thread_local.cc +++ b/util/thread_local.cc @@ -180,7 +180,7 @@ pthread_key_t thread_local_key = -1; void NTAPI WinOnThreadExit(PVOID module, DWORD reason, PVOID reserved) { // We decided to punt on PROCESS_EXIT if (DLL_THREAD_DETACH == reason) { - if (thread_local_key != -1 && thread_local_inclass_routine != nullptr) { + if (thread_local_key != pthread_key_t(-1) && thread_local_inclass_routine != nullptr) { void* tls = pthread_getspecific(thread_local_key); if (tls != nullptr) { thread_local_inclass_routine(tls); @@ -191,22 +191,11 @@ void NTAPI WinOnThreadExit(PVOID module, DWORD reason, PVOID reserved) { } // wintlscleanup -#ifdef _WIN64 - -#pragma comment(linker, "/include:_tls_used") -#pragma comment(linker, "/include:p_thread_callback_on_exit") - -#else // _WIN64 - -#pragma comment(linker, "/INCLUDE:__tls_used") -#pragma comment(linker, "/INCLUDE:_p_thread_callback_on_exit") - -#endif // _WIN64 - // extern "C" suppresses C++ name mangling so we know the symbol name for the // linker /INCLUDE:symbol pragma above. extern "C" { +#ifdef _MSC_VER // The linker must not discard thread_callback_on_exit. (We force a reference // to this variable with a linker /include:symbol pragma to ensure that.) If // this variable is discarded, the OnThreadExit function will never be called. @@ -222,6 +211,9 @@ const PIMAGE_TLS_CALLBACK p_thread_callback_on_exit = // Reset the default section. #pragma const_seg() +#pragma comment(linker, "/include:_tls_used") +#pragma comment(linker, "/include:p_thread_callback_on_exit") + #else // _WIN64 #pragma data_seg(".CRT$XLB") @@ -229,8 +221,19 @@ PIMAGE_TLS_CALLBACK p_thread_callback_on_exit = wintlscleanup::WinOnThreadExit; // Reset the default section. #pragma data_seg() +#pragma comment(linker, "/INCLUDE:__tls_used") +#pragma comment(linker, "/INCLUDE:_p_thread_callback_on_exit") + #endif // _WIN64 +#else +// https://github.com/couchbase/gperftools/blob/master/src/windows/port.cc +BOOL WINAPI DllMain(HINSTANCE h, DWORD dwReason, PVOID pv) { + if (dwReason == DLL_THREAD_DETACH) + wintlscleanup::WinOnThreadExit(h, dwReason, pv); + return TRUE; +} +#endif } // extern "C" #endif // OS_WIN diff --git a/utilities/persistent_cache/persistent_cache_test.cc b/utilities/persistent_cache/persistent_cache_test.cc index 12d24552e..56246c638 100644 --- a/utilities/persistent_cache/persistent_cache_test.cc +++ b/utilities/persistent_cache/persistent_cache_test.cc @@ -324,14 +324,14 @@ void PersistentCacheDBTest::RunTest( BlockBasedTableOptions table_options; table_options.cache_index_and_filter_blocks = true; - const uint64_t uint64_max = std::numeric_limits::max(); + const size_t size_max = std::numeric_limits::max(); switch (iter) { case 0: // page cache, block cache, no-compressed cache pcache = new_pcache(/*is_compressed=*/true); table_options.persistent_cache = pcache; - table_options.block_cache = NewLRUCache(uint64_max); + table_options.block_cache = NewLRUCache(size_max); table_options.block_cache_compressed = nullptr; options.table_factory.reset(NewBlockBasedTableFactory(table_options)); break; @@ -339,8 +339,8 @@ void PersistentCacheDBTest::RunTest( // page cache, block cache, compressed cache pcache = new_pcache(/*is_compressed=*/true); table_options.persistent_cache = pcache; - table_options.block_cache = NewLRUCache(uint64_max); - table_options.block_cache_compressed = NewLRUCache(uint64_max); + table_options.block_cache = NewLRUCache(size_max); + table_options.block_cache_compressed = NewLRUCache(size_max); options.table_factory.reset(NewBlockBasedTableFactory(table_options)); break; case 2: @@ -349,8 +349,8 @@ void PersistentCacheDBTest::RunTest( // also, make block cache sizes bigger, to trigger block cache hits pcache = new_pcache(/*is_compressed=*/true); table_options.persistent_cache = pcache; - table_options.block_cache = NewLRUCache(uint64_max); - table_options.block_cache_compressed = NewLRUCache(uint64_max); + table_options.block_cache = NewLRUCache(size_max); + table_options.block_cache_compressed = NewLRUCache(size_max); options.table_factory.reset(NewBlockBasedTableFactory(table_options)); options.compression = kNoCompression; break;