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 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/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 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 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; 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/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, 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) 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 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); 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 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 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" 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) 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 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"); 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); 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 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; 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); 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) 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;