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

Fix build with MinGW #2052

Closed
wants to merge 1 commit into from
Closed

Fix build with MinGW #2052

wants to merge 1 commit into from

Conversation

orgads
Copy link
Contributor

@orgads orgads commented Mar 29, 2017

There still are many warnings (most of them about invalid printf format
for long long), but it builds if FAIL_ON_WARNINGS is disabled.

@yuslepukhin
Copy link
Contributor

@orgads Generally, looks good but you will need to fix XPRESS compression build. Don't know why this started failing but suspect because of the additional define on the compile line. If it is indeed so, I suggest you add that one for gcc-on-windows only

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

@orgads
Copy link
Contributor Author

orgads commented Mar 29, 2017

There. No warnings at all.

I couldn't find a proper fix for the format warnings (believe me, it's complicated ;)), so I muted them on this platform. Other platforms will report those.

CMakeLists.txt Outdated
COMPILE_FLAGS "-DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb")
else()
if(MSVC)
set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a bit of duplication here and in line 526. Can you suggest a way to reduce it? I don't use CMake often...

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks.

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is incorrect. I ran into this warning as well, which I believe is due to a bug in mingw's inttypes.h introduced in https://sourceforge.net/p/mingw-w64/mingw-w64/ci/35d4bb429fb3bb13e9659ad4534ec784545a28ce/

The bug is that mingw-w64-headers/include/_mingw_print_push.h defines all the macros to GNU-specific values, rather than MS-specific values as the comment claims.

Copy link
Contributor Author

@orgads orgads Mar 29, 2017

Choose a reason for hiding this comment

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

I tracked it down. Let me elaborate.

The problem is that _mingw_print_pop.h defines GNU values if __USE_MINGW_ANSI_STDIO is defined and is not zero. But in mingw's os_defines.h there's:

// Make sure that POSIX printf/scanf functions are activated.  As
// libstdc++ depends on POSIX-definitions of those functions, we define
// it unconditionally.
#undef __USE_MINGW_ANSI_STDIO
#define __USE_MINGW_ANSI_STDIO 1

This is needed for C++ streams. And it doesn't help to set it as a gcc flag because it is being overridden.

See this discussion and this one on similar issues. Apparently the CRT works with these specifiers (%lld etc.), so these are false alarms on this case.

Anyway, even if this is/will be fixed upstream, you still need to be able to compile with older mingw versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you're saying; it seems pretty clear that the author of that commit simply made a mistake in _mingw_print_pop where he sets %lld, etc, instead of the correct MS-specific macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like you didn't follow the second link :). Let me quote:

The os_defines.h is done deliberately though, so std::cout and friends
can print 64bit integers properly.

Anyway, this discussion doesn't belong here but to the mingw mailing list. We need to live with what we have. If you find a way to use the MS defines I'll accept it.

Notice that the GNU specifiers do work as intended, even with the standard MSVCRT, so we can safely ignore the warnings.

CMakeLists.txt Outdated
COMPILE_FLAGS "-DROCKSDB_DLL -DROCKSDB_LIBRARY_EXPORTS /Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb")
else()
if(MSVC)
set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, but not all users have the latest and greatest mingw, and it makes sense to support at least one version back. Moreover, using strncpy with strlen is funny.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you're correct. I think the point is that you can omit the second parameter in your call to take advantage of the template magic explained in https://msdn.microsoft.com/en-us/library/ms175759.aspx (for which I added support in the above commit).

I don't know why this was using strncpy_s before.

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I think you should be able to write

strcpy_s(dir->entry_.d_name, dir->data_.name);

here, and

strcpy_s(dirp->entry_.d_name, dirp->data_.name);

below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this will not compile with MinGW 6.2.0. Why should we support only >=6.3.0 just for a negligible style improvement?

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, it seems like this patch hasn't made it into any release (the latest looks to be mingw-w64 v5.0.2; 6.2.0 is the gcc version, I think).

Anyway, you're right, this is fine.

@@ -8676,8 +8676,8 @@ void Notification::WaitForNotification() {
}

Mutex::Mutex()
: type_(kDynamic),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go upstream, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It already has: google/googletest@3330752

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, should probably file an issue to upgrade this to dependency to 1.8.0.

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

@@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This obviously doesn't work as expected on 32-bit platforms (regardless of my change), but this test is disabled anyway...

@siying
Copy link
Contributor

siying commented Mar 30, 2017

A dumb question, does MinGW work using make instead of cmake?

@tamird
Copy link
Contributor

tamird commented Mar 30, 2017

Not on Windows.

EDIT: it might in the general case, but the current make-based build system doesn't support windows.

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

CMakeLists.txt Outdated
endif()

if(WIN32)
if(MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine this with the other MSVC block a few lines down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@facebook-github-bot
Copy link
Contributor

@orgads updated the pull request - view changes

@siying
Copy link
Contributor

siying commented Mar 30, 2017

@yuslepukhin are you OK if I merge this PR?

@tamird
Copy link
Contributor

tamird commented Mar 30, 2017

@siying have you considered adding the mingw build to appveyor?

@siying
Copy link
Contributor

siying commented Mar 30, 2017

@tamird you are welcome to add it, unless it takes too much time budget, or @yuslepukhin has an objection.

@tamird
Copy link
Contributor

tamird commented Mar 30, 2017

Sounds good. Could you share the commands you used to build and run the tests?

@tamird
Copy link
Contributor

tamird commented Mar 30, 2017

In the meantime, please feel free to merge this when you get the necessary approvals. I'll be happy to see it go in.

@siying
Copy link
Contributor

siying commented Mar 30, 2017

@tamird the entrance is appveyor.xml https://github.com/facebook/rocksdb/blob/master/appveyor.yml . I assume you need to add the test there. @yuslepukhin knows much better than me.

@tamird
Copy link
Contributor

tamird commented Mar 30, 2017

Sorry, I meant the commands you ran locally to build and test on mingw.

Something like

mkdir rocksdb-build
cd rocksdb-build
cmake -G 'MSYS Makefiles' ../rocksdb
cmake --build .

?

@orgads
Copy link
Contributor Author

orgads commented Mar 30, 2017

The generator is MinGW Makefiles. The rest is right. And you need to have mingw bin directory in your PATH.

And if you want to take advantage of all your cores, execute:

cmake --build . -- -j%NUMBER_OR_PROCESSORS%

(or $NUMBER_OF_PROCESSORS, depends if you run it from bash or the command prompt)

@yuslepukhin
Copy link
Contributor

@siying I am fine with merging it. With regards to AppVeyor, you need to check if they support it.

@facebook-github-bot
Copy link
Contributor

@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

daviesrob added a commit to daviesrob/htslib that referenced this pull request Mar 8, 2018
It appears -Wformat is broken in mingw-w64's gcc at present.
For example, see discussion at:
facebook/rocksdb#2052 (comment)

As there is no easy fix, turn off format warnings in appveyor
configuration to reduce clutter in the output.
daviesrob added a commit to daviesrob/htslib that referenced this pull request Mar 8, 2018
It appears -Wformat is broken in mingw-w64's gcc at present.
For example, see discussion at:
facebook/rocksdb#2052 (comment)

As there is no easy fix, turn off format warnings in appveyor
configuration to reduce clutter in the output.
daviesrob added a commit to daviesrob/htslib that referenced this pull request Mar 15, 2018
It appears -Wformat is broken in mingw-w64's gcc at present.
For example, see discussion at:
facebook/rocksdb#2052 (comment)

As there is no easy fix, turn off format warnings in appveyor
configuration to reduce clutter in the output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants