Skip to content

Commit

Permalink
fluent-bit: fix build for not-the-latest systems
Browse files Browse the repository at this point in the history
  • Loading branch information
barracuda156 committed Aug 14, 2024
1 parent 6351be7 commit 5d8c222
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sysutils/fluent-bit/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ checksums rmd160 82864bd89b6c7836fae17ef17928df7d30cb092e \
sha256 e75305c4ba9baa717baeacb4abbb9390f7433a74dcef0c41cc9d630288ca1d81 \
size 26767198

patchfiles-append 0001-macos-setup-do-not-use-clang-flag-with-gcc.patch \
0002-posix_file.c-add-a-missing-header.patch \
0003-libatomic-gcc.patch \
0004-snappy-compat.h-fix-Big-endian-on-Apple.patch \
0005-mk_scheduler-fix-for-missing-pthread_threadid_np.patch \
0006-flb_utils.c-fix-for-macOS-12.patch \
0007-Fix-for-meminfo-on-32-bit-darwin.patch

# At least for atomics and some modules
compiler.cxx_standard 2011
# /usr/bin/ranlib: unknown option character `n' in: -no_warning_for_no_symbols
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 5da85905ae4b67dbf742d9f9f5cbf16a77d2193d Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 18:58:16 +0800
Subject: [PATCH] macos-setup: do not use clang flag with gcc

---
cmake/macos-setup.cmake | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git cmake/macos-setup.cmake cmake/macos-setup.cmake
index 58681f572..c01ae829a 100644
--- cmake/macos-setup.cmake
+++ cmake/macos-setup.cmake
@@ -5,7 +5,9 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef-prefix=TARGET_OS_ ")
+if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef-prefix=TARGET_OS_ ")
+endif()

if (HOMEBREW EQUAL 0 AND EXISTS "${HOMEBREW_PREFIX}")
message(STATUS "Found Homebrew at ${HOMEBREW_PREFIX}")
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 69551c99db208e28e64cb0e7630758261742b972 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 18:14:34 +0800
Subject: [PATCH] posix_file.c: add a missing header

---
.../core/shared/platform/common/posix/posix_file.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c
index 8c4f7aa9d..262aa887d 100644
--- lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c
+++ lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c
@@ -7,6 +7,10 @@
#include "libc_errno.h"
#include <unistd.h>

+#ifdef __APPLE__
+#include <sys/stdio.h> /* renameat */
+#endif
+
#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
#define CONFIG_HAS_PWRITEV 1
#define CONFIG_HAS_PREADV 1
--
2.46.0

18 changes: 18 additions & 0 deletions sysutils/fluent-bit/files/0003-libatomic-gcc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From 1cd1773c7332532a271f355453e33ecb154dfe4a Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 17:42:56 +0800
Subject: [PATCH] Fix CMake setup

diff --git CMakeLists.txt CMakeLists.txt
index fa6393f35..eca403d27 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -67,7 +67,7 @@ endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FLB_FILENAME__=__FILE__")

-if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l")
+if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -latomic")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 63cf77ffc453f34bcfe4a085b95a24f1bdd068f5 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 19:02:15 +0800
Subject: [PATCH] snappy/compat.h: fix Big-endian on Apple

---
lib/snappy-fef67ac/compat.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git lib/snappy-fef67ac/compat.h lib/snappy-fef67ac/compat.h
index 3b755f495..afa127507 100644
--- lib/snappy-fef67ac/compat.h
+++ lib/snappy-fef67ac/compat.h
@@ -5,14 +5,14 @@
#ifdef __FreeBSD__
# include <sys/endian.h>
#elif defined(__APPLE_CC_) || defined(__MACH__) /* MacOS/X support */
-# include <machine/endian.h>
+# include <libkern/OSByteOrder.h>

#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
# define htole16(x) (x)
# define le32toh(x) (x)
#elif __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
-# define htole16(x) __DARWIN_OSSwapInt16(x)
-# define le32toh(x) __DARWIN_OSSwapInt32(x)
+# define htole16(x) OSSwapInt16(x)
+# define le32toh(x) OSSwapInt32(x)
#else
# error "Endianness is undefined"
#endif
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From 04088e6cb1b1614ddfab29b60aebff316e009bb4 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 19:00:28 +0800
Subject: [PATCH] mk_scheduler: fix for missing pthread_threadid_np

---
lib/monkey/mk_server/mk_scheduler.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git lib/monkey/mk_server/mk_scheduler.c lib/monkey/mk_server/mk_scheduler.c
index a680d3cdf..2ccec3bed 100644
--- lib/monkey/mk_server/mk_scheduler.c
+++ lib/monkey/mk_server/mk_scheduler.c
@@ -37,6 +37,10 @@

#include <signal.h>

+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+
#ifndef _WIN32
#include <sys/syscall.h>
#endif
@@ -288,7 +292,17 @@ static int mk_sched_register_thread(struct mk_server *server)
worker->pid = syscall(__NR_gettid);
#elif defined(__APPLE__)
uint64_t tid;
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 || defined(__POWERPC__)
+ tid = pthread_mach_thread_np(pthread_self());
+#elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+ if (&pthread_threadid_np != NULL) {
+ pthread_threadid_np(NULL, &tid);
+ } else {
+ tid = pthread_mach_thread_np(pthread_self());
+ }
+#else
pthread_threadid_np(NULL, &tid);
+#endif
worker->pid = tid;
#else
worker->pid = 0xdeadbeef;
--
2.46.0

27 changes: 27 additions & 0 deletions sysutils/fluent-bit/files/0006-flb_utils.c-fix-for-macOS-12.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 2dd55595e6dc321766ce39887371c9b66f69dbb7 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 19:23:11 +0800
Subject: [PATCH] flb_utils.c: fix for macOS < 12

---
src/flb_utils.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git src/flb_utils.c src/flb_utils.c
index 2f445980d..863a4c7db 100644
--- src/flb_utils.c
+++ src/flb_utils.c
@@ -49,6 +49,10 @@ extern struct flb_aws_error_reporter *error_reporter;
#ifdef FLB_SYSTEM_MACOS
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
+#include <AvailabilityMacros.h>
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
+#define kIOMainPortDefault kIOMasterPortDefault
+#endif
#endif

/*
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
From b664f9839df3b3c9f342de9ee0b7ba097bc1cba9 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 14 Aug 2024 19:51:24 +0800
Subject: [PATCH] Fix for meminfo on 32-bit darwin

---
.../in_node_exporter_metrics/ne_meminfo_darwin.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git plugins/in_node_exporter_metrics/ne_meminfo_darwin.c plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
index 23d4a34bd..822846fbb 100644
--- plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
+++ plugins/in_node_exporter_metrics/ne_meminfo_darwin.c
@@ -32,6 +32,8 @@
#include <mach/mach_init.h>
#include <mach/mach_host.h>

+#include <AvailabilityMacros.h>
+
static int meminfo_configure(struct flb_ne *ctx)
{
struct cmt_counter *c;
@@ -140,7 +142,11 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
+#if defined(__i386__) || defined(__ppc__)
+ vm_statistics_data_t vm_stat;
+#else
vm_statistics64_data_t vm_stat;
+#endif
kern_return_t err;
vm_size_t page_size;
struct xsw_usage swap;
@@ -152,7 +158,11 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);

+#if defined(__i386__) || defined(__ppc__)
+ err = host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
+#else
err = host_statistics64(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
+#endif

if (err != KERN_SUCCESS) {
flb_plg_error(ctx->ins, "host_statistics() is failed with error = %d", err);
@@ -177,8 +187,10 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
cmt_gauge_set(ctx->darwin_free_bytes, ts,
ps * vm_stat.free_count, 0, NULL);

+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
cmt_gauge_set(ctx->darwin_compressed_bytes, ts,
ps * vm_stat.compressor_page_count, 0, NULL);
+#endif

cmt_gauge_set(ctx->darwin_active_bytes, ts,
ps * vm_stat.active_count, 0, NULL);
@@ -186,14 +198,18 @@ static int meminfo_update(struct flb_ne *ctx, uint64_t ts)
cmt_gauge_set(ctx->darwin_inactive_bytes, ts,
ps * vm_stat.inactive_count, 0, NULL);

+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
cmt_gauge_set(ctx->darwin_internal_bytes, ts,
ps * vm_stat.internal_page_count, 0, NULL);
+#endif

cmt_gauge_set(ctx->darwin_wired_bytes, ts,
ps * vm_stat.wire_count, 0, NULL);

+#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
cmt_gauge_set(ctx->darwin_purgeable_bytes, ts,
ps * vm_stat.purgeable_count, 0, NULL);
+#endif

cmt_counter_set(ctx->darwin_pageins_bytes, ts,
ps * vm_stat.pageins, 0, NULL);
--
2.46.0

0 comments on commit 5d8c222

Please sign in to comment.