This PR adds support for compilation with MinGW, and modifies the CI to also run MinGW in the test matrix to avoid regressions.
Modifications are trivial and listed here:
_MSC_VER was used to both test for MSVC and Windows. Changed it to _WIN32 where it actually meant "check for Windows" (eg: around all usages of Windows APIs).
To compile MS structure definitions that use non-standard C++ code (anonymous structs in unions), it is necessary to either disable -Wpedantic or use -fms-extensions. It is my understanding that subprocess.h tries to be compatible with the strictest compile time options, so I went for scoped disabling of -Wpedantic via #pragma
In MinGW, weak functions are basically non-working because of weird interactions with PE/COFF. I've changed the definition of subprocess_weak to static __attribute__((used)) for MinGW. Yes, it means the code gets linked multiple times, but I don't know of any other solution. Other single-file libraries opt for an external define to differentiate declaration vs definition, but since that's not the case here, it looks like duplicating code is the only solution.
I also did some similar changes to utest.h. I understand that utest.h is separately maintained, but I guess it can be upstreamed later if this PR is approved.
MSVC predefines _DLL as an empty macro instead of giving it value 1 like MSVC does. I've changed the check to cover both cases.
Some tests that are disabled for MSVC appears to pass in MinGW. Activate those.
I forgot to mention two unrelated changes that I’ve left in, but I can back out if you prefer:
Change CI to run in all branches. This was useful to me to test the changes in my fork before opening the PR. I can back it out if you feel strongly, but I think it makes it harder for contributors to test modifications.
clang-10 doesn’t exist anymore in today’s ubuntu-latest image, so CI is actually broken right now on master. I changed it to be a rolling package “clang”, but let me know what you prefer here.
This PR adds support for compilation with MinGW, and modifies the CI to also run MinGW in the test matrix to avoid regressions.
Modifications are trivial and listed here:
_MSC_VER
was used to both test for MSVC and Windows. Changed it to_WIN32
where it actually meant "check for Windows" (eg: around all usages of Windows APIs).-Wpedantic
or use-fms-extensions
. It is my understanding that subprocess.h tries to be compatible with the strictest compile time options, so I went for scoped disabling of-Wpedantic
via#pragma
subprocess_weak
tostatic __attribute__((used))
for MinGW. Yes, it means the code gets linked multiple times, but I don't know of any other solution. Other single-file libraries opt for an external define to differentiate declaration vs definition, but since that's not the case here, it looks like duplicating code is the only solution.Some tests that are disabled for MSVC appears to pass in MinGW. Activate those.