Fix build with MinGW
Summary: There still are many warnings (most of them about invalid printf format for long long), but it builds if FAIL_ON_WARNINGS is disabled. Closes https://github.com/facebook/rocksdb/pull/2052 Differential Revision: D4807355 Pulled By: siying fbshipit-source-id: ef03786
This commit is contained in:
parent
80fe5b3855
commit
6401a8b76b
@ -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}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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_);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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<uint64_t>::max();
|
||||
const size_t size_max = std::numeric_limits<size_t>::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;
|
||||
|
Loading…
Reference in New Issue
Block a user