From ba893e7ce2f6e981c04b6a69f826de6e936dba92 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sun, 22 Feb 2026 11:47:59 +0000 Subject: [PATCH] build: transition libtap to static archive and bundle dependencies Refactored the build system to use a static 'libtap.a' instead of a shared library. This allows for bundling PostgreSQL, re2, and SQLite3 symbols directly into the archive using a cross-platform extraction and re-archiving method, ensuring compatibility with both GNU and BSD 'ar'. Key fixes: - Resolved 'undefined reference' errors for libpq and re2 symbols in TAP tests. - Fixed 'multiple definition' conflict for 'replace_str' between utils.cpp and proxysql_utils.cpp. - Simplified test Makefiles to link against the self-contained 'libtap.a'. --- test/tap/tap/Makefile | 41 ++++++++++++++----- test/tap/tap/noise_utils.cpp | 18 ++++++++ test/tap/tap/utils.cpp | 16 -------- test/tap/tests/Makefile | 6 +-- .../deprecate_eof_support/Makefile | 2 +- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/test/tap/tap/Makefile b/test/tap/tap/Makefile index 76564c464..35d7a24a2 100644 --- a/test/tap/tap/Makefile +++ b/test/tap/tap/Makefile @@ -18,6 +18,7 @@ IDIRS := -I$(PROXYSQL_IDIR) \ LIBPROXYSQLAR := $(PROXYSQL_LDIR)/libproxysql.a +AR ?= ar OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed $(WASAN) @@ -38,10 +39,10 @@ default: all .PHONY: all all: libtap_mariadb.a libtap_mysql57.a libtap_mysql8.a \ - libtap.so libcpp_dotenv.so libre2.so + libtap.a libcpp_dotenv.so libre2.so debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed $(WASAN) -debug: libtap_mariadb.a libtap_mysql57.a libtap_mysql8.a libtap.so +debug: libtap_mariadb.a libtap_mysql57.a libtap_mysql8.a libtap.a ### helper targets @@ -61,28 +62,46 @@ tap.o: tap.cpp cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so -lssl -lc $(CXX) -fPIC -c tap.cpp $(IDIRS) $(OPT) noise_utils_mariadb.o: noise_utils.cpp noise_utils.h utils.h command_line.h - $(CXX) -fPIC -c noise_utils.cpp $(IDIRS) -I$(MARIADB_IDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ + $(CXX) -DEXCLUDE_REPLACE_STR -fPIC -c noise_utils.cpp $(IDIRS) -I$(MARIADB_IDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ noise_utils_mysql57.o: noise_utils.cpp noise_utils.h utils.h command_line.h - $(CXX) -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL_IDIR) -I$(TEST_MYSQL_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ + $(CXX) -DEXCLUDE_REPLACE_STR -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL_IDIR) -I$(TEST_MYSQL_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ noise_utils_mysql8.o: noise_utils.cpp noise_utils.h utils.h command_line.h - $(CXX) -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ + $(CXX) -DEXCLUDE_REPLACE_STR -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ mcp_client.o: mcp_client.cpp mcp_client.h libcurl.so $(CXX) -fPIC -c mcp_client.cpp $(IDIRS) $(OPT) libtap_mariadb.a: tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mariadb.a tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo + rm -rf tmp_mariadb && mkdir tmp_mariadb + cd tmp_mariadb && $(AR) x $(POSTGRESQL_PATH)/interfaces/libpq/libpq.a + cd tmp_mariadb && $(AR) x $(POSTGRESQL_PATH)/common/libpgcommon.a + cd tmp_mariadb && $(AR) x $(POSTGRESQL_PATH)/port/libpgport.a + cd tmp_mariadb && $(AR) x $(RE2_LDIR)/libre2.a + $(AR) rcs $@ tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo tmp_mariadb/*.o + rm -rf tmp_mariadb libtap_mysql57.a: tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mysql57.a tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo + rm -rf tmp_mysql57 && mkdir tmp_mysql57 + cd tmp_mysql57 && $(AR) x $(POSTGRESQL_PATH)/interfaces/libpq/libpq.a + cd tmp_mysql57 && $(AR) x $(POSTGRESQL_PATH)/common/libpgcommon.a + cd tmp_mysql57 && $(AR) x $(POSTGRESQL_PATH)/port/libpgport.a + cd tmp_mysql57 && $(AR) x $(RE2_LDIR)/libre2.a + $(AR) rcs $@ tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo tmp_mysql57/*.o + rm -rf tmp_mysql57 libtap_mysql8.a: tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mysql8.a tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo - -libtap.so: libtap_mariadb.a cpp-dotenv/dynamic/cpp-dotenv/libcpp_dotenv.so libre2.so - $(CXX) -shared -o libtap.so -Wl,--whole-archive libtap_mariadb.a -Wl,--no-whole-archive -L$(POSTGRESQL_PATH)/interfaces/libpq -L$(POSTGRESQL_PATH)/common -L$(POSTGRESQL_PATH)/port -l:libpq.a $(LWGCOV) + rm -rf tmp_mysql8 && mkdir tmp_mysql8 + cd tmp_mysql8 && $(AR) x $(POSTGRESQL_PATH)/interfaces/libpq/libpq.a + cd tmp_mysql8 && $(AR) x $(POSTGRESQL_PATH)/common/libpgcommon.a + cd tmp_mysql8 && $(AR) x $(POSTGRESQL_PATH)/port/libpgport.a + cd tmp_mysql8 && $(AR) x $(RE2_LDIR)/libre2.a + $(AR) rcs $@ tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo tmp_mysql8/*.o + rm -rf tmp_mysql8 + +libtap.a: libtap_mariadb.a + cp libtap_mariadb.a libtap.a ### tap deps targets diff --git a/test/tap/tap/noise_utils.cpp b/test/tap/tap/noise_utils.cpp index 7adb8c2c3..f45972f97 100644 --- a/test/tap/tap/noise_utils.cpp +++ b/test/tap/tap/noise_utils.cpp @@ -45,6 +45,24 @@ static std::string get_opt_str(const NoiseOptions& opt, const std::string& key, return default_val; } +#ifndef EXCLUDE_REPLACE_STR +static std::string replace_str(const std::string& str, const std::string& match, const std::string& repl) { + if(match.empty()) { + return str; + } + + std::string result = str; + size_t start_pos = 0; + + while((start_pos = result.find(match, start_pos)) != std::string::npos) { + result.replace(start_pos, match.length(), repl); + start_pos += repl.length(); + } + + return result; +} +#endif + // Helper to get int option from map static int get_opt_int(const NoiseOptions& opt, const std::string& key, int default_val) { if (opt.find(key) != opt.end()) { diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index 71be780c4..8eed3dd62 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -247,22 +247,6 @@ string to_string(std::thread::id id) { return helper.str(); } -string replace_str(const string& str, const string& match, const string& repl) { - if(match.empty()) { - return str; - } - - string result { str }; - size_t start_pos = 0; - - while((start_pos = result.find(match, start_pos)) != std::string::npos) { - result.replace(start_pos, match.length(), repl); - start_pos += repl.length(); - } - - return result; -} - pair> disable_core_nodes_scheduler(CommandLine& cl, MYSQL* admin) { vector nodes_conns {}; diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index 8434bb0f5..4f37e3f82 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -61,16 +61,16 @@ OBJ := $(PROXYSQL_PATH)/src/obj/proxysql_global.o $(PROXYSQL_PATH)/src/obj/main. #SOURCES := ../tap/utils.cpp -MYLIBS_DYNAMIC_PART := -Wl,--export-dynamic -Wl,-Bdynamic -lgnutls -ltap -lcpp_dotenv -lcurl -lssl -lcrypto -luuid +MYLIBS_DYNAMIC_PART := -Wl,--export-dynamic -Wl,-Bdynamic -lgnutls -lcpp_dotenv -lcurl -lssl -lcrypto -luuid MYLIBS_STATIC_PART := -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lev -lprometheus-cpp-pull -lprometheus-cpp-core -MYLIBS_PG_PART := -Wl,-Bstatic -lpq -lpgcommon -lpgport +MYLIBS_PG_PART := MYLIBS_LAST_PART := -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl $(EXTRALINK) MYLIBS := $(MYLIBS_DYNAMIC_PART) $(MYLIBS_STATIC_PART) $(MYLIBS_PG_PART) $(MYLIBS_LAST_PART) #MYLIBS_PG := $(MYLIBS_DYNAMIC_PART) $(MYLIBS_STATIC_PART) $(MYLIBS_PG_PART) $(MYLIBS_LAST_PART) #MYLIBS := -Wl,--export-dynamic -Wl,-Bdynamic -lssl -lcrypto -lgnutls -ltap -lcpp_dotenv -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lev -lprometheus-cpp-pull -lprometheus-cpp-core -luuid -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl $(EXTRALINK) MYLIBSJEMALLOC := -Wl,-Bstatic -ljemalloc -STATIC_LIBS := $(CITYHASH_LDIR)/libcityhash.a +STATIC_LIBS := $(CITYHASH_LDIR)/libcityhash.a $(TAP_LDIR)/libtap.a LIBCOREDUMPERAR := ifeq ($(UNAME_S),Linux) diff --git a/test/tap/tests_with_deps/deprecate_eof_support/Makefile b/test/tap/tests_with_deps/deprecate_eof_support/Makefile index 44c372b74..24d3c066d 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/Makefile +++ b/test/tap/tests_with_deps/deprecate_eof_support/Makefile @@ -78,7 +78,7 @@ tests: @echo "Removing empty .gcno files ..." find -L . -type f -name '*.gcno' -empty -ls -delete -COMMONARGS = $(OPT) -Wl,-Bdynamic -ltap -lcpp_dotenv -lcurl -lre2 -lssl -lcrypto -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\" +COMMONARGS = $(OPT) -Wl,--start-group $(TAP_LDIR)/libtap.a -Wl,--end-group -Wl,-Bdynamic -lcpp_dotenv -lcurl -lre2 -lssl -lcrypto -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\" ok_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp $(CXX) $< -I$(MARIADB_IDIR) $(IDIRS) -L$(MARIADB_LDIR) $(LDIRS) -lmariadbclient $(COMMONARGS) -o $@