Fix mingw-w64 GCC toolchain compatibility issues #1054
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes and improves libmongocrypt compatibility with the mingw-w64 GCC toolchain (referred to as just "mingw" going forward for brevity) to unblock upcoming changes to downstream mingw task coverage improvements in the C and C++ drivers.
The first issue is with libbson compatibility:
This is an old mingw compatibility problem that is well-described by this comment concerning format string tests:
Upgrading to a UCRT-based mingw-w64 toolchain is beyond the scope of this PR (although we should investigate doing so properly; filed DEVPROD-20813 in advance to prepare EVG Windows distros for such a transition). For now, given this mingw workaround applies to the entire codebase (not just libbson), a call to
add_compile_definitions()
is added to the root CMakeLists.txt that defines__USE_MINGW_ANSI_STDIO=1
for the entire project when CMake detects aMINGW
compiler is being used.The second issue is with calls to
BCrypt*
API:The platform-independent struct
aes_256_args_t
contains auint32_t *bytes_written
pointer, whereuint32_t
is anunsigned int
. This pointer type is incompatible with mingw whereULONG
is defined asunsigned long
. Therefore, aULONG bytes_written
local variable is used to obtain a valid pointer toULONG
(guarded byargs.bytes_written != nullptr
).The third issue is related to the
__USE_MINGW_ANSI_STDIO
problem above:It seems
__attribute__((format(__printf__, ...)))
is not aware of__USE_MINGW_ANSI_STDIO=1
and uses the MSVCRT-compatible (non-C99-conforming)printf
mingw definition rather than a C99-conforming definition. These warnings are addressed by usinggnu_printf
rather than__printf__
(orprintf
) when building with GCC, as currently done in mongo-c-driver (the GCC version check is omitted, as I do not believe we are, or want to, continue supporting such old GCC versions).