windows build has more issues #10

Merged
jorijnvdgraaf merged 1 commit from claude/issue-9 into master 2026-05-27 05:15:54 +02:00
Showing only changes of commit 47b886602a - Show all commits

fix: unbreak mingw build of Crafter.Build-Clang
Some checks failed
CI / build-test-release (pull_request) Has been cancelled

Two Windows-only compile errors blocked the mingw cross-compile:

* `<winsock2.h>` transitively includes `<rpc.h>`, which defines
  `#define interface struct`. The file uses `interface` as a loop
  variable name in three for-loops, so on mingw it expanded into
  `for(... struct : ...)` and cascaded into a wall of unrelated parse
  errors. Undefine the macro right after the Windows headers in the
  global module fragment.
* `static_cast<uint16_t>` in the port-probe helper failed because
  mingw's `<stdint.h>` typedefs are in the global module fragment and
  the C-namespace `::uint16_t` isn't anchored into the module purview
  on this toolchain. `import std;` does export `std::uint16_t`, so
  qualify the cast.

Verified by running `crafter-build --target=x86_64-w64-mingw32` end to
end and the full test suite (13 passed, 5 environment-skipped).
catbot 2026-05-27 03:15:19 +00:00

View file

@ -21,6 +21,9 @@ module;
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32) #if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
// <rpc.h> (pulled in transitively) defines `interface` as a macro for `struct`,
// which collides with local variables named `interface` in this TU.
#undef interface
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -1471,7 +1474,7 @@ int Crafter::Run(int argc, char** argv) {
sockaddr_in addr{}; sockaddr_in addr{};
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(static_cast<uint16_t>(p)); addr.sin_port = htons(static_cast<std::uint16_t>(p));
bool ok = ::bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == 0; bool ok = ::bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == 0;
closesock(s); closesock(s);
if (ok) return p; if (ok) return p;