From f5910ea4eb39df41faf0b754a72b7a354f1b9dd1 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:54 -0700 Subject: [PATCH 01/20] build: support Windows cross-compilation with the MinGW toolchain Make the cmake tree usable for a Linux-hosted MinGW-w64 UCRT64 cross-build targeting Windows, building the standard Windows plugin profile from cmake/windows-setup.cmake: - Define _POSIX_THREAD_SAFE_FUNCTIONS so the MinGW headers declare the POSIX gmtime_r()/localtime_r() family, and keep the Winsock char-pointer signature mismatches (warnings under MSVC) from becoming hard errors under GCC 14 and later unless the strict option is set. - Derive the autoconf host triple from the cross compiler when CMAKE_CROSSCOMPILING and no GNU_HOST was given, so the external autotools sub-builds (libbacktrace, jemalloc) configure for the target instead of silently producing build-host objects. - Use plain make for external autotools sub-builds under the Ninja generator on all targets; the $(MAKE) escape only exists in the Make-family generators. - Give the executable an import-library suffix distinct from the shared library's on MinGW, mirroring the MSVC branch; Ninja rejects the duplicate libfluent-bit.dll.a output NMake never noticed. - Link libbacktrace on fluent-bit-static, where the stacktrace helpers are compiled, so GNU ld orders the archive correctly. - Guard the MSVC /W2 warning flag with if(MSVC) in the core and plugin cmake files, link the Windows system libraries by their lowercase names (GNU ld resolves them against import libraries, MSVC accepts them unchanged), and append to FLB_DEPS instead of overwriting it so onigmo-static and friends survive on Windows. - Keep the ELF hardening link flags off for all Windows targets, not just MSVC, since GNU ld does not support them for PE. - Define YAML_DECLARE_STATIC for any Windows toolchain when FLB_LIBYAML_DIR is given; that path carries a static libyaml for MSVC (vcpkg static triplets) and MinGW alike. - Link OpenSSL statically only on MSVC; the MinGW cross-build uses the toolchain's dynamic OpenSSL to avoid GNU ld link-order issues. - Keep FLB_HAVE_UNIX_SOCKET off for non-MSVC Windows builds: the Windows unix socket paths are untested, so keep feature parity with MSVC. - Skip the tools/xxd-c host tool when cross-compiling, since it cannot run on the build host. - Overwrite onigmo's generated config.h with the win32/config.h it ships when cross-compiling to Windows; Onigmo's configure-time probes otherwise inspect the build host and misdetect the target. This keeps the vendored onigmo tree unpatched. Signed-off-by: Jiawei Huang --- CMakeLists.txt | 59 +++++++++++++++++++++++++++++++++++++----- plugins/CMakeLists.txt | 4 ++- src/CMakeLists.txt | 30 ++++++++++++++++----- 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f545f5bc08..84cae7d44bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,20 @@ if (MSVC) add_compile_options(/MT) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + if (MINGW) + # MinGW-w64 headers only declare the POSIX thread-safe time functions + # (gmtime_r and friends) when the feature test macro is set. + add_definitions(-D_POSIX_THREAD_SAFE_FUNCTIONS=200112L) + + # The Winsock APIs take 'char *' buffers where POSIX takes 'void *', + # which trips -Wincompatible-pointer-types across the code base. MSVC + # reports the same mismatches as warnings; keep GCC (>= 14 makes them + # errors by default) at warning level too unless the strict option is + # enabled explicitly. + if(NOT FLB_COMPILER_STRICT_POINTER_TYPES) + add_compile_options(-Wno-error=incompatible-pointer-types) + endif() + endif() if (CMAKE_SYSTEM_NAME STREQUAL "Linux") # Prevent the toolchain from emitting an executable stack on Linux targets, # which triggers kernel warnings (e.g. "started with executable stack") and @@ -570,7 +584,7 @@ endif() # Harden release binary against security vulnerabilities if(FLB_SECURITY STREQUAL "On" OR (FLB_SECURITY STREQUAL "ReleaseOnly" AND FLB_RELEASE)) - if (NOT MSVC) + if (NOT WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,relro,-z,now") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack") if(NOT FLB_SMALL) @@ -865,8 +879,10 @@ if(FLB_TLS) option(ENABLE_PROGRAMS OFF) option(INSTALL_MBEDTLS_HEADERS OFF) - # Link OpenSSL statically on Windows. - if (FLB_SYSTEM_WINDOWS) + # Link OpenSSL statically on MSVC Windows builds only. + # MinGW cross-compiles use dynamic OpenSSL to avoid GNU ld link-order issues + # with static archives that have cascading system library dependencies. + if (FLB_SYSTEM_WINDOWS AND MSVC) set(OPENSSL_USE_STATIC_LIBS ON) set(OPENSSL_MSVC_STATIC_RT ON) endif() @@ -1138,7 +1154,9 @@ check_c_source_compiles(" close(sock); return 0; }" FLB_HAVE_UNIX_SOCKET) -if(FLB_HAVE_UNIX_SOCKET) +if(FLB_HAVE_UNIX_SOCKET AND NOT FLB_SYSTEM_WINDOWS) + # MinGW headers can satisfy the sys/un.h probe, but the Windows unix + # socket paths are untested; keep feature parity with MSVC builds. FLB_DEFINITION(FLB_HAVE_UNIX_SOCKET) endif() @@ -1170,7 +1188,10 @@ if(FLB_CONFIG_YAML) set(LIBYAML_LIBRARY_DIRS "${FLB_LIBYAML_DIR}/lib") set(LIBYAML_INCLUDEDIR "${FLB_LIBYAML_DIR}/include") message(STATUS "specified libyaml dir: ${FLB_LIBYAML_DIR}") - if (MSVC) + if (FLB_SYSTEM_WINDOWS) + # FLB_LIBYAML_DIR on Windows carries a static libyaml (the MSVC CI + # uses vcpkg static triplets, MinGW cross-builds a static libyaml), + # so keep from declaring dllimport symbols. FLB_DEFINITION(YAML_DECLARE_STATIC) endif () set(FLB_HAVE_LIBYAML 1) @@ -1233,7 +1254,9 @@ if (FLB_BENCHMARKS) endif() # Build tools/xxd-c -add_subdirectory(tools/xxd-c) +if(NOT CMAKE_CROSSCOMPILING) + add_subdirectory(tools/xxd-c) +endif() # Static configuration generator (using xxd-c) if(FLB_STATIC_CONF) @@ -1256,13 +1279,29 @@ if(FLB_PROXY_GO) FLB_DEFINITION(FLB_HAVE_PROXY_GO) endif() +if("${GNU_HOST}" STREQUAL "" AND CMAKE_CROSSCOMPILING + AND CMAKE_C_COMPILER_ID STREQUAL "GNU") + # Derive the autoconf host triple from the cross compiler so the + # external autotools sub-builds (libbacktrace, jemalloc) configure for + # the target instead of silently building host objects. + get_filename_component(FLB_C_COMPILER_NAME "${CMAKE_C_COMPILER}" NAME) + string(REGEX REPLACE "-gcc(-[0-9.]+)?$" "" GNU_HOST "${FLB_C_COMPILER_NAME}") + if(GNU_HOST STREQUAL FLB_C_COMPILER_NAME) + # Compiler name carries no triple prefix; leave GNU_HOST unset. + set(GNU_HOST "") + endif() +endif() + if("${GNU_HOST}" STREQUAL "") set(AUTOCONF_HOST_OPT "") else() set(AUTOCONF_HOST_OPT "--host=${GNU_HOST}") endif() -if(CMAKE_GENERATOR MATCHES "Ninja" AND NOT FLB_SYSTEM_WINDOWS) +# The $(MAKE) escape only exists in the Make-family generators; under Ninja +# the external autotools sub-builds always run with plain make on the build +# host, including when cross-compiling for a Windows target. +if(CMAKE_GENERATOR MATCHES "Ninja") set(EXTERNAL_BUILD_TOOL "make") else() set(EXTERNAL_BUILD_TOOL "$(MAKE)") @@ -1332,6 +1371,12 @@ if(FLB_REGEX) endif() add_subdirectory(${FLB_PATH_LIB_ONIGMO} EXCLUDE_FROM_ALL) target_include_directories(onigmo-static INTERFACE ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}) + if(CMAKE_CROSSCOMPILING AND WIN32) + # Onigmo's configure_file(config.h.cmake config.h) misdetects when cross + # compiling; overwrite it with the prebuilt Windows config it ships. + file(COPY ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}/win32/config.h + DESTINATION ${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}/) + endif() endif() # tutf8e (UTF8 Encoding) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 36fcc94ad12..c73dfe2b556 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -315,7 +315,9 @@ if (FLB_SYSTEM_WINDOWS) REGISTER_IN_PLUGIN("in_winstat") REGISTER_IN_PLUGIN("in_winevtlog") REGISTER_IN_PLUGIN("in_windows_exporter_metrics") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2") + if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2") + endif() else() REGISTER_IN_PLUGIN("in_serial") endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a47a5d9d658..b7c10923288 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,7 +137,9 @@ if(FLB_SYSTEM_WINDOWS) ${src} flb_dlfcn_win32.c ) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2") + if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2") + endif() endif() if(FLB_PARSER) @@ -288,10 +290,14 @@ check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4) # Core dependencies if(FLB_SYSTEM_WINDOWS) set(FLB_DEPS - "ws2_32.lib" - "crypt32.lib" - "Bcrypt.lib" - "Shlwapi.lib" + # Append: the upstream plain set() discards deps recorded earlier, e.g. + # onigmo-static (FLB_REGEX) whose INTERFACE include dir core needs. + ${FLB_DEPS} + "ws2_32" + "crypt32" + "bcrypt" + "shlwapi" + "shell32" ) else() set(FLB_DEPS @@ -553,6 +559,13 @@ add_library(fluent-bit-static STATIC ${src}) add_sanitizers(fluent-bit-static) target_link_libraries(fluent-bit-static ${FLB_DEPS}) +if(FLB_BACKTRACE) + # The stacktrace helpers are compiled into this library; declaring the + # dependency here keeps libbacktrace ordered after every occurrence of + # the archive on GNU ld link lines. + target_link_libraries(fluent-bit-static ${LIBBACKTRACE_LIBRARIES}) +endif() + if(MSVC) # Rename the output for Windows environment to avoid naming issues set_target_properties(fluent-bit-static PROPERTIES OUTPUT_NAME libfluent-bit) @@ -574,7 +587,12 @@ if(FLB_BINARY) endif() if (MSVC) set_target_properties(fluent-bit-bin PROPERTIES IMPORT_SUFFIX ".exe.lib") - endif(MSVC) + elseif (FLB_SYSTEM_WINDOWS) + # Same import-library name clash the MSVC branch above avoids, with the + # GNU naming: the executable's implib would otherwise collide with the + # shared library's libfluent-bit.dll.a. + set_target_properties(fluent-bit-bin PROPERTIES IMPORT_SUFFIX ".exe.a") + endif () add_sanitizers(fluent-bit-bin) if(FLB_STATIC_CONF) From 9282a0acccb611be6d27add80de367b38ef139cd Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:54 -0700 Subject: [PATCH 02/20] compat: support the MinGW UCRT toolchain in Windows headers MinGW-w64 UCRT headers already provide strcasecmp(), strncasecmp(), timezone, tzname, usleep() and, with _POSIX_THREAD_SAFE_FUNCTIONS set by the build system, the POSIX gmtime_r()/localtime_r() family, plus a real pthread implementation (winpthreads); redefining them or pulling in monkey's Windows pthread shim breaks compilation. Guard the MSVC replacement shims and route MinGW to , mapping only the BSD random()/srandom() pair the MinGW unistd.h lacks. Use GCC's __thread for the thread-local basename() buffer since MinGW GCC ignores __declspec(thread), add a PTHREAD_STACK_MIN fallback for the coroutine stack sizing, lowercase the wincrypt.h include for cross-builds from case-sensitive filesystems, and use the Windows gate instead of the MSVC one in flb_langinfo.h. Signed-off-by: Jiawei Huang --- include/fluent-bit/flb_compat.h | 64 ++++++++++++++----------- include/fluent-bit/flb_coro.h | 5 ++ include/fluent-bit/flb_langinfo.h | 2 +- include/fluent-bit/flb_pthread.h | 3 +- include/fluent-bit/flb_thread_pool.h | 3 +- include/fluent-bit/flb_thread_storage.h | 3 +- 6 files changed, 49 insertions(+), 31 deletions(-) diff --git a/include/fluent-bit/flb_compat.h b/include/fluent-bit/flb_compat.h index 4b481086cfb..af0bf71b73d 100644 --- a/include/fluent-bit/flb_compat.h +++ b/include/fluent-bit/flb_compat.h @@ -40,7 +40,7 @@ #define WIN32_LEAN_AND_MEAN #include #include -#include /* flb_io_tls.c */ +#include /* flb_io_tls.c */ #include #include @@ -56,16 +56,9 @@ /* monkey exposes a broken vsnprintf macro. Undo it */ #undef vsnprintf -/* - * Windows prefer to add an underscore to each POSIX function. - * To suppress compiler warnings, we need these trivial macros. - */ -#define timezone _timezone -#define tzname _tzname -#define strcasecmp _stricmp -#define strncasecmp _strnicmp #define timegm _mkgmtime + static inline int getpagesize(void) { SYSTEM_INFO info; @@ -73,6 +66,20 @@ static inline int getpagesize(void) return info.dwPageSize; } +static inline char* realpath(char *path, char *buf) +{ + if (buf != NULL) { + return NULL; /* Read BUGS in realpath(3) */ + } + return _fullpath(NULL, path, 0); +} + +#ifndef __MINGW32__ +#define timezone _timezone +#define tzname _tzname +#define strcasecmp _stricmp +#define strncasecmp _strnicmp + static inline struct tm *gmtime_r(const time_t *timep, struct tm *result) { if (gmtime_s(result, timep)) { @@ -90,10 +97,6 @@ static inline char *ctime_r(const time_t *timep, char *result) return strcpy(result, tmp); } -/* - * We can't just define localtime_r here, since mk_core/mk_utils.c is - * exposing a symbol with the same name inadvertently. - */ static struct tm *flb_localtime_r(time_t *timep, struct tm *result) { if (localtime_s(result, timep)) { @@ -103,13 +106,34 @@ static struct tm *flb_localtime_r(time_t *timep, struct tm *result) } #define localtime_r flb_localtime_r +static inline int usleep(LONGLONG usec) +{ + // Convert into 100ns unit. + return nanosleep(usec * 10); +} +#else /* __MINGW32__ */ +/* + * MinGW-w64 headers provide the POSIX functions replaced above, but the + * real unistd.h they ship has no BSD random()/srandom(); map them to + * rand()/srand() like monkey's unistd drop-in does for MSVC. + */ +#define random rand +#define srandom srand +#endif /* !__MINGW32__ */ + static inline char* basename(const char *path) { char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; +#ifdef _MSC_VER static __declspec(thread) char buf[_MAX_PATH]; +#else + /* MinGW GCC ignores __declspec(thread); use GCC's own TLS keyword so + * the buffer keeps the thread-safety the MSVC build has. */ + static __thread char buf[_MAX_PATH]; +#endif _splitpath_s(path, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); @@ -117,20 +141,6 @@ static inline char* basename(const char *path) _makepath_s(buf, _MAX_PATH, "", "", fname, ext); return buf; } - -static inline char* realpath(char *path, char *buf) -{ - if (buf != NULL) { - return NULL; /* Read BUGS in realpath(3) */ - } - return _fullpath(NULL, path, 0); -} - -static inline int usleep(LONGLONG usec) -{ - // Convert into 100ns unit. - return nanosleep(usec * 10); -} #else #include #include diff --git a/include/fluent-bit/flb_coro.h b/include/fluent-bit/flb_coro.h index 7f1111ea6ee..c7f42453f87 100644 --- a/include/fluent-bit/flb_coro.h +++ b/include/fluent-bit/flb_coro.h @@ -38,6 +38,11 @@ #include #include + +/* MinGW-w64's winpthreads does not define PTHREAD_STACK_MIN */ +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 16384 +#endif #include #ifdef FLB_HAVE_VALGRIND diff --git a/include/fluent-bit/flb_langinfo.h b/include/fluent-bit/flb_langinfo.h index eab63169ab7..0b49f0407d2 100644 --- a/include/fluent-bit/flb_langinfo.h +++ b/include/fluent-bit/flb_langinfo.h @@ -26,7 +26,7 @@ #ifndef FLB_LANGINFO_H #define FLB_LANGINFO_H -#ifndef _MSC_VER +#ifndef _WIN32 #include #else diff --git a/include/fluent-bit/flb_pthread.h b/include/fluent-bit/flb_pthread.h index 87774e1fd40..32c577f0025 100644 --- a/include/fluent-bit/flb_pthread.h +++ b/include/fluent-bit/flb_pthread.h @@ -21,9 +21,10 @@ #define FLB_PTHREAD_H #include -#ifdef FLB_SYSTEM_WINDOWS +#if defined(FLB_SYSTEM_WINDOWS) && !defined(__MINGW32__) #include #else +/* MinGW-w64 ships a real pthread implementation (winpthreads) */ #include #endif diff --git a/include/fluent-bit/flb_thread_pool.h b/include/fluent-bit/flb_thread_pool.h index a417d3183ab..401350d5a02 100644 --- a/include/fluent-bit/flb_thread_pool.h +++ b/include/fluent-bit/flb_thread_pool.h @@ -27,9 +27,10 @@ #define FLB_THREAD_POOL_STOPPED 2 #include -#ifdef FLB_SYSTEM_WINDOWS +#if defined(FLB_SYSTEM_WINDOWS) && !defined(__MINGW32__) #include #else +/* MinGW-w64 ships a real pthread implementation (winpthreads) */ #include #endif diff --git a/include/fluent-bit/flb_thread_storage.h b/include/fluent-bit/flb_thread_storage.h index 3360a69e97e..22038e73caa 100644 --- a/include/fluent-bit/flb_thread_storage.h +++ b/include/fluent-bit/flb_thread_storage.h @@ -22,9 +22,10 @@ #include -#ifdef FLB_SYSTEM_WINDOWS +#if defined(FLB_SYSTEM_WINDOWS) && !defined(__MINGW32__) #include #else +/* MinGW-w64 ships a real pthread implementation (winpthreads) */ #include #endif From ac0cd21f2a8ccdd25cf873277127120cf3ea7c6f Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:54 -0700 Subject: [PATCH 03/20] network: fix share_port arg in flb_net_server_unix fallback stub The header declares flb_net_server_unix() with four parameters, but the fallback stub compiled when FLB_HAVE_UNIX_SOCKET is not set still has the old three-parameter signature, so any platform taking that branch fails to compile with a conflicting declaration error. Signed-off-by: Jiawei Huang --- src/flb_network.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flb_network.c b/src/flb_network.c index 91a3e37a1d8..21b9db653bf 100644 --- a/src/flb_network.c +++ b/src/flb_network.c @@ -1851,7 +1851,8 @@ flb_sockfd_t flb_net_server_unix(const char *listen_path, #else flb_sockfd_t flb_net_server_unix(const char *listen_path, int stream_mode, - int backlog) + int backlog, + int share_port) { flb_error("Unix sockets are not available in this platform"); From 22be970801747da1466e2600f1360da01dcb3ea5 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:54 -0700 Subject: [PATCH 04/20] config_format: use Windows gates for MinGW cross-builds The glob(3) fallback and _fullpath() usage apply to any Windows toolchain, not just MSVC, so gate them on _WIN32 instead of _MSC_VER, and lowercase the windows.h include so it resolves against the lowercase MinGW SDK headers when cross-compiling from a case-sensitive filesystem. No behavior change for MSVC builds. Signed-off-by: Jiawei Huang --- src/config_format/flb_cf_fluentbit.c | 8 ++++---- src/config_format/flb_cf_yaml.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config_format/flb_cf_fluentbit.c b/src/config_format/flb_cf_fluentbit.c index 8f3ee566161..28199fefdbb 100644 --- a/src/config_format/flb_cf_fluentbit.c +++ b/src/config_format/flb_cf_fluentbit.c @@ -30,12 +30,12 @@ #include #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif #ifdef _WIN32 -#include +#include #include #define PATH_MAX MAX_PATH #endif @@ -280,7 +280,7 @@ static int local_init(struct local_ctx *ctx, char *file) char *p; if (file) { -#ifdef _MSC_VER +#ifdef _WIN32 p = _fullpath(path, file, PATH_MAX + 1); #else p = realpath(file, path); @@ -294,7 +294,7 @@ static int local_init(struct local_ctx *ctx, char *file) #endif /* lookup path ending and truncate */ -#ifdef _MSC_VER +#ifdef _WIN32 end = strrchr(path, '\\'); #else end = strrchr(path, '/'); diff --git a/src/config_format/flb_cf_yaml.c b/src/config_format/flb_cf_yaml.c index f05f2385d20..13eaea24e60 100644 --- a/src/config_format/flb_cf_yaml.c +++ b/src/config_format/flb_cf_yaml.c @@ -37,12 +37,12 @@ #include #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif #ifdef _WIN32 -#include +#include #include #define PATH_MAX MAX_PATH #endif From 4b5f1be8ce0f15a80e3f493795bbe681279d4078 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:55 -0700 Subject: [PATCH 05/20] wasm: cross-compile WAMR for Windows with the MinGW toolchain Make the bundled WAMR runtime build for a Windows target with a non-MSVC toolchain: - Select the WAMR platform port from the target system (CMAKE_SYSTEM_NAME) instead of the build host, so a Linux-hosted Windows cross-build uses the windows port rather than compiling the linux port against missing POSIX headers. - The MASM assembler (ASM_MASM) is MSVC-only, so enable it only for MSVC; MinGW and other Windows toolchains still build WASM, using the generic C native-call wrapper the ARM64 Windows build already uses. - Link pathcch and ntdll, which WAMR's Windows platform needs for PathCchCombine (win_file.c) and NtQueryTimerResolution (win_clock.c). MSVC pulls these in via #pragma comment(lib, ...), which GCC ignores; declare them on vmlib-static so CMake orders them after the archive on consumers' link lines. Signed-off-by: Jiawei Huang --- src/wasm/CMakeLists.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wasm/CMakeLists.txt b/src/wasm/CMakeLists.txt index 1f21022b046..54a47bf8b37 100644 --- a/src/wasm/CMakeLists.txt +++ b/src/wasm/CMakeLists.txt @@ -1,6 +1,15 @@ -string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +# Use the target system, not the build host, so cross-compiles pick the +# right WAMR platform port. +string (TOLOWER ${CMAKE_SYSTEM_NAME} WAMR_BUILD_PLATFORM) if (FLB_SYSTEM_WINDOWS) - enable_language(ASM_MASM) + if (MSVC) + enable_language(ASM_MASM) + else () + # ASM_MASM is the MSVC-only assembler; MinGW and other toolchains + # still build WASM, using the generic C native-call wrapper the + # ARM64 Windows build already uses. + set (WAMR_BUILD_INVOKE_NATIVE_GENERAL 1) + endif () endif() if (APPLE) add_definitions(-DBH_PLATFORM_DARWIN) @@ -137,6 +146,14 @@ set (WAMR_ROOT_DIR ../../${FLB_PATH_LIB_WASM_MICRO_RUNTIME}) # build out vmlib-static include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) add_library(vmlib-static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) +if (FLB_SYSTEM_WINDOWS AND NOT MSVC) + # WAMR's Windows platform calls PathCchCombine (win_file.c) and + # NtQueryTimerResolution (win_clock.c). MSVC links these via + # #pragma comment(lib, ...), which GCC ignores; declare them on the + # library that needs them so CMake orders them after vmlib-static on + # consumers' link lines (GNU ld resolves left to right). + target_link_libraries(vmlib-static PUBLIC pathcch ntdll) +endif () # Application related include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) From 6423c62126bf3096d863a5d5840cb1a5818a753a Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:38 -0700 Subject: [PATCH 06/20] bin: lowercase the consoleapi.h include for MinGW cross-builds GCC on a case-sensitive filesystem cannot resolve the capitalised ; MSVC is unaffected. Signed-off-by: Jiawei Huang --- src/fluent-bit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fluent-bit.c b/src/fluent-bit.c index 14e5f5682a4..fb5905c2f4e 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -654,7 +654,7 @@ static void flb_signal_handler(int signal) } #ifdef FLB_SYSTEM_WINDOWS -#include +#include static flb_ctx_t *handler_ctx = NULL; static struct flb_cf *handler_opts = NULL; From 3f479da1259e905ae4535c5b6e0de58accec168b Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 07/20] sosreport: gate Windows code on _WIN32 instead of _MSC_VER The blocks guard Windows-only functionality, not the MSVC compiler, so MinGW builds must take the same path. Signed-off-by: Jiawei Huang --- src/flb_sosreport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flb_sosreport.c b/src/flb_sosreport.c index deced8e9d38..2f93c4ccd25 100644 --- a/src/flb_sosreport.c +++ b/src/flb_sosreport.c @@ -28,7 +28,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif @@ -107,7 +107,7 @@ static void print_properties(struct mk_list *props) } } -#ifdef _MSC_VER +#ifdef _WIN32 /* A definition table of SYSTEM_INFO.wProcessorArchitecture. * * This is a streight-forward translation of the official manual. @@ -188,7 +188,7 @@ int flb_sosreport(struct flb_config *config) printf(" Built Flags\t\t%s\n", FLB_INFO_FLAGS); printf("\n"); -#ifndef _MSC_VER +#ifndef _WIN32 struct utsname uts; uname(&uts); From 6537346e609bf5bc8ff68495fd64a30304e44621 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 08/20] time: gate Windows code on _WIN32 instead of _MSC_VER The block guards Windows-only functionality, not the MSVC compiler. Signed-off-by: Jiawei Huang --- src/flb_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flb_time.c b/src/flb_time.c index 6a1c94e0287..6dce302037a 100644 --- a/src/flb_time.c +++ b/src/flb_time.c @@ -75,7 +75,7 @@ int flb_time_get(struct flb_time *tm) /* A portable function to sleep N msec */ int flb_time_msleep(uint32_t ms) { -#ifdef _MSC_VER +#ifdef _WIN32 Sleep((DWORD) ms); return 0; #else From 825fc43eff21421b9ba0d181a9783fb3682a92e4 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 09/20] tls: gate Windows code on _WIN32 instead of _MSC_VER The blocks guard Windows-only functionality, not the MSVC compiler. Signed-off-by: Jiawei Huang --- src/tls/openssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tls/openssl.c b/src/tls/openssl.c index 53e3574ea8a..8843563f7a8 100644 --- a/src/tls/openssl.c +++ b/src/tls/openssl.c @@ -455,7 +455,7 @@ static int tls_context_set_verify_client(void *ctx_backend, int verify_client) return 0; } -#ifdef _MSC_VER +#ifdef _WIN32 /* Parse certstore_name prefix like * * "My" -> no prefix, leave location untouched @@ -826,7 +826,7 @@ static int load_system_certificates(struct tls_context *ctx) (void) ca_file; /* For Windows use specific API to read the certs store */ -#ifdef _MSC_VER +#ifdef _WIN32 return windows_load_system_certificates(ctx); #elif defined(__APPLE__) return macos_load_system_certificates(ctx); From 0be0f350a7a51b58a02e6d2d1f90362da6d37eb5 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 10/20] win32: lowercase the windows.h/shlwapi.h includes for MinGW cross-builds Capitalised headers do not resolve on a case-sensitive filesystem under GCC; MSVC is unaffected. Signed-off-by: Jiawei Huang --- src/win32/winsvc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/win32/winsvc.c b/src/win32/winsvc.c index 9e0942ee5f7..b82f2780bac 100644 --- a/src/win32/winsvc.c +++ b/src/win32/winsvc.c @@ -17,8 +17,8 @@ * limitations under the License. */ -#include -#include +#include +#include struct flb_config; extern struct flb_config *config; From 4e69669faeba74d5fda75ac07fa293a754eb8a6e Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 11/20] filter_throttle_size: add the size parameter to create_throttle_size_table The prototype used empty parens; under C23 that means (void) and conflicts with the definition that takes a size_t. Signed-off-by: Jiawei Huang --- plugins/filter_throttle_size/size_window.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/filter_throttle_size/size_window.h b/plugins/filter_throttle_size/size_window.h index 50d4b901ec4..0bad8d029c8 100644 --- a/plugins/filter_throttle_size/size_window.h +++ b/plugins/filter_throttle_size/size_window.h @@ -47,7 +47,7 @@ struct throttle_size_table void *lock; }; -struct throttle_size_table *create_throttle_size_table(); +struct throttle_size_table *create_throttle_size_table(size_t size); struct throttle_size_window *size_window_create(const char *name, unsigned name_length, From 2c79ad047b292fd55af86889d004c9b2e0379993 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 12/20] in_calyptia_fleet: gate on _WIN32 and lowercase windows.h for MinGW The block guards Windows functionality, not MSVC; the capitalised header also fails to resolve under GCC. Signed-off-by: Jiawei Huang --- plugins/in_calyptia_fleet/in_calyptia_fleet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index ba9eb76aa95..644e75fb539 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -47,12 +47,12 @@ #include "in_calyptia_fleet.h" /* Glob support */ -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif #ifdef _WIN32 -#include +#include #include #define PATH_MAX MAX_PATH #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) From 04a15bdf737625cb87046299b8334404e11cff2f Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 13/20] in_prometheus_textfile: gate on _WIN32 and lowercase windows.h for MinGW The block guards Windows functionality, not MSVC; the capitalised header also fails to resolve under GCC. Signed-off-by: Jiawei Huang --- plugins/in_prometheus_textfile/prometheus_textfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/in_prometheus_textfile/prometheus_textfile.c b/plugins/in_prometheus_textfile/prometheus_textfile.c index ac26d52abf5..43fb7080b41 100644 --- a/plugins/in_prometheus_textfile/prometheus_textfile.c +++ b/plugins/in_prometheus_textfile/prometheus_textfile.c @@ -30,12 +30,12 @@ #include /* Glob support */ -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif #ifdef _WIN32 -#include +#include #include #define PATH_MAX MAX_PATH #endif From 52e3a1cb0855c8e044fe0ffe926b4700fb7760ed Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 14/20] in_syslog: guard S_ISSOCK, which MinGW's headers do not define Only test the socket type when the platform provides the macro. Signed-off-by: Jiawei Huang --- plugins/in_syslog/syslog_server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/in_syslog/syslog_server.c b/plugins/in_syslog/syslog_server.c index 5ccdecd71d1..eb2bbf83431 100644 --- a/plugins/in_syslog/syslog_server.c +++ b/plugins/in_syslog/syslog_server.c @@ -53,9 +53,11 @@ static int remove_existing_socket_file(char *socket_path) return -1; } +#ifdef S_ISSOCK if (S_ISSOCK(file_data.st_mode) == 0) { return -2; } +#endif result = unlink(socket_path); From c5e2958d8d1a1d830909be85008d4b99262f1cdc Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 15/20] in_tail: use a WIN32 gate and lowercase shlwapi for MinGW Widen the MSVC-only CMake gate to WIN32, link shlwapi by its lowercase name, and lowercase the windows.h includes in the win32 helpers. Signed-off-by: Jiawei Huang --- plugins/in_tail/CMakeLists.txt | 4 ++-- plugins/in_tail/win32/io.c | 2 +- plugins/in_tail/win32/stat.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/in_tail/CMakeLists.txt b/plugins/in_tail/CMakeLists.txt index 31d865218d5..fd68aa0cd07 100644 --- a/plugins/in_tail/CMakeLists.txt +++ b/plugins/in_tail/CMakeLists.txt @@ -25,13 +25,13 @@ if(FLB_PARSER) ) endif() -if(MSVC) +if(WIN32) set(src ${src} win32/stat.c win32/io.c ) - FLB_PLUGIN(in_tail "${src}" "Shlwapi") + FLB_PLUGIN(in_tail "${src}" "shlwapi") else() FLB_PLUGIN(in_tail "${src}" "") endif() diff --git a/plugins/in_tail/win32/io.c b/plugins/in_tail/win32/io.c index 5315e28c061..358d26742a0 100644 --- a/plugins/in_tail/win32/io.c +++ b/plugins/in_tail/win32/io.c @@ -17,7 +17,7 @@ * limitations under the License. */ -#include +#include #include #include #include diff --git a/plugins/in_tail/win32/stat.c b/plugins/in_tail/win32/stat.c index ce6b9ffd457..4a2b83e5779 100644 --- a/plugins/in_tail/win32/stat.c +++ b/plugins/in_tail/win32/stat.c @@ -17,7 +17,7 @@ * limitations under the License. */ -#include +#include #include #include #include From 78e19f03294165786b2aae16cf137a66b17e8785 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 16/20] in_windows_exporter_metrics: fix includes and declarations for the MinGW build Add the missing math.h and we_util.h/we_perflib.h includes and adjust the headers so the plugin compiles with GCC. Signed-off-by: Jiawei Huang --- plugins/in_windows_exporter_metrics/we.c | 2 + plugins/in_windows_exporter_metrics/we_cpu.c | 1 + .../in_windows_exporter_metrics/we_metric.h | 198 +++++++++--------- .../in_windows_exporter_metrics/we_perflib.h | 3 +- plugins/in_windows_exporter_metrics/we_wmi.h | 2 + .../we_wmi_process.h | 4 + 6 files changed, 110 insertions(+), 100 deletions(-) diff --git a/plugins/in_windows_exporter_metrics/we.c b/plugins/in_windows_exporter_metrics/we.c index 7cfbd38f5f6..cec0d50b878 100644 --- a/plugins/in_windows_exporter_metrics/we.c +++ b/plugins/in_windows_exporter_metrics/we.c @@ -27,6 +27,8 @@ #include "we.h" #include "we_wmi.h" #include "we_config.h" +#include "we_util.h" +#include "we_perflib.h" /* collectors */ #include "we_cpu.h" diff --git a/plugins/in_windows_exporter_metrics/we_cpu.c b/plugins/in_windows_exporter_metrics/we_cpu.c index 6247e0d8244..6381b9f8d09 100644 --- a/plugins/in_windows_exporter_metrics/we_cpu.c +++ b/plugins/in_windows_exporter_metrics/we_cpu.c @@ -18,6 +18,7 @@ * limitations under the License. */ +#include #include #include #include diff --git a/plugins/in_windows_exporter_metrics/we_metric.h b/plugins/in_windows_exporter_metrics/we_metric.h index 11315143f01..9aa4c4e9405 100644 --- a/plugins/in_windows_exporter_metrics/we_metric.h +++ b/plugins/in_windows_exporter_metrics/we_metric.h @@ -1,99 +1,99 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* Fluent Bit - * ========== - * Copyright (C) 2019-2021 The Fluent Bit Authors - * Copyright (C) 2015-2018 Treasure Data Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FLB_METRIC_H -#define FLB_METRIC_H - -#include -#include -#include -#include - -struct we_perflib_metric_spec { - int type; - char *name; - char *description; - char *raw_label_set; - char **label_set; - size_t label_set_size; - void *metric_instance; -}; - -struct we_perflib_metric_source { - struct we_perflib_metric_spec *parent; - char *parent_name; - char *name; - char *raw_label_set; - char **label_set; - size_t label_set_size; - int use_secondary_value; -}; - -#define WE_PERFLIB_SPEC(type_, name_, description_, raw_label_set_) \ - { \ - .type = type_, \ - .name = name_, \ - .description = description_, \ - .raw_label_set = raw_label_set_, \ - .label_set = NULL, \ - .label_set_size = 0, \ - .metric_instance = NULL \ - } - -#define WE_PERFLIB_COUNTER_SPEC(name_, description_, raw_label_set_) \ - WE_PERFLIB_SPEC(CMT_COUNTER, name_, description_, raw_label_set_) - -#define WE_PERFLIB_GAUGE_SPEC(name_, description_, raw_label_set_) \ - WE_PERFLIB_SPEC(CMT_GAUGE, name_, description_, raw_label_set_) - -#define WE_PERFLIB_TERMINATOR_SPEC() \ - WE_PERFLIB_SPEC(0, NULL, NULL, NULL) - -#define WE_PERFLIB_METRIC_SOURCE(parent_name_, name_, raw_label_set_) \ - { \ - .parent = NULL, \ - .parent_name = parent_name_, \ - .name = name_, \ - .raw_label_set = raw_label_set_, \ - .label_set = NULL, \ - .label_set_size = 0 \ - } - -#define WE_PERFLIB_TERMINATOR_SOURCE() \ - WE_PERFLIB_METRIC_SOURCE(NULL, NULL, NULL) - - -void we_deinitialize_perflib_metric_sources(struct we_perflib_metric_source *sources); -int we_initialize_perflib_metric_sources( - struct flb_hash *lookup_table, - struct we_perflib_metric_source **out_sources, - struct we_perflib_metric_source *in_sources); - - -void we_deinitialize_perflib_metric_specs(struct we_perflib_metric_spec *specs); -int we_initialize_perflib_metric_specs( - struct cmt *context, - struct flb_hash *lookup_table, - char *namespace, - char *subsystem, - struct we_perflib_metric_spec **out_specs, - struct we_perflib_metric_spec *in_specs); - -#endif +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2019-2021 The Fluent Bit Authors + * Copyright (C) 2015-2018 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLB_METRIC_H +#define FLB_METRIC_H + +#include +#include +#include +#include + +struct we_perflib_metric_spec { + int type; + char *name; + char *description; + char *raw_label_set; + char **label_set; + size_t label_set_size; + void *metric_instance; +}; + +struct we_perflib_metric_source { + struct we_perflib_metric_spec *parent; + char *parent_name; + char *name; + char *raw_label_set; + char **label_set; + size_t label_set_size; + int use_secondary_value; +}; + +#define WE_PERFLIB_SPEC(type_, name_, description_, raw_label_set_) \ + { \ + .type = type_, \ + .name = name_, \ + .description = description_, \ + .raw_label_set = raw_label_set_, \ + .label_set = NULL, \ + .label_set_size = 0, \ + .metric_instance = NULL \ + } + +#define WE_PERFLIB_COUNTER_SPEC(name_, description_, raw_label_set_) \ + WE_PERFLIB_SPEC(CMT_COUNTER, name_, description_, raw_label_set_) + +#define WE_PERFLIB_GAUGE_SPEC(name_, description_, raw_label_set_) \ + WE_PERFLIB_SPEC(CMT_GAUGE, name_, description_, raw_label_set_) + +#define WE_PERFLIB_TERMINATOR_SPEC() \ + WE_PERFLIB_SPEC(0, NULL, NULL, NULL) + +#define WE_PERFLIB_METRIC_SOURCE(parent_name_, name_, raw_label_set_) \ + { \ + .parent = NULL, \ + .parent_name = parent_name_, \ + .name = name_, \ + .raw_label_set = raw_label_set_, \ + .label_set = NULL, \ + .label_set_size = 0 \ + } + +#define WE_PERFLIB_TERMINATOR_SOURCE() \ + WE_PERFLIB_METRIC_SOURCE(NULL, NULL, NULL) + + +void we_deinitialize_perflib_metric_sources(struct we_perflib_metric_source *sources); +int we_initialize_perflib_metric_sources( + struct flb_hash_table *lookup_table, + struct we_perflib_metric_source **out_sources, + struct we_perflib_metric_source *in_sources); + + +void we_deinitialize_perflib_metric_specs(struct we_perflib_metric_spec *specs); +int we_initialize_perflib_metric_specs( + struct cmt *context, + struct flb_hash_table *lookup_table, + char *namespace, + char *subsystem, + struct we_perflib_metric_spec **out_specs, + struct we_perflib_metric_spec *in_specs); + +#endif diff --git a/plugins/in_windows_exporter_metrics/we_perflib.h b/plugins/in_windows_exporter_metrics/we_perflib.h index 46059bb8df7..c846c9f2717 100644 --- a/plugins/in_windows_exporter_metrics/we_perflib.h +++ b/plugins/in_windows_exporter_metrics/we_perflib.h @@ -67,6 +67,7 @@ int we_perflib_update_counters(struct flb_we *ctx, we_perflib_instance_filter filter_hook, we_perflib_label_prepend_hook label_prepend_hook); -double we_perflib_get_adjusted_counter_value(struct we_perflib_counter *counter); +double we_perflib_get_adjusted_counter_value(struct we_perflib_counter *counter, + struct we_perflib_metric_source *source); #endif \ No newline at end of file diff --git a/plugins/in_windows_exporter_metrics/we_wmi.h b/plugins/in_windows_exporter_metrics/we_wmi.h index 2999f57648f..af38349f7f8 100644 --- a/plugins/in_windows_exporter_metrics/we_wmi.h +++ b/plugins/in_windows_exporter_metrics/we_wmi.h @@ -42,6 +42,8 @@ int we_wmi_cleanup(struct flb_we *ctx); int we_wmi_exit(struct flb_we *ctx); /* Abstract APIs */ +struct wmi_query_specs; + int we_wmi_query(struct flb_we *ctx, struct wmi_query_specs *spec); int we_wmi_query_fixed_val(struct flb_we *ctx, struct wmi_query_specs *spec); int we_wmi_query_namespace(struct flb_we *ctx, struct wmi_query_specs *spec, char *namepsace); diff --git a/plugins/in_windows_exporter_metrics/we_wmi_process.h b/plugins/in_windows_exporter_metrics/we_wmi_process.h index c55e577c2ae..1155f63245c 100644 --- a/plugins/in_windows_exporter_metrics/we_wmi_process.h +++ b/plugins/in_windows_exporter_metrics/we_wmi_process.h @@ -26,4 +26,8 @@ int we_wmi_process_info_init(struct flb_we *ctx); int we_wmi_process_info_exit(struct flb_we *ctx); int we_wmi_process_info_update(struct flb_we *ctx); +int we_wmi_process_init(struct flb_we *ctx); +int we_wmi_process_exit(struct flb_we *ctx); +int we_wmi_process_update(struct flb_we *ctx); + #endif From c379f0ec11801b48a40aa0ef365f87b4e6145b0f Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Tue, 7 Jul 2026 23:16:39 -0700 Subject: [PATCH 17/20] out_file: lowercase the shlobj.h/shlwapi.h includes for MinGW Capitalised headers do not resolve on a case-sensitive filesystem under GCC; MSVC is unaffected. Signed-off-by: Jiawei Huang --- plugins/out_file/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/out_file/file.c b/plugins/out_file/file.c index 89a2e0176af..fe049d59410 100644 --- a/plugins/out_file/file.c +++ b/plugins/out_file/file.c @@ -35,8 +35,8 @@ #include #ifdef FLB_SYSTEM_WINDOWS -#include -#include +#include +#include #endif #include "file.h" From 4880080a231e47d9afc9ec093a0685b13268162e Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:55 -0700 Subject: [PATCH 18/20] lib: carry upstream-bound MinGW cross-build fixes for vendored libraries Make the vendored libraries build and run with the MinGW-w64 UCRT toolchain. Each change belongs in the library's own upstream and has been submitted there -- monkey, chunkio and cmetrics via the fluent org, flb_libco via edsiper/flb_libco, and WAMR via bytecodealliance -- so these hunks are carried here only until those merge and are re-vendored. Two other vendored libraries needed no source change and are intentionally not touched: nghttp2 (its inline byte-order fallback compiles as-is; the consumers that include it do not pull in winsock2) and snappy (its MSVC intrinsic path builds under MinGW). Onigmo's cross-compile config is handled in the fluent-bit build files, not by patching its tree. - monkey: select the POSIX threading model for MinGW (winpthreads is a real pthread implementation; the hand-rolled shim stays MSVC-only), guard the MSVC-only typedefs and shims MinGW already provides, widen MSVC-only gates covering Windows functionality to _WIN32, use the standard GCC container_of, lowercase Windows header includes, and for the vendored libevent record the winsock dependency on the static archives; for MinGW only, pin NTDDI_VERSION next to the existing _WIN32_WINNT override in evutil.c (its sdkddkver.h errors when the two disagree, where MSVC does not, so MSVC compiles the file unchanged) and define EVENT__HAVE_STRTOK_R (libevent's WIN32 function check takes the function's address and only sees the force-included winsock headers, so it mis-detects strtok_r from and then defines a conflicting static copy). - chunkio: guard the ssize_t/mode_t typedefs MinGW provides, widen the fts.h gate to _WIN32, lowercase Windows header includes, and link shell32 by its lowercase name. - cmetrics: define YY_NO_UNISTD_H only for MSVC, since MinGW has a real unistd.h the generated lexer needs for isatty(). - flb_libco: select the fiber backend on Windows before the arch check, matching the MSVC branch that avoids amd64.c due to its SIGSEGV bug (its co_swap machine-code blob faults under DEP). Applied to both the top-level lib/flb_libco copy and monkey's vendored deps/flb_libco copy, since the HTTP server build compiles the latter. - wasm-micro-runtime: lowercase the pathcch.h include and reword the // comments in win_file.c that end in a backslash; GCC treats a backslash-newline as a line continuation even inside a // comment and swallows the following line of code, while MSVC does not. Signed-off-by: Jiawei Huang --- lib/chunkio/include/chunkio/chunkio_compat.h | 2 ++ lib/chunkio/src/CMakeLists.txt | 2 +- lib/chunkio/src/cio_os.c | 2 +- lib/chunkio/src/cio_utils.c | 4 ++-- lib/chunkio/src/win32/dirent.c | 2 +- lib/cmetrics/CMakeLists.txt | 9 ++++++--- lib/flb_libco/libco.c | 14 +++++++++++--- lib/monkey/deps/flb_libco/libco.c | 14 +++++++++++--- lib/monkey/include/monkey/mk_config.h | 2 ++ .../include/monkey/mk_core/external/winuio.h | 2 +- .../include/monkey/mk_core/mk_dep_unistd.h | 2 +- lib/monkey/include/monkey/mk_core/mk_list.h | 4 ++-- lib/monkey/include/monkey/mk_core/mk_macros.h | 2 +- lib/monkey/include/monkey/mk_core/mk_sleep.h | 2 ++ lib/monkey/include/monkey/mk_scheduler.h | 2 ++ lib/monkey/include/monkey/mk_thread_libco.h | 12 ++++++++++++ lib/monkey/mk_core/CMakeLists.txt | 16 +++++++++++----- lib/monkey/mk_core/deps/libevent/CMakeLists.txt | 17 ++++++++++++++++- lib/monkey/mk_core/deps/libevent/evutil.c | 7 +++++++ lib/monkey/mk_core/mk_rconf.c | 6 +++--- lib/monkey/mk_core/mk_utils.c | 2 ++ .../core/shared/platform/windows/win_file.c | 8 ++++---- 22 files changed, 101 insertions(+), 32 deletions(-) diff --git a/lib/chunkio/include/chunkio/chunkio_compat.h b/lib/chunkio/include/chunkio/chunkio_compat.h index 3e4951b988d..ef125bf0576 100644 --- a/lib/chunkio/include/chunkio/chunkio_compat.h +++ b/lib/chunkio/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/lib/chunkio/src/CMakeLists.txt b/lib/chunkio/src/CMakeLists.txt index 3590143fd05..86d102e1f70 100644 --- a/lib/chunkio/src/CMakeLists.txt +++ b/lib/chunkio/src/CMakeLists.txt @@ -23,7 +23,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ) set(libs ${libs} - Shell32.lib) + shell32) else() set(src ${src} diff --git a/lib/chunkio/src/cio_os.c b/lib/chunkio/src/cio_os.c index 637b74e4bee..ddbf93a0962 100644 --- a/lib/chunkio/src/cio_os.c +++ b/lib/chunkio/src/cio_os.c @@ -28,7 +28,7 @@ #include #ifdef _WIN32 -#include +#include #endif /* Check if a path is a directory */ diff --git a/lib/chunkio/src/cio_utils.c b/lib/chunkio/src/cio_utils.c index 45cb0ae885e..3be13bead29 100644 --- a/lib/chunkio/src/cio_utils.c +++ b/lib/chunkio/src/cio_utils.c @@ -25,7 +25,7 @@ #include #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif @@ -34,7 +34,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 /* * Taken from StackOverflow: * diff --git a/lib/chunkio/src/win32/dirent.c b/lib/chunkio/src/win32/dirent.c index 020943d0eac..48491f2e06d 100644 --- a/lib/chunkio/src/win32/dirent.c +++ b/lib/chunkio/src/win32/dirent.c @@ -22,7 +22,7 @@ * Win32's FIndFirstFile/FindNextFile API. */ -#include +#include #include "dirent.h" diff --git a/lib/cmetrics/CMakeLists.txt b/lib/cmetrics/CMakeLists.txt index d7da71a795b..9055bc231c6 100644 --- a/lib/cmetrics/CMakeLists.txt +++ b/lib/cmetrics/CMakeLists.txt @@ -45,9 +45,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows") set(CMT_SYSTEM_WINDOWS On) add_definitions(-DCMT_SYSTEM_WINDOWS) - # Disable unistd.h for flex/bison - CMT_DEFINITION(YY_NO_UNISTD_H) - message(STATUS "Specifying YY_NO_UNISTD_H") + # Disable unistd.h for flex/bison on MSVC only: MinGW provides a real + # unistd.h, and without it the generated lexer has no isatty declaration. + if(MSVC) + CMT_DEFINITION(YY_NO_UNISTD_H) + message(STATUS "Specifying YY_NO_UNISTD_H") + endif() endif() # Define macro to identify macOS system diff --git a/lib/flb_libco/libco.c b/lib/flb_libco/libco.c index a66b5b3119c..560d2b91a68 100644 --- a/lib/flb_libco/libco.c +++ b/lib/flb_libco/libco.c @@ -8,7 +8,17 @@ #endif #if defined(__clang__) || defined(__GNUC__) - #if defined(__i386__) + #if defined(_WIN32) + /* + * Check Windows before the architecture: on x86_64 MinGW both __amd64__ + * and _WIN32 are defined, so amd64.c would win, but its co_swap executes + * a machine-code blob held in a read-only array and faults under DEP on + * the first coroutine switch (the same reason the MSVC branch below + * disables amd64.c "due to SIGSEGV bug"). Use the fiber backend, which is + * what MSVC already selects on Windows. + */ + #include "fiber.c" + #elif defined(__i386__) #include "x86.c" #elif defined(__amd64__) #include "amd64.c" @@ -20,8 +30,6 @@ #include "ppc64le.c" #elif defined(_ARCH_PPC) && !defined(__LITTLE_ENDIAN__) #include "ppc.c" - #elif defined(_WIN32) - #include "fiber.c" #else #include "sjlj.c" #endif diff --git a/lib/monkey/deps/flb_libco/libco.c b/lib/monkey/deps/flb_libco/libco.c index e0101d23872..854ebd09eea 100644 --- a/lib/monkey/deps/flb_libco/libco.c +++ b/lib/monkey/deps/flb_libco/libco.c @@ -8,7 +8,17 @@ #endif #if defined(__clang__) || defined(__GNUC__) - #if defined(__i386__) + #if defined(_WIN32) + /* + * Check Windows before the architecture: on x86_64 MinGW both __amd64__ + * and _WIN32 are defined, so amd64.c would win, but its co_swap executes + * a machine-code blob held in a read-only array and faults under DEP on + * the first coroutine switch (the same reason the MSVC branch below + * disables amd64.c "due to SIGSEGV bug"). Use the fiber backend, which is + * what MSVC already selects on Windows. + */ + #include "fiber.c" + #elif defined(__i386__) #include "x86.c" #elif defined(__amd64__) #include "amd64.c" @@ -18,8 +28,6 @@ #include "aarch64.c" #elif defined(_ARCH_PPC) #include "ppc.c" - #elif defined(_WIN32) - #include "fiber.c" #else #include "sjlj.c" #endif diff --git a/lib/monkey/include/monkey/mk_config.h b/lib/monkey/include/monkey/mk_config.h index f6552815347..8f5f041c946 100644 --- a/lib/monkey/include/monkey/mk_config.h +++ b/lib/monkey/include/monkey/mk_config.h @@ -27,7 +27,9 @@ #include "../../deps/rbtree/rbtree.h" #ifdef _WIN32 +#ifndef __MINGW32__ typedef uint32_t mode_t; +#endif typedef uint32_t uid_t; typedef uint32_t gid_t; #endif diff --git a/lib/monkey/include/monkey/mk_core/external/winuio.h b/lib/monkey/include/monkey/mk_core/external/winuio.h index f49349c42da..03f17a9e2f7 100644 --- a/lib/monkey/include/monkey/mk_core/external/winuio.h +++ b/lib/monkey/include/monkey/mk_core/external/winuio.h @@ -8,7 +8,7 @@ #else #include #include -#include +#include #include #include typedef SSIZE_T ssize_t; diff --git a/lib/monkey/include/monkey/mk_core/mk_dep_unistd.h b/lib/monkey/include/monkey/mk_core/mk_dep_unistd.h index 448a93c0995..638856283b7 100644 --- a/lib/monkey/include/monkey/mk_core/mk_dep_unistd.h +++ b/lib/monkey/include/monkey/mk_core/mk_dep_unistd.h @@ -44,7 +44,7 @@ #define STDOUT_FILENO 1 #define STDERR_FILENO 2 /* should be in some equivalent to */ -#if _MSC_VER >= 1600 /* MSVC 2010 or higher */ +#if defined(__MINGW32__) || _MSC_VER >= 1600 /* MSVC 2010 or higher */ #include #else typedef __int8 int8_t; diff --git a/lib/monkey/include/monkey/mk_core/mk_list.h b/lib/monkey/include/monkey/mk_core/mk_list.h index 0a87381a8cd..5c697a4d3fd 100644 --- a/lib/monkey/include/monkey/mk_core/mk_list.h +++ b/lib/monkey/include/monkey/mk_core/mk_list.h @@ -24,8 +24,8 @@ #include #include "mk_macros.h" -#ifdef _WIN32 -/* Windows */ +#if defined(_WIN32) && !defined(__MINGW32__) +/* Windows (MSVC): PCHAR/ULONG_PTR come from the Windows SDK headers */ #define container_of(address, type, field) ((type *)( \ (PCHAR)(address) - \ (ULONG_PTR)(&((type *)0)->field))) diff --git a/lib/monkey/include/monkey/mk_core/mk_macros.h b/lib/monkey/include/monkey/mk_core/mk_macros.h index f5179faa139..3940f9126ae 100644 --- a/lib/monkey/include/monkey/mk_core/mk_macros.h +++ b/lib/monkey/include/monkey/mk_core/mk_macros.h @@ -166,7 +166,7 @@ #define MK_EXPORT __declspec(dllexport) #endif -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define MK_INLINE __forceinline #else #define MK_INLINE inline __attribute__((always_inline)) diff --git a/lib/monkey/include/monkey/mk_core/mk_sleep.h b/lib/monkey/include/monkey/mk_core/mk_sleep.h index 44f4d5aa626..b9fe2de16c2 100644 --- a/lib/monkey/include/monkey/mk_core/mk_sleep.h +++ b/lib/monkey/include/monkey/mk_core/mk_sleep.h @@ -34,6 +34,7 @@ #include /* WinAPI */ /* Windows sleep in 100ns units */ +#ifndef __MINGW32__ static inline BOOLEAN nanosleep(LONGLONG ns){ /* Declarations */ HANDLE timer; /* Timer handle */ @@ -55,5 +56,6 @@ static inline BOOLEAN nanosleep(LONGLONG ns){ return TRUE; } #endif +#endif #endif diff --git a/lib/monkey/include/monkey/mk_scheduler.h b/lib/monkey/include/monkey/mk_scheduler.h index f749cba5420..5b5ff1113cb 100644 --- a/lib/monkey/include/monkey/mk_scheduler.h +++ b/lib/monkey/include/monkey/mk_scheduler.h @@ -38,11 +38,13 @@ #define MK_SCHED_SIGNAL_EVENT_LOOP_BREAK 0xEEFFAACC #ifdef _WIN32 +#ifndef __MINGW32__ /* The pid field in the mk_sched_worker structure is ignored in platforms other than * linux and mac os so it can be safely plugged in this meaningless way */ typedef uint64_t pid_t; #endif +#endif /* * Scheduler balancing mode: diff --git a/lib/monkey/include/monkey/mk_thread_libco.h b/lib/monkey/include/monkey/mk_thread_libco.h index 28c320fc5bf..4cc40499546 100644 --- a/lib/monkey/include/monkey/mk_thread_libco.h +++ b/lib/monkey/include/monkey/mk_thread_libco.h @@ -26,6 +26,18 @@ #include +/* + * MinGW-w64's winpthreads, unlike glibc, does not define PTHREAD_STACK_MIN. + * MinGW uses the POSIX threading model (the real ), so provide it + * here or MK_THREAD_STACK_SIZE below will not compile; 16384 is the glibc + * x86-64 minimum, matching the value the other POSIX platforms build with. + * MSVC is unaffected: its winpthreads shim (pulled in via mk_pthread.h before + * this header) already defines PTHREAD_STACK_MIN, so this guard is a no-op. + */ +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 16384 +#endif + #ifdef MK_HAVE_VALGRIND #include #endif diff --git a/lib/monkey/mk_core/CMakeLists.txt b/lib/monkey/mk_core/CMakeLists.txt index a1a32101783..9ff364c28e4 100644 --- a/lib/monkey/mk_core/CMakeLists.txt +++ b/lib/monkey/mk_core/CMakeLists.txt @@ -20,11 +20,17 @@ endmacro() # Set threading system if (CMAKE_SYSTEM_NAME MATCHES "Windows") - MK_DEFINITION(MK_THREADS_WIN32) - set(src - ${src} - "external/winpthreads.c" - ) + if (MSVC) + MK_DEFINITION(MK_THREADS_WIN32) + set(src + ${src} + "external/winpthreads.c" + ) + else() + # MinGW-w64 ships a real pthread implementation (winpthreads), so the + # POSIX threading model applies; the hand-rolled shim is MSVC-only. + MK_DEFINITION(MK_THREADS_POSIX) + endif() add_subdirectory(deps/) else() if (MK_EVENT_LOOP_LIBEVENT) diff --git a/lib/monkey/mk_core/deps/libevent/CMakeLists.txt b/lib/monkey/mk_core/deps/libevent/CMakeLists.txt index 7a839decf14..7a63c7a2fb0 100644 --- a/lib/monkey/mk_core/deps/libevent/CMakeLists.txt +++ b/lib/monkey/mk_core/deps/libevent/CMakeLists.txt @@ -435,7 +435,7 @@ CHECK_TYPE_SIZE("off_t" EVENT__SIZEOF_OFF_T LANGUAGE C) # Winssck. if (_MSC_VER) - list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h) + list(APPEND CMAKE_EXTRA_INCLUDE_FILES basetsd.h) endif() CHECK_TYPE_SIZE("ssize_t" EVENT__SIZEOF_SSIZE_T_LOWER LANGUAGE C) CHECK_TYPE_SIZE("SSIZE_T" EVENT__SIZEOF_SSIZE_T_UPPER LANGUAGE C) @@ -786,6 +786,13 @@ else (EVENT__BUILD_SHARED_LIBRARIES) set(EVENT__LIBRARY_TYPE STATIC) endif (EVENT__BUILD_SHARED_LIBRARIES) +if(MINGW) + # MinGW-w64 declares strtok_r in , but libevent's WIN32 function + # check (CheckFunctionExistsEx.c takes the function's address) only sees the + # force-included winsock headers, so it mis-detects strtok_r as absent and + # then defines a conflicting static strtok_r in evdns.c. Set it explicitly. + set(EVENT__HAVE_STRTOK_R 1) +endif() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/event-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/event2/event-config.h @@ -823,6 +830,14 @@ add_library(event ${EVENT__LIBRARY_TYPE} ${SRC_CORE} ${SRC_EXTRA}) +if(WIN32) + # Record the winsock dependency on the static archives too, so + # consumers order -lws2_32 after them (GNU ld resolves left to right). + target_link_libraries(event_core ${LIB_PLATFORM}) + target_link_libraries(event_extra ${LIB_PLATFORM}) + target_link_libraries(event ${LIB_PLATFORM}) +endif() + if (EVENT__BUILD_SHARED_LIBRARIES) # Prepare static library to be linked to tests that need hidden symbols add_library(event_extra_static STATIC diff --git a/lib/monkey/mk_core/deps/libevent/evutil.c b/lib/monkey/mk_core/deps/libevent/evutil.c index 1e8ef7bd328..463baf8fd86 100644 --- a/lib/monkey/mk_core/deps/libevent/evutil.c +++ b/lib/monkey/mk_core/deps/libevent/evutil.c @@ -39,6 +39,13 @@ #undef _WIN32_WINNT /* For structs needed by GetAdaptersAddresses */ #define _WIN32_WINNT 0x0501 +#ifdef __MINGW32__ +/* MinGW-w64's sdkddkver.h rejects a _WIN32_WINNT that disagrees with + * NTDDI_VERSION; pin NTDDI to the same level. MSVC does not enforce this + * and is left unchanged. */ +#undef NTDDI_VERSION +#define NTDDI_VERSION 0x05010000 +#endif #include #endif diff --git a/lib/monkey/mk_core/mk_rconf.c b/lib/monkey/mk_core/mk_rconf.c index bf169d0e804..ab8218c6c52 100644 --- a/lib/monkey/mk_core/mk_rconf.c +++ b/lib/monkey/mk_core/mk_rconf.c @@ -23,7 +23,7 @@ #include #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif @@ -33,7 +33,7 @@ #include #ifdef _WIN32 -#include +#include #include #define PATH_MAX MAX_PATH #endif @@ -604,7 +604,7 @@ static int mk_rconf_path_set(struct mk_rconf *conf, char *file) char *end; char path[PATH_MAX + 1]; -#ifdef _MSC_VER +#ifdef _WIN32 p = _fullpath(path, file, PATH_MAX + 1); #else p = realpath(file, path); diff --git a/lib/monkey/mk_core/mk_utils.c b/lib/monkey/mk_core/mk_utils.c index 54cdd39388d..3b4a942fa38 100644 --- a/lib/monkey/mk_core/mk_utils.c +++ b/lib/monkey/mk_core/mk_utils.c @@ -37,6 +37,7 @@ #elif defined (_WIN32) #include +#ifndef __MINGW32__ #ifndef localtime_r struct tm *localtime_r(time_t *_clock, struct tm *_result) { @@ -70,6 +71,7 @@ return 0; } +#endif /* !__MINGW32__ */ #endif diff --git a/lib/wasm-micro-runtime-WAMR-2.4.1/core/shared/platform/windows/win_file.c b/lib/wasm-micro-runtime-WAMR-2.4.1/core/shared/platform/windows/win_file.c index 55ea77ac76e..019e62f6adc 100644 --- a/lib/wasm-micro-runtime-WAMR-2.4.1/core/shared/platform/windows/win_file.c +++ b/lib/wasm-micro-runtime-WAMR-2.4.1/core/shared/platform/windows/win_file.c @@ -7,7 +7,7 @@ #include "libc_errno.h" #include "win_util.h" -#include "PathCch.h" +#include "pathcch.h" #pragma comment(lib, "Pathcch.lib") @@ -1295,13 +1295,13 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf, if (wbufsize >= 4 && wbuf[0] == L'\\' && wbuf[1] == L'?' && wbuf[2] == L'?' && wbuf[3] == L'\\') { - // Starts with \??\ + // Starts with \??\ prefix if (wbufsize >= 6 && ((wbuf[4] >= L'A' && wbuf[4] <= L'Z') || (wbuf[4] >= L'a' && wbuf[4] <= L'z')) && wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\')) { - // \??\:\ + // \??\:\ form wbuf += 4; wbufsize -= 4; } @@ -1310,7 +1310,7 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf, && (wbuf[6] == L'C' || wbuf[6] == L'c') && wbuf[7] == L'\\') { - // \??\UNC\\\ - make sure the final path looks like \\\\ + // \??\UNC\\\ - make sure the final path looks like \\\\ afterwards wbuf += 6; wbuf[0] = L'\\'; wbufsize -= 6; From 1cd43cb29545ebfa2ba394097f49ed82623d0fd2 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:55 -0700 Subject: [PATCH 19/20] workflows: add MinGW UCRT64 Windows cross-compile check Add a compile sanity check that cross-builds fluent-bit.exe for Windows from Linux with the Fedora MinGW-w64 UCRT64 toolchain, so the MinGW support does not bit-rot. The job runs in a fedora container, pins the same cmake version as the other compile checks, cross-builds a static libyaml, and configures with the distribution's ucrt64 toolchain file and the standard Windows plugin defaults. It is a single configuration with no matrix to keep the added CI cost low. Signed-off-by: Jiawei Huang --- .github/workflows/pr-compile-check.yaml | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.github/workflows/pr-compile-check.yaml b/.github/workflows/pr-compile-check.yaml index f980670919a..ad6fe8f1460 100644 --- a/.github/workflows/pr-compile-check.yaml +++ b/.github/workflows/pr-compile-check.yaml @@ -155,3 +155,49 @@ jobs: cmake -DFLB_PREFER_SYSTEM_LIB_ZSTD=ON -DFLB_PREFER_SYSTEM_LIB_KAFKA=ON ../ make -j $nparallel working-directory: build + + # Sanity check for Windows cross-compilation from Linux with the + # MinGW-w64 UCRT64 toolchain (no MSVC or Windows runner involved). + # See "Cross-compiling for Windows with MinGW" in DEVELOPER_GUIDE.md. + pr-compile-mingw-cross: + runs-on: ubuntu-latest + container: fedora:44 + timeout-minutes: 60 + steps: + - name: Install toolchain and build dependencies + run: | + dnf install -y bison file flex gcc git make ninja-build \ + ucrt64-gcc ucrt64-gcc-c++ ucrt64-openssl ucrt64-zlib + + - name: Install cmake + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2.2.0 + with: + cmake-version: "3.31.6" + + - name: Checkout Fluent Bit code + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Cross-compile a static libyaml + run: | + mkdir -p /tmp/libyaml-src + curl -sfL https://github.com/yaml/libyaml/releases/download/0.2.5/yaml-0.2.5.tar.gz \ + | tar xz --strip-components 1 -C /tmp/libyaml-src + cd /tmp/libyaml-src + ./configure --host=x86_64-w64-mingw32ucrt --prefix=/opt/libyaml \ + --enable-static --disable-shared CFLAGS="-DYAML_DECLARE_STATIC" + make -j 8 -C src + make -C src install + make -C include install + + # No plugin selection here: the build takes the standard Windows + # defaults from cmake/windows-setup.cmake, the same profile the MSVC + # Windows CI builds. + - name: Cross-compile Fluent Bit for Windows + run: | + cmake -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-ucrt64.cmake \ + -DFLB_LIBYAML_DIR=/opt/libyaml \ + ../ + ninja + file bin/fluent-bit.exe + working-directory: build From b21b836e4e1ea928773c7ff5b7f2905ddafebe62 Mon Sep 17 00:00:00 2001 From: Jiawei Huang Date: Mon, 6 Jul 2026 09:35:55 -0700 Subject: [PATCH 20/20] docs: describe MinGW Windows cross-compilation Document the Linux-hosted MinGW-w64 UCRT64 cross-compilation option in the Windows section of the developer guide, pointing at the pr-compile-mingw-cross workflow job as the reference recipe. Signed-off-by: Jiawei Huang --- DEVELOPER_GUIDE.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index a1a8aef3fb2..b228dc4507e 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -676,6 +676,21 @@ At time of writing this workflow *does not run any of the Fluent Bit test suite* - so it only checks that the target branch can be compiled. To run tests, a local build will be required. +#### Cross-compiling from Linux with MinGW + +Fluent Bit can also be cross-compiled for Windows from a Linux host using the +MinGW-w64 UCRT64 toolchain, without a Windows machine or MSVC. The +[`.github/workflows/pr-compile-check.yaml`](.github/workflows/pr-compile-check.yaml) +`pr-compile-mingw-cross` job is the reference recipe: it runs in a Fedora +container, installs the `ucrt64-gcc` cross toolchain, cross-builds a static +libyaml, and then configures with +`-DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-ucrt64.cmake`. + +Cross-builds produce `bin/fluent-bit.exe` but cannot run the test suites (the +binaries are Windows executables). Note the toolchain must target UCRT +(`x86_64-w64-mingw32ucrt`); the older MSVCRT-based MinGW toolchains are not +supported. + #### Using Docker for Windows For Windows users with Hyper-V capable machines the simplest way to build a