Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build on darwin #4527

Open
wants to merge 10 commits into
base: v2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/CI-darwin.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ core
#config
proxysql.cnf*
proxysql.db*
proxysql-*.pem

jeprof*heap
perf.data*
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
32 changes: 16 additions & 16 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 .
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -331,4 +332,3 @@ cleanall:
cd cityhash && rm -rf cityhash-*/ || true
cd coredumper && rm -rf coredumper-*/ || true
.PHONY: cleanall

29 changes: 17 additions & 12 deletions deps/curl/configure.patch
Original file line number Diff line number Diff line change
@@ -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
-
4 changes: 2 additions & 2 deletions deps/sqlite3/sqlite3_pass_exts.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
@@ -25168,6 +25168,183 @@
sqlite3ResultStrAccum(context, &sRes);
}

+#define DEF_SALT_SIZE 20
+#define SHA_DIGEST_LENGTH 20
+
+/// Forward declarations
+////////////////////////////////////////////////////////////////////////////////
+
+// 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);
Expand Down
6 changes: 3 additions & 3 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 2 additions & 9 deletions include/proxysql_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
#define ETIME ETIMEDOUT
#endif

#ifdef CXX17
template<class...> struct conjunction : std::true_type { };
template<class B1> struct std::conjunction<B1> : B1 { };
template<class B1, class... Bn>
struct std::conjunction<B1, Bn...>
: std::conditional<bool(B1::value), std::conjunction<Bn...>, B1>::type {};
#else
template<class...> struct conjunction : std::true_type { };
shyim marked this conversation as resolved.
Show resolved Hide resolved
template<class B1> struct conjunction<B1> : B1 { };
template<class B1, class... Bn>
struct conjunction<B1, Bn...>
struct conjunction<B1, Bn...>
: std::conditional<bool(B1::value), conjunction<Bn...>, 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.
Expand Down
4 changes: 2 additions & 2 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ProxySQL_GloVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 22 additions & 9 deletions lib/sha256crypt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* SHA256-based Unix crypt implementation.
Released into the Public Domain by Ulrich Drepper <[email protected]>. */

#include <endian.h>
#include <cstring>
#if defined __APPLE__
#include <machine/endian.h>
#else
#include <endian.h>
shyim marked this conversation as resolved.
Show resolved Hide resolved
#endif
#include <errno.h>
#include <limits.h>
#include <stdint.h>
Expand Down Expand Up @@ -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);
shyim marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand All @@ -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. */
Expand Down
7 changes: 4 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)