From 42900aaffa5116588da98f4a4c7c52e4398bfc3c Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Sun, 5 Jul 2026 11:42:09 -0700 Subject: [PATCH] build: fix MinGW-w64 cross-compilation for Windows - Guard the ssize_t and mode_t typedefs that MinGW-w64 already provides. - Widen the fts.h gate that covers Windows functionality to _WIN32. - Widen the POSIX-only gates in the cio tool (pwd.h, SIGQUIT/SIGHUP, ANSI colors) to _WIN32. - Lowercase capitalized Windows header includes so they resolve on a case-sensitive filesystem when cross-compiling from Linux. - Link shell32 by its lowercase name so GNU ld resolves the import library, and link ws2_32 explicitly. GCC ignores the #pragma comment(lib) that MSVC uses for it. Signed-off-by: Jiawei Huang --- include/chunkio/chunkio_compat.h | 2 ++ src/CMakeLists.txt | 3 ++- src/cio_os.c | 2 +- src/cio_utils.c | 4 ++-- src/win32/dirent.c | 2 +- tools/cio.c | 12 ++++++------ 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/chunkio/chunkio_compat.h b/include/chunkio/chunkio_compat.h index 3e4951b..ef125bf 100644 --- a/include/chunkio/chunkio_compat.h +++ b/include/chunkio/chunkio_compat.h @@ -42,8 +42,10 @@ #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define strerror_r(errno,buf,len) strerror_s(buf,len,errno) +#ifndef __MINGW32__ typedef SSIZE_T ssize_t; typedef unsigned mode_t; +#endif static inline char* dirname(const char *path) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3590143..9d3685f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,7 +23,8 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ) set(libs ${libs} - Shell32.lib) + shell32 + ws2_32) else() set(src ${src} diff --git a/src/cio_os.c b/src/cio_os.c index 637b74e..ddbf93a 100644 --- a/src/cio_os.c +++ b/src/cio_os.c @@ -28,7 +28,7 @@ #include #ifdef _WIN32 -#include +#include #endif /* Check if a path is a directory */ diff --git a/src/cio_utils.c b/src/cio_utils.c index ca199d4..0a63cc8 100644 --- a/src/cio_utils.c +++ b/src/cio_utils.c @@ -28,7 +28,7 @@ #include #if defined(CIO_HAVE_BACKEND_FILESYSTEM) && defined(__EMSCRIPTEN__) #include -#elif defined(CIO_HAVE_BACKEND_FILESYSTEM) && !defined(_MSC_VER) +#elif defined(CIO_HAVE_BACKEND_FILESYSTEM) && !defined(_WIN32) #include #endif @@ -64,7 +64,7 @@ int cio_utils_recursive_delete(const char *dir) */ return nftw(dir, cio_utils_remove_entry, 32, FTW_DEPTH | FTW_PHYS | FTW_MOUNT); } -#elif !defined(_MSC_VER) +#elif !defined(_WIN32) /* * Taken from StackOverflow: * diff --git a/src/win32/dirent.c b/src/win32/dirent.c index 020943d..48491f2 100644 --- a/src/win32/dirent.c +++ b/src/win32/dirent.c @@ -22,7 +22,7 @@ * Win32's FIndFirstFile/FindNextFile API. */ -#include +#include #include "dirent.h" diff --git a/tools/cio.c b/tools/cio.c index a278276..3e39c23 100644 --- a/tools/cio.c +++ b/tools/cio.c @@ -24,7 +24,7 @@ #include #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif #ifdef __MACH__ @@ -35,7 +35,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #define ANSI_RESET "\033[0m" #define ANSI_BOLD "\033[1m" #define ANSI_CYAN "\033[96m" @@ -121,7 +121,7 @@ static void cio_signal_handler(int signal) write(STDERR_FILENO, s, sizeof(s) - 1); switch (signal) { cio_print_signal(SIGINT); -#ifndef _MSC_VER +#ifndef _WIN32 cio_print_signal(SIGQUIT); cio_print_signal(SIGHUP); #endif @@ -132,7 +132,7 @@ static void cio_signal_handler(int signal) /* Signal handlers */ switch (signal) { case SIGINT: -#ifndef _MSC_VER +#ifndef _WIN32 case SIGQUIT: case SIGHUP: #endif @@ -173,7 +173,7 @@ void cio_bytes_to_human_readable_size(size_t bytes, static void cio_signal_init() { signal(SIGINT, &cio_signal_handler); -#ifndef _MSC_VER +#ifndef _WIN32 signal(SIGQUIT, &cio_signal_handler); signal(SIGHUP, &cio_signal_handler); #endif @@ -206,7 +206,7 @@ static int log_cb(struct cio_ctx *ctx, int level, const char *file, int line, return 0; } -#ifndef _MSC_VER +#ifndef _WIN32 static int cio_default_root_path(char *path, int size) { int len;