@cryptotaxi247 / netdata-1 / commits / 1138bde50

compile time and runtime check of required compiler flags (#19513)

* compile time and runtime check of required compiler flags * added compiler flags in buildinfo * added basic runtime information in buildinfo * check for -fexceptions

Costa Tsaousis committed Jan 28, 2025 at 17:52 UTC 1138bde50e8b2f51043b6a5f60141a325ccb822a
4 files changed +106 -2
CMakeLists.txt
+31 -1
@@ -83,6 +83,11 @@ if(USE_MOLD)
83 endif()
84 endif()
85
86 +check_c_compiler_flag("-fexceptions" HAVE_FEXCEPTIONS)
87 +if (NOT HAVE_FEXCEPTIONS)
88 + message(FATAL_ERROR "Missing required compiler flag: -fexceptions.")
89 +endif()
90 +
91 set(CONFIG_H_DIR ${CMAKE_BINARY_DIR})
92 set(CONFIG_H ${CONFIG_H_DIR}/config.h)
93
@@ -2965,8 +2970,33 @@ endif()
2970 set(WEB_DEST "${WEB_DIR}")
2971 set(WEB_DIR "${NETDATA_RUNTIME_PREFIX}/${WEB_DEST}")
2972
2973 +# Collect all compiler flags
2974 +get_directory_property(NETDATA_COMPILE_OPTIONS COMPILE_OPTIONS)
2975 +get_directory_property(NETDATA_COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
2976 +
2977 +# Collect all linker flags
2978 +get_directory_property(NETDATA_LINK_OPTIONS LINK_OPTIONS)
2979 +get_directory_property(NETDATA_LINK_LIBRARIES LINK_LIBRARIES)
2980 +
2981 +list(APPEND CONFIGURE_OPTIONS
2982 + # Build type and languages
2983 + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
2984 + "-DCMAKE_C_STANDARD=${CMAKE_C_STANDARD}"
2985 + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
2986 + "-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}"
2987 +
2988 + # Compiler flags (dynamically collected)
2989 + "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS} ${NETDATA_COMPILE_OPTIONS}'"
2990 + "-DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS} ${NETDATA_COMPILE_OPTIONS}'"
2991 + "-DCMAKE_COMPILE_DEFINITIONS='${NETDATA_COMPILE_DEFINITIONS}'"
2992 +
2993 + # Linker flags (dynamically collected)
2994 + "-DCMAKE_EXE_LINKER_FLAGS='${CMAKE_EXE_LINKER_FLAGS} ${NETDATA_LINK_OPTIONS}'"
2995 + "-DCMAKE_SHARED_LINKER_FLAGS='${CMAKE_SHARED_LINKER_FLAGS}'"
2996 +)
2997 +
2998 +string(JOIN " " CONFIGURE_COMMAND "cmake" ${CONFIGURE_OPTIONS})
2999
2969 -set(CONFIGURE_COMMAND "dummy-configure-command")
3000 if (NOT NETDATA_USER)
3001 set(NETDATA_USER "netdata")
3002 endif()
packaging/cmake/config.cmake.h.in
+4
@@ -14,6 +14,10 @@
14 #cmakedefine OS_MACOS
15 #cmakedefine OS_WINDOWS
16
17 +// required compilation options
18 +
19 +#cmakedefine HAVE_FEXCEPTIONS
20 +
21 // checked headers
22
23 #cmakedefine HAVE_NETINET_IN_H
src/daemon/buildinfo.c
+66 -1
@@ -118,6 +118,11 @@ typedef enum __attribute__((packed)) {
118 BIB_EXPORT_SHELL,
119 BIB_DEVEL_TRACE_ALLOCATIONS,
120 BIB_DEVELOPER_MODE,
121 + BIB_RUNTIME_PROFILE,
122 + BIB_RUNTIME_PARENT,
123 + BIB_RUNTIME_CHILD,
124 + BIB_RUNTIME_MEM_TOTAL,
125 + BIB_RUNTIME_MEM_AVAIL,
126
127 // leave this last
128 BIB_TERMINATOR,
@@ -135,7 +140,8 @@ typedef enum __attribute__((packed)) {
140 BIC_LIBS,
141 BIC_PLUGINS,
142 BIC_EXPORTERS,
138 - BIC_DEBUG_DEVEL
143 + BIC_DEBUG_DEVEL,
144 + BIC_RUNTIME,
145 } BUILD_INFO_CATEGORY;
146
147 typedef enum __attribute__((packed)) {
@@ -1040,6 +1046,46 @@ static struct {
1046 .json = "dev-mode",
1047 .value = NULL,
1048 },
1049 + [BIB_RUNTIME_PROFILE] = {
1050 + .category = BIC_RUNTIME,
1051 + .type = BIT_STRING,
1052 + .analytics = "ConfigProfile",
1053 + .print = "Profile",
1054 + .json = "profile",
1055 + .value = NULL,
1056 + },
1057 + [BIB_RUNTIME_PARENT] = {
1058 + .category = BIC_RUNTIME,
1059 + .type = BIT_BOOLEAN,
1060 + .analytics = "StreamParent",
1061 + .print = "Stream Parent (accept data from Children)",
1062 + .json = "parent",
1063 + .value = NULL,
1064 + },
1065 + [BIB_RUNTIME_CHILD] = {
1066 + .category = BIC_RUNTIME,
1067 + .type = BIT_BOOLEAN,
1068 + .analytics = "StreamChild",
1069 + .print = "Stream Child (send data to a Parent)",
1070 + .json = "child",
1071 + .value = NULL,
1072 + },
1073 + [BIB_RUNTIME_MEM_TOTAL] = {
1074 + .category = BIC_RUNTIME,
1075 + .type = BIT_STRING,
1076 + .analytics = "TotalMemory",
1077 + .print = "Total System Memory",
1078 + .json = "mem-total",
1079 + .value = NULL,
1080 + },
1081 + [BIB_RUNTIME_MEM_AVAIL] = {
1082 + .category = BIC_RUNTIME,
1083 + .type = BIT_STRING,
1084 + .analytics = "AvailableMemory",
1085 + .print = "Available System Memory",
1086 + .json = "mem-available",
1087 + .value = NULL,
1088 + },
1089
1090 // leave this last
1091 [BIB_TERMINATOR] = {
@@ -1454,9 +1500,26 @@ static void populate_packaging_info() {
1500 build_info_set_value(BIB_PACKAGING_INSTALL_TYPE, strdupz(BUILD_PACKAGING_INFO.install_type));
1501 build_info_set_value(BIB_PACKAGING_ARCHITECTURE, strdupz(BUILD_PACKAGING_INFO.prebuilt_arch));
1502 build_info_set_value(BIB_PACKAGING_DISTRO, strdupz(BUILD_PACKAGING_INFO.prebuilt_distro));
1503 +
1504 + CLEAN_BUFFER *wb = buffer_create(0, NULL);
1505 + ND_PROFILE_2buffer(wb, nd_profile_detect_and_configure(false), " ");
1506 + build_info_set_value_strdupz(BIB_RUNTIME_PROFILE, buffer_tostring(wb));
1507 +
1508 + build_info_set_status(BIB_RUNTIME_PARENT, stream_conf_is_parent(false));
1509 + build_info_set_status(BIB_RUNTIME_CHILD, stream_conf_is_child());
1510 }
1511 spinlock_unlock(&BUILD_PACKAGING_INFO.spinlock);
1512 }
1513 +
1514 + OS_SYSTEM_MEMORY sm = os_system_memory(true);
1515 + char buf[1024];
1516 + snprintfz(buf, sizeof(buf), "%" PRIu64, sm.ram_total_bytes);
1517 + // size_snprintf(buf, sizeof(buf), sm.ram_total_bytes, "B", false);
1518 + build_info_set_value_strdupz(BIB_RUNTIME_MEM_TOTAL, buf);
1519 +
1520 + snprintfz(buf, sizeof(buf), "%" PRIu64, sm.ram_available_bytes);
1521 + // size_snprintf(buf, sizeof(buf), sm.ram_available_bytes, "B", false);
1522 + build_info_set_value_strdupz(BIB_RUNTIME_MEM_AVAIL, buf);
1523 }
1524
1525 // ----------------------------------------------------------------------------
@@ -1529,6 +1592,7 @@ void print_build_info(void) {
1592 print_build_info_category_to_console(BIC_PLUGINS, "Plugins");
1593 print_build_info_category_to_console(BIC_EXPORTERS, "Exporters");
1594 print_build_info_category_to_console(BIC_DEBUG_DEVEL, "Debug/Developer Features");
1595 + print_build_info_category_to_console(BIC_RUNTIME, "Runtime Information");
1596 }
1597
1598 void build_info_to_json_object(BUFFER *b) {
@@ -1548,6 +1612,7 @@ void build_info_to_json_object(BUFFER *b) {
1612 print_build_info_category_to_json(b, BIC_PLUGINS, "plugins");
1613 print_build_info_category_to_json(b, BIC_EXPORTERS, "exporters");
1614 print_build_info_category_to_json(b, BIC_DEBUG_DEVEL, "debug-n-devel");
1615 + print_build_info_category_to_json(b, BIC_RUNTIME, "runtime");
1616 }
1617
1618 void print_build_info_json(void) {
src/daemon/main.c
+5
@@ -227,6 +227,11 @@ int unittest_prepare_rrd(const char **user) {
227 }
228
229 int netdata_main(int argc, char **argv) {
230 +#if !defined(HAVE_FEXCEPTIONS)
231 + fprintf(stderr, "Netdata has been compiled without these required compiler flags: -fexceptions.\n");
232 + exit(1);
233 +#endif
234 +
235 string_init();
236 analytics_init();
237