From 1149d9ac4116cd6d447b01ef6a5747d215367919 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 19 Dec 2024 23:51:59 +0000 Subject: [PATCH 1/6] auto/otel: Make use of nxt_feature_name When building with --otel on macOS for example I was seeing compile failures with the cpu_set_t stuff which should only be used under Linux. It turned out that despite checking for Linux sched_getaffinity() ... not found we were getting #ifndef NXT_HAVE_LINUX_SCHED_GETAFFINITY #define NXT_HAVE_LINUX_SCHED_GETAFFINITY 1 #endif in build/include/nxt_auto_config.h It seems this was due to the . auto/feature in auto/otel, this check happens right after the above. Without having nxt_feature_name=NXT_HAVE_OTEL set. Instead we were adding the define for that manually. Doing auto/feature without having a nxt_feature_name must have used the last set one and enabled it. Set nxt_feature_name and remove the manual editing of nxt_auto_config.h Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") Signed-off-by: Andrew Clayton --- auto/otel | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/auto/otel b/auto/otel index f23aac3b1..8ca325c89 100644 --- a/auto/otel +++ b/auto/otel @@ -22,6 +22,7 @@ if [ $NXT_OTEL = YES ]; then $echo -n " - " nxt_feature="OpenSSL library" + nxt_feature_name=NXT_HAVE_OTEL nxt_feature_run=yes nxt_feature_incs= nxt_feature_libs="-lssl -lcrypto" @@ -42,11 +43,4 @@ if [ $NXT_OTEL = YES ]; then NXT_OTEL_LIBS="-lssl -lcrypto" - cat << END >> $NXT_AUTO_CONFIG_H - -#ifndef NXT_HAVE_OTEL -#define NXT_HAVE_OTEL 1 -#endif - -END fi From b9232c75609db9f4ef5adddf366dc7bb894112f6 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Mon, 6 Jan 2025 17:47:05 +0000 Subject: [PATCH 2/6] auto/make: s/NXT_OTEL_LIB_LOC/NXT_OTEL_LIB_STATIC/ This better matches existing naming convention, e.g NXT_LIB_STATIC Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") Signed-off-by: Andrew Clayton --- auto/make | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/auto/make b/auto/make index 183e95c75..3ffac2fcc 100644 --- a/auto/make +++ b/auto/make @@ -22,7 +22,7 @@ AR = $AR EXTRA_CFLAGS = CFLAGS = $NXT_CFLAGS $NXT_CC_OPT $CFLAGS \$(EXTRA_CFLAGS) RUST_FLAGS = -NXT_OTEL_LIB_LOC = +NXT_OTEL_LIB_STATIC = NXT_EXEC_LINK = $NXT_EXEC_LINK $NXT_LD_OPT NXT_SHARED_LOCAL_LINK = $NXT_SHARED_LOCAL_LINK $NXT_LD_OPT @@ -85,9 +85,9 @@ if [ $NXT_OTEL = YES ]; then cat << END >> $NXT_MAKEFILE ifeq (\$D,1) - NXT_OTEL_LIB_LOC = $NXT_OTEL_LIB_DIR/target/debug/libotel.a + NXT_OTEL_LIB_STATIC = $NXT_OTEL_LIB_DIR/target/debug/libotel.a else - NXT_OTEL_LIB_LOC = $NXT_OTEL_LIB_DIR/target/release/libotel.a + NXT_OTEL_LIB_STATIC = $NXT_OTEL_LIB_DIR/target/release/libotel.a endif END @@ -154,14 +154,14 @@ cat << END >> $NXT_MAKEFILE libnxt: $NXT_BUILD_DIR/lib/$NXT_LIB_SHARED $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC -$NXT_BUILD_DIR/lib/$NXT_LIB_SHARED: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC) +$NXT_BUILD_DIR/lib/$NXT_LIB_SHARED: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_SHARED_LOCAL_LINK) -o \$@ \$(NXT_LIB_OBJS) \\ - $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_LOC) + $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_STATIC) -$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC) +$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) \$(PP_AR) \$@ - \$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC) + \$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC: \$(NXT_LIB_UNIT_OBJS) \\ $NXT_BUILD_DIR/share/pkgconfig/unit.pc \\ @@ -375,11 +375,11 @@ $echo >> $NXT_MAKEFILE cat << END >> $NXT_MAKEFILE $NXT_BUILD_DIR/sbin/$NXT_DAEMON: $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ - \$(NXT_OBJS) \$(NXT_OTEL_LIB_LOC) + \$(NXT_OBJS) \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_EXEC_LINK) -o \$@ \$(CFLAGS) \\ \$(NXT_OBJS) $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ - $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_LOC) + $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_STATIC) END @@ -580,7 +580,7 @@ NXT_OTEL_DEPS=" \ cat << END >> $NXT_MAKEFILE -\$(NXT_OTEL_LIB_LOC): $NXT_OTEL_DEPS +\$(NXT_OTEL_LIB_STATIC): $NXT_OTEL_DEPS cargo build \$(RUST_FLAGS) --manifest-path $NXT_OTEL_LIB_DIR/Cargo.toml END fi From 854a52ce6b75a434a4d2b89d306024c84b9c670f Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov Date: Thu, 19 Dec 2024 15:47:50 -0800 Subject: [PATCH 3/6] auto/make, otel: fix linking on macOS and Ubuntu The static library is supposed to be specified prior to its dependencies. Also, no need to put an otel static library inside libnxt static library, as we explicitely link unit binary with otel static library anyway. This fixes the following build problems: - macOS: Finished `release` profile [optimized] target(s) in 58.07s AR build/lib/libnxt.a LD build/sbin/unitd ld: archive member 'libotel.a' not a mach-o file in '/private/tmp/unit-20241219-8965-yb46xp/build/lib/libnxt.a' clang: error: linker command failed with exit code 1 (use -v to see invocation) - Ubuntu 22 (./configure --otel): LD build/sbin/unitd cc -Wl,-E -o build/sbin/unitd -pipe -fPIC -fvisibility=hidden -fno-strict-overflow -funsigned-char -std=gnu11 -O -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fno-strict-aliasing -Wmissing-prototypes -Werror -g \ build/src/nxt_main.o build/lib/libnxt.a \ -lm -lrt -lpthread \ \ -lpcre2-8 -lssl -lcrypto src/otel/target/release/libotel.a /usr/bin/ld: src/otel/target/release/libotel.a(reqwest-97d1376dfb77d784.reqwest.cb371ce8e1e3945e-cgu.04.rcgu.o): in function `core::ptr::drop_in_place>': reqwest.cb371ce8e1e3945e-cgu.04:(.text._ZN4core3ptr69drop_in_place$LT$alloc..vec..Vec$LT$reqwest..tls..Certificate$GT$$GT$17h9b62679cc7161be5E+0x30): undefined reference to `X509_free' Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") [ Tweaked subject prefix. s/NXT_OTEL_LIB_LOC/NXT_OTEL_LIB_STATIC/ - Andrew ] Signed-off-by: Andrew Clayton --- auto/make | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/auto/make b/auto/make index 3ffac2fcc..81994e6ec 100644 --- a/auto/make +++ b/auto/make @@ -157,11 +157,12 @@ libnxt: $NXT_BUILD_DIR/lib/$NXT_LIB_SHARED $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC $NXT_BUILD_DIR/lib/$NXT_LIB_SHARED: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_SHARED_LOCAL_LINK) -o \$@ \$(NXT_LIB_OBJS) \\ - $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_STATIC) + \$(NXT_OTEL_LIB_STATIC) \\ + $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS -$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) +$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC: \$(NXT_LIB_OBJS) \$(PP_AR) \$@ - \$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_STATIC) + \$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_OBJS) $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC: \$(NXT_LIB_UNIT_OBJS) \\ $NXT_BUILD_DIR/share/pkgconfig/unit.pc \\ @@ -379,7 +380,8 @@ $NXT_BUILD_DIR/sbin/$NXT_DAEMON: $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ \$(PP_LD) \$@ \$(v)\$(NXT_EXEC_LINK) -o \$@ \$(CFLAGS) \\ \$(NXT_OBJS) $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ - $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_STATIC) + \$(NXT_OTEL_LIB_STATIC) \\ + $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS END From bfb86ed0b97f886f1e979d3e68a04585af1792f4 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 20 Dec 2024 09:16:03 +0100 Subject: [PATCH 4/6] auto/make: Add missing NXT_OTEL_LIB_STATIC to some C tests Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") [ Commit subject, s/NXT_OTEL_LIB_LOC/NXT_OTEL_LIB_STATIC/ and placement of NXT_OTEL_LIB_STATIC tweaked as per @thresheek - Andrew ] Signed-off-by: Andrew Clayton --- auto/make | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/auto/make b/auto/make index 81994e6ec..2468ea39e 100644 --- a/auto/make +++ b/auto/make @@ -265,36 +265,40 @@ tests: $NXT_BUILD_DIR/tests $NXT_BUILD_DIR/utf8_file_name_test \\ $NXT_BUILD_DIR/unit_websocket_echo $NXT_BUILD_DIR/tests: \$(NXT_TEST_OBJS) \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/tests \\ \$(CFLAGS) \$(NXT_TEST_OBJS) \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \$(NXT_OTEL_LIB_STATIC) \\ $NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS $NXT_BUILD_DIR/utf8_file_name_test: $NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(CC) \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\ -o $NXT_BUILD_DIR/utf8_file_name_test \\ $NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \$(NXT_OTEL_LIB_STATIC) \\ $NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS $NXT_BUILD_DIR/ncq_test: $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/ncq_test \\ \$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \$(NXT_OTEL_LIB_STATIC) \\ $NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS $NXT_BUILD_DIR/vbcq_test: $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + \$(NXT_OTEL_LIB_STATIC) \$(PP_LD) \$@ \$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/vbcq_test \\ \$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\ - $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ + $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \$(NXT_OTEL_LIB_STATIC) \\ $NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS $NXT_BUILD_DIR/unit_app_test: $NXT_BUILD_DIR/src/test/nxt_unit_app_test.o \\ From 1ac4e40941df4fac62c471545aec3e3c75abe50e Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov Date: Thu, 19 Dec 2024 16:09:43 -0800 Subject: [PATCH 5/6] auto/otel: don't look for OpenSSL on Darwin Rust code relies on macOS-provided frameworks for TLS. Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") [ Tweaked subject prefix. Some minor tweaks for current changes. - Andrew ] Signed-off-by: Andrew Clayton --- auto/otel | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/auto/otel b/auto/otel index 8ca325c89..4d059a285 100644 --- a/auto/otel +++ b/auto/otel @@ -19,28 +19,44 @@ if [ $NXT_OTEL = YES ]; then fi $echo "found" - $echo -n " - " - - nxt_feature="OpenSSL library" - nxt_feature_name=NXT_HAVE_OTEL - nxt_feature_run=yes - nxt_feature_incs= - nxt_feature_libs="-lssl -lcrypto" - nxt_feature_test="#include - - int main(void) { - SSL_library_init(); - return 0; - }" - . auto/feature - - if [ ! $nxt_found = yes ]; then - $echo - $echo $0: error: OpenTelemetry support requires OpenSSL. - $echo - exit 1; - fi - - NXT_OTEL_LIBS="-lssl -lcrypto" + case "$NXT_SYSTEM" in + Darwin) + NXT_OTEL_LIBS="-framework CoreFoundation -framework Security -framework SystemConfiguration" + + cat << END >> $NXT_AUTO_CONFIG_H + +#ifndef NXT_HAVE_OTEL +#define NXT_HAVE_OTEL 1 +#endif + +END + ;; + *) + + $echo -n " - " + + nxt_feature="OpenSSL library" + nxt_feature_name=NXT_HAVE_OTEL + nxt_feature_run=yes + nxt_feature_incs= + nxt_feature_libs="-lssl -lcrypto" + nxt_feature_test="#include + + int main(void) { + SSL_library_init(); + return 0; + }" + . auto/feature + + if [ ! $nxt_found = yes ]; then + $echo + $echo $0: error: OpenTelemetry support requires OpenSSL. + $echo + exit 1; + fi + + NXT_OTEL_LIBS="-lssl -lcrypto" + ;; + esac fi From d0dbba3b9f2f6a2e0e0d6e9862a4c6c1ab603242 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 9 Jan 2025 03:55:44 +0000 Subject: [PATCH 6/6] auto/make: Fix various issues with building OTEL There were at least a couple of issues with building OTEL support. It only worked with GNU make due to the use of ifeq, even gmake had some issues. Debug builds were broken due to trying to pass --debug to cargo which is the default and isn't a valid option. This 'fixes' things by doing 'release' builds of OTEL by default. Passing D=1 to make will generate 'debug' builds but this as previously with D= etc, only works with GNU make. We make use of the '--emit link=' rustc option to place the libotel.a static library into build/lib This is good, it consolidates the static libraries into one place and it simplifies the build scripts. While we're at it pretty print the cargo command by default. Fixes: 9d3dcb800 ("otel: add build tooling to include otel code") Link: Signed-off-by: Andrew Clayton --- auto/make | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/auto/make b/auto/make index 2468ea39e..4320f6299 100644 --- a/auto/make +++ b/auto/make @@ -15,19 +15,20 @@ PP_AR := @echo ' AR ' PP_LD := @echo ' LD ' PP_VER := @echo ' VER ' PP_SED := @echo ' SED ' +PP_CR := @echo ' CR ' CC = $CC AR = $AR EXTRA_CFLAGS = CFLAGS = $NXT_CFLAGS $NXT_CC_OPT $CFLAGS \$(EXTRA_CFLAGS) -RUST_FLAGS = -NXT_OTEL_LIB_STATIC = NXT_EXEC_LINK = $NXT_EXEC_LINK $NXT_LD_OPT NXT_SHARED_LOCAL_LINK = $NXT_SHARED_LOCAL_LINK $NXT_LD_OPT NXT_MODULE_LINK = $NXT_MODULE_LINK +NXT_OTEL_LIB_STATIC = + all: $NXT_DAEMON manpage .PHONY: $NXT_DAEMON manpage @@ -37,6 +38,18 @@ manpage: $NXT_BUILD_DIR/share/man/man8/unitd.8 END +if [ $NXT_OTEL = YES ]; then + + cat << END >> $NXT_MAKEFILE + +RUST_FLAGS = --release +NXT_OTEL_LIB_STATIC = $NXT_BUILD_DIR/lib/libotel.a + +END + +fi + + NXT_OS=$(uname -s) NXT_GNU_MAKE=$(make --version | grep GNU || true) @@ -63,9 +76,7 @@ D := 0 ifeq (\$D,1) CFLAGS += -O0 - RUST_FLAGS += --debug -else - RUST_FLAGS += --release + RUST_FLAGS = endif # Optionally disable -Werror with @@ -80,18 +91,6 @@ END fi -# potentially set otel lib location -if [ $NXT_OTEL = YES ]; then -cat << END >> $NXT_MAKEFILE - -ifeq (\$D,1) - NXT_OTEL_LIB_STATIC = $NXT_OTEL_LIB_DIR/target/debug/libotel.a -else - NXT_OTEL_LIB_STATIC = $NXT_OTEL_LIB_DIR/target/release/libotel.a -endif - -END -fi # The include paths list. @@ -587,6 +586,9 @@ NXT_OTEL_DEPS=" \ cat << END >> $NXT_MAKEFILE \$(NXT_OTEL_LIB_STATIC): $NXT_OTEL_DEPS - cargo build \$(RUST_FLAGS) --manifest-path $NXT_OTEL_LIB_DIR/Cargo.toml + \$(PP_CR) \$@ + \$(v)cargo rustc \$(RUST_FLAGS) \\ + --manifest-path $NXT_OTEL_LIB_DIR/Cargo.toml \\ + -- --emit link=../../$NXT_BUILD_DIR/lib/libotel.a END fi