-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support mingw-w64 (from msys2) on Windows. #1570
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
Conversation
Signed-off-by: Tao He <[email protected]>
/cc @barcharcraz. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick look at this, and I'm a bit concerned about how many new preprocessor branches are added. I'm also concerned that you are conditionally avoiding calling functions that should be available on mingw-w64, as they are in the UCRT and the legacy CRT.
# on mingw there are tons of warnings. | ||
set(WERROR OFF CACHE BOOL "Treat Warnings as Errors.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep WERROR on, and either address the warnings or tell people to turn it off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing the warnings requires a lot changes in the codebase. Could I print a CMake warning if users are working with MinGW and WERROR
is ON
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah a warning is fine, I just don't like setting werror based on platform
SET(DEFAULT_BUILD_TYPE "Release") | ||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") | ||
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't change the build type like this, just print a warning during configuration if the build isn't likely to work.
# | ||
# see also: https://stackoverflow.com/questions/14125007/gcc-string-table-overflow-error-during-compilation | ||
if(MINGW AND CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
message(FATAL_ERROR "mingw-w64 cannot build the debug version of this library") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a forward compat issue, just warn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fixes that by using a warning.
#ifdef _WIN32 | ||
#if defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
driveby change
@@ -69,7 +69,7 @@ | |||
#endif // __clang__ | |||
#endif // _WIN32 | |||
|
|||
#ifdef _NO_ASYNCRTIMP | |||
#if defined(_NO_ASYNCRTIMP) || defined(__MINGW32__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just force _NO_ASYNCRTIMP on mingw, don't special case the feature here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, actually this is a visibility macro, so I'm not sure this is even right, even on mingw if you're building a shared library I think you need __declspec(dllexport) (attribute((visibility)) may work as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember it correctly mingw-w64 (gcc) exports all symbol by default, just like what happens to the shared library on Linux.
But I would restore the dllexport behaviour on mingw-w64 by good.
#if defined(__MINGW32__) | ||
// link error on mingw-w64: undefined reference to `__imp__wcstod_l' | ||
return wcstod(str, nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_wcstod_l should be available in mingw
#else // LINUX or APPLE | ||
#endif // _WIN32 | ||
|
||
#if !defined(_WIN32) || defined(__MINGW32__) // LINUX, APPLE or MinGW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably either be based on GCC or on detecting libstdc++
bool _open_fsb_str(_filestream_callback* callback, const wchar_t* filename, std::ios_base::openmode mode, int prot) { | ||
return _open_fsb_str(callback, utility::conversions::to_utf8string(filename).c_str(), mode, prot); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why these wide functions are required for mingw but somehow not for msvc with /UNICODE
#if !defined(__MINGW32__) | ||
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW | _CRTDBG_MODE_DEBUG); | ||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | ||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW | _CRTDBG_MODE_DEBUG); | ||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | ||
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); | ||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | ||
#endif // !defined(__MINGW32__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just do _MSC_VER here, or perhaps _UCRT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will fix.
|
||
#if defined(__MINGW32__) | ||
const auto numChars = strnlen(tempBuffer, tempSize); | ||
#else | ||
const auto numChars = strnlen_s(tempBuffer, tempSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strnlen_s
should be available in mingw (but not msys)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will double check that, but I remember here is an compile error.
@barcharcraz Thanks for reviewing this PR! I will revise that as soon as my Windows laptop back. |
Got this error during "make -j":
|
I guess this PR is dead? |
Not dead yet. Will address the review comments in this Sep. |
Closing. Will reopen when I come back to this project. |
Supporting for MinGW on Windows is a long-standling feature request for the cpprestsdk project. This PR makes the codebase compilable with mingw-w64 from msys2, include main library, test cases and examples.
At the same time, this PR has minimized the changeset for the convenience of code review.
Resolves #202, #1361 and #1541.