diff --git a/.github/workflows/CI-darwin.yml b/.github/workflows/CI-darwin.yml new file mode 100644 index 0000000000..3f3167d1e4 --- /dev/null +++ b/.github/workflows/CI-darwin.yml @@ -0,0 +1,28 @@ +name: Darwin + +on: + push: + branches: [ "v2.x" ] + paths-ignore: + - '.github/**' + - '**.md' + pull_request: + branches: [ "v2.x" ] + paths-ignore: + - '.github/**' + - '**.md' + workflow_dispatch: +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: brew install automake bzip2 cmake git gpatch gnutls ossp-uuid libtool + + - name: Build + run: make + + - name: Show version + run: ./src/proxysql --version diff --git a/.gitignore b/.gitignore index adcc2774b8..3747260053 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ core #config proxysql.cnf* proxysql.db* +proxysql-*.pem jeprof*heap perf.data* diff --git a/INSTALL.md b/INSTALL.md index e7d5cfed02..677c65088e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -26,7 +26,7 @@ The list of currently supported operating systems for native packaging is: - Fedora 33,24 - OpenSUSE 15 - AlmaLinux 8,9 - + Download a __deb__ or __rpm__ installer file for your OS and architecture from: https://github.com/sysown/proxysql/releases @@ -111,7 +111,7 @@ https://github.com/ProxySQL/docker-images/tree/main/build-clang-images On modern Mac OSX, ProxySQL's dependencies are not fully satisfied by the tools included with the XCode/clang toolkit. Using the [Homebrew](https://brew.sh/) OSX package manager, dependencies can be installed and located on OSX like this: ```bash -brew install automake bzip2 cmake make git gpatch gnutls ossp-uuid +brew install automake bzip2 cmake make git gpatch gnutls ossp-uuid libtool ``` Go to the directory where you cloned the repo (or unpacked the tarball) and run: diff --git a/Makefile b/Makefile index a067414c08..4607fc6f8f 100644 --- a/Makefile +++ b/Makefile @@ -42,9 +42,9 @@ export MAKE export CURVER ### detect compiler support for c++11/17 -CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') +CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201703L) - CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') + CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | cut -d' ' -f3) LEGACY_BUILD := 1 ifneq ($(CPLUSPLUS),201103L) $(error Compiler must support at least c++11) @@ -235,7 +235,7 @@ build_tap_test_debug: build_tap_tests_debug build_tap_tests_debug: build_src_debug cd test/tap && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE} debug -# ClickHouse build targets are now default build targets. +# ClickHouse build targets are now default build targets. # To maintain backward compatibility, ClickHouse targets are still available. .PHONY: build_deps_clickhouse build_deps_clickhouse: build_deps_default @@ -289,7 +289,7 @@ SYS_ARCH := $(shell uname -m) REL_ARCH := $(subst x86_64,amd64,$(subst aarch64,arm64,$(SYS_ARCH))) RPM_ARCH := .$(SYS_ARCH) DEB_ARCH := _$(REL_ARCH) -REL_VERS := $(shell echo ${GIT_VERSION} | grep -Po '(?<=^v|^)[\d\.]+') +REL_VERS := $(shell echo ${GIT_VERSION} | awk -F'[.-]' '{print $1"."$2"."$3}') RPM_VERS := -$(REL_VERS)-1 DEB_VERS := _$(REL_VERS) diff --git a/deps/Makefile b/deps/Makefile index 7e4235dc97..7e3f123540 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -28,9 +28,9 @@ endif ### detect compiler support for c++11/17 -CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') +CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201703L) - CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') + CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201103L) $(error Compiler must support at least c++11) endif @@ -60,11 +60,7 @@ ifneq ($(CENTOSVER),6) cd libinjection/libinjection && patch -p1 < ../update-build-py3.diff cd libinjection/libinjection && patch -p1 < ../libinjection_sqli.c.patch endif -ifeq ($(SYS_KERN),Darwin) - sed -i '' 's/CC=/CC?=/' libinjection/libinjection/src/Makefile -else sed -i -e 's/CC=/CC?=/' libinjection/libinjection/src/Makefile -endif cd libinjection/libinjection && CC=${CC} CXX=${CXX} ${MAKE} libinjection: libinjection/libinjection/src/libinjection.a @@ -78,7 +74,7 @@ libssl/openssl/libssl.a: # cd libssl/openssl && patch crypto/asn1/a_time.c < ../a_time.c-multiplication-overflow.patch cd libssl/openssl && ./config no-ssl3 no-tests cd libssl/openssl && CC=${CC} CXX=${CXX} ${MAKE} - cd libssl/openssl && ln -fsT . lib # curl wants this path + cd libssl/openssl && ln -fs . lib # curl wants this path libssl: libssl/openssl/libssl.a @@ -94,6 +90,11 @@ libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a: libmicrohttpd/libmi cd libhttpserver/libhttpserver && patch -p0 < ../replace_static_global_strings.patch ifeq ($(UNAME_S),FreeBSD) sed -i -e 's/\/bin\/bash/\/usr\/local\/bin\/bash/' libhttpserver/libhttpserver/bootstrap +endif +ifeq ($(SYS_KERN),Darwin) +ifeq (, $(shell which glibtoolize)) + sed -i -e 's/glibtoolize/libtoolize/' libhttpserver/libhttpserver/bootstrap +endif endif cd libhttpserver/libhttpserver && ./bootstrap && mkdir build cd libhttpserver/libhttpserver/build && LDFLAGS=-L$(shell pwd)/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/ CPPFLAGS=-I$(shell pwd)/libmicrohttpd/libmicrohttpd/src/include ../configure --disable-doxygen-doc --disable-doxygen-dot --disable-doxygen-man --disable-doxygen-html --enable-fastopen=false --disable-examples @@ -160,7 +161,7 @@ lz4: lz4/lz4/lib/liblz4.a clickhouse-cpp/clickhouse-cpp/clickhouse/libclickhouse-cpp-lib-static.a: cd clickhouse-cpp && rm -rf clickhouse-cpp-*/ || true - cd clickhouse-cpp && ln -fsT clickhouse-cpp-2.3.0 clickhouse-cpp + cd clickhouse-cpp && ln -fs clickhouse-cpp-2.3.0 clickhouse-cpp cd clickhouse-cpp && tar -zxf v2.3.0.tar.gz && sync cd clickhouse-cpp/clickhouse-cpp && patch clickhouse/base/wire_format.h < ../wire_format.patch cd clickhouse-cpp/clickhouse-cpp && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo . @@ -240,16 +241,21 @@ endif mariadb_client: mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a -sqlite3/sqlite3/sqlite3.o: +sqlite3/sqlite3/libsqlite3.so: cd sqlite3 && rm -rf sqlite-amalgamation-*/ || true cd sqlite3 && tar -zxf sqlite-amalgamation-*.tar.gz cd sqlite3/sqlite3 && patch -p1 < ../from_unixtime.patch cd sqlite3/sqlite3 && patch sqlite3.c < ../sqlite3.c-multiplication-overflow.patch cd sqlite3/sqlite3 && patch -p0 < ../sqlite3_pass_exts.patch cd sqlite3/sqlite3 && ${CC} ${MYCFLAGS} -fPIC -c -o sqlite3.o sqlite3.c -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_JSON1 -DSQLITE_DLL=1 + +ifeq ($(SYS_KERN),Darwin) + cd sqlite3/sqlite3 && ${CC} -shared -Wl,-U,_ERR_error_string -Wl,-U,_RAND_bytes -Wl,-U,_SHA1 -Wl,-U,_sha256_crypt_r -Wl,-U,_ERR_get_error -o libsqlite3.so sqlite3.o +else cd sqlite3/sqlite3 && ${CC} -shared -o libsqlite3.so sqlite3.o +endif -sqlite3: sqlite3/sqlite3/sqlite3.o +sqlite3: sqlite3/sqlite3/libsqlite3.so libconfig/libconfig/lib/.libs/libconfig++.a: @@ -280,13 +286,8 @@ re2/re2/obj/libre2.a: # cd re2/re2 && sed -i -e 's/-O3 -g /-O3 -fPIC /' Makefile # cd re2/re2 && patch util/mutex.h < ../mutex.h.patch cd re2/re2 && patch re2/onepass.cc < ../onepass.cc-multiplication-overflow.patch -ifeq ($(SYS_KERN),Darwin) - cd re2/re2 && sed -i '' -e 's/-O3 -g/-O3 -g -${STDCPP} -fPIC -DMEMORY_SANITIZER -DRE2_ON_VALGRIND /' Makefile -# cd re2/re2 && sed -i '' -e 's/RE2_CXXFLAGS?=-std=c++11 /RE2_CXXFLAGS?=-std=c++11 -fPIC /' Makefile -else cd re2/re2 && sed -i -e 's/-O3 -g/-O3 -g ${STDCPP} -fPIC -DMEMORY_SANITIZER -DRE2_ON_VALGRIND /' Makefile # cd re2/re2 && sed -i -e 's/RE2_CXXFLAGS?=-std=c++11 /RE2_CXXFLAGS?=-std=c++11 -fPIC /' Makefile -endif cd re2/re2 && CC=${CC} CXX=${CXX} ${MAKE} re2: re2/re2/obj/libre2.a @@ -331,4 +332,3 @@ cleanall: cd cityhash && rm -rf cityhash-*/ || true cd coredumper && rm -rf coredumper-*/ || true .PHONY: cleanall - diff --git a/deps/curl/configure.patch b/deps/curl/configure.patch index 1a60f5c559..292abd2d2a 100644 --- a/deps/curl/configure.patch +++ b/deps/curl/configure.patch @@ -1,18 +1,23 @@ -@@ -34014,7 +34014,7 @@ - else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +@@ -34590,7 +34590,7 @@ + else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 printf "%s\n" "failed" >&6; } - as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 -+# as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 - ++ #as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 + ;; + esac fi - rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ -@@ -34049,7 +34049,7 @@ - else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +@@ -34629,7 +34629,7 @@ + else case e in #( + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 printf "%s\n" "failed" >&6; } - as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 -+# as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 - ++ #as_fn_error $? "one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS" "$LINENO" 5 + ;; + esac fi - rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ +@@ -49329,4 +49329,3 @@ + WARNING: $experimental enabled but marked EXPERIMENTAL. Use with caution! + _EOF + fi +- diff --git a/deps/sqlite3/sqlite3_pass_exts.patch b/deps/sqlite3/sqlite3_pass_exts.patch index 467a363616..12a9853c5a 100644 --- a/deps/sqlite3/sqlite3_pass_exts.patch +++ b/deps/sqlite3/sqlite3_pass_exts.patch @@ -3,7 +3,7 @@ @@ -25168,6 +25168,183 @@ sqlite3ResultStrAccum(context, &sRes); } - + +#define DEF_SALT_SIZE 20 +#define SHA_DIGEST_LENGTH 20 + @@ -11,7 +11,7 @@ +//////////////////////////////////////////////////////////////////////////////// + +// ctype.h -+extern int toupper (int __c) __THROW; ++extern int toupper (int __c); + +// SHA256_crypt +char * sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen); diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index b2b2066fc3..faa6c8f5ba 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -106,7 +106,7 @@ class ProxySQL_GlobalVariables { bool restart_on_error; int restart_delay; std::mutex ssl_mutex; - SSL_CTX *ssl_ctx; + SSL_CTX *ssl_ctx; SSL_CTX *tmp_ssl_ctx; // these two buffers are used for the web interface char * ssl_key_pem_mem; @@ -121,9 +121,9 @@ class ProxySQL_GlobalVariables { char* gr_bootstrap_account; char* gr_bootstrap_account_create; char* gr_bootstrap_account_host; - uint64_t gr_bootstrap_password_retries; + unsigned long gr_bootstrap_password_retries; char* gr_bootstrap_conf_bind_address; - uint64_t gr_bootstrap_conf_base_port; + unsigned long gr_bootstrap_conf_base_port; bool gr_bootstrap_conf_use_sockets; bool gr_bootstrap_conf_skip_tcp; char* gr_bootstrap_ssl_ca; diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index 2e127e57c4..77b8ab4063 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -25,19 +25,12 @@ #define ETIME ETIMEDOUT #endif -#ifdef CXX17 -template struct conjunction : std::true_type { }; -template struct std::conjunction : B1 { }; -template -struct std::conjunction - : std::conditional, B1>::type {}; -#else template struct conjunction : std::true_type { }; template struct conjunction : B1 { }; template -struct conjunction +struct conjunction : std::conditional, B1>::type {}; -#endif // CXX17 + /** * @brief Stores the result of formatting the first parameter with the provided * arguments, into the std::string reference provided in the second parameter. diff --git a/lib/Makefile b/lib/Makefile index 58b17c29eb..798968c6fb 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -95,9 +95,9 @@ endif ### detect compiler support for c++11/17 -CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') +CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201703L) - CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') + CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201103L) $(error Compiler must support at least c++11) endif diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index b01c62f893..d3c5ff2312 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -319,7 +319,7 @@ void update_string_var_if_set(char** cur_val, ez::ezOptionParser* opt, const cha } } -void update_ulong_var_if_set(uint64_t& cur_val, ez::ezOptionParser* opt, const char* cmd_opt) { +void update_ulong_var_if_set(unsigned long& cur_val, ez::ezOptionParser* opt, const char* cmd_opt) { if (opt->isSet(cmd_opt)) { opt->get(cmd_opt)->getULong(cur_val); } diff --git a/lib/sha256crypt.cpp b/lib/sha256crypt.cpp index 1eafd5fb2b..873caa690b 100644 --- a/lib/sha256crypt.cpp +++ b/lib/sha256crypt.cpp @@ -1,7 +1,12 @@ /* SHA256-based Unix crypt implementation. Released into the Public Domain by Ulrich Drepper . */ -#include +#include +#if defined __APPLE__ + #include +#else + #include +#endif #include #include #include @@ -422,10 +427,13 @@ extern "C" char * sha256_crypt_r (const char *key, const char *salt, char *buffe sha256_finish_ctx (&alt_ctx, temp_result); /* Create byte sequence P. */ - cp = p_bytes = (char *)alloca (key_len); - for (cnt = key_len; cnt >= 32; cnt -= 32) - cp = (char *)mempcpy (cp, temp_result, 32); - memcpy (cp, temp_result, cnt); + cp = p_bytes = (char *)alloca(key_len); + char *p_copy = cp; + for (cnt = key_len; cnt >= 32; cnt -= 32) { + memcpy(cp, temp_result, 32); + cp += 32; + } + memcpy(cp, temp_result, cnt); /* Start computation of S byte sequence. */ sha256_init_ctx (&alt_ctx); @@ -438,10 +446,15 @@ extern "C" char * sha256_crypt_r (const char *key, const char *salt, char *buffe sha256_finish_ctx (&alt_ctx, temp_result); /* Create byte sequence S. */ - cp = s_bytes = (char *)alloca (salt_len); - for (cnt = salt_len; cnt >= 32; cnt -= 32) - cp = (char *) mempcpy (cp, temp_result, 32); - memcpy (cp, temp_result, cnt); + cp = s_bytes = (char *)alloca(salt_len); + char *cp_end = cp + salt_len; + for (cnt = salt_len; cnt >= 32; cnt -= 32) { + memcpy(cp, temp_result, 32); + cp += 32; + } + if (cnt > 0) { + memcpy(cp, temp_result, cnt); + } /* Repeatedly run the collected hash value through SHA256 to burn CPU cycles. */ diff --git a/src/Makefile b/src/Makefile index 40480140b9..363d810439 100644 --- a/src/Makefile +++ b/src/Makefile @@ -105,9 +105,9 @@ endif ### detect compiler support for c++11/17 -CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') +CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201703L) - CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL') + CPLUSPLUS := $(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | cut -d' ' -f3) ifneq ($(CPLUSPLUS),201103L) $(error Compiler must support at least c++11) endif @@ -158,8 +158,10 @@ endif MYCXXFLAGS := $(STDCPP) ifeq ($(CXX),clang++) +ifeq ($(UNAME_S),Linux) MYCXXFLAGS += -fuse-ld=lld endif +endif MYCXXFLAGS += $(IDIRS) $(OPTZ) $(DEBUG) $(PSQLCH) -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) $(WGCOV) $(WASAN) @@ -243,4 +245,3 @@ default: $(EXECUTABLE) clean: rm -rf *.pid $(ODIR)/*.o $(ODIR)/*.gcno $(ODIR)/*.gcda *~ core perf.data* heaptrack.proxysql.* $(EXECUTABLE) $(EXECUTABLE).sha1 $(ODIR) -