From 70573f3d92a64d6a52c50057286691e457adab0f Mon Sep 17 00:00:00 2001 From: Yongting You <2010youy01@gmail.com> Date: Mon, 20 Mar 2023 12:48:16 -0700 Subject: [PATCH] MacOS X support Signed-off-by: Yongting You <2010youy01@gmail.com> --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++++- AUTHORS | 3 +- CMakeLists.txt | 1 + src/CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++------ src/libpgagroal/utils.c | 4 +-- src/main.c | 4 +-- 6 files changed, 101 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ec4b3a0..fb1429ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - master jobs: - build: + build-linux: runs-on: ubuntu-latest @@ -46,3 +46,45 @@ jobs: - name: CLANG/make run: make working-directory: /home/runner/work/pgagroal/pgagroal/build/ + + + + build-macos: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - name: Install Homebrew + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" + - name: Update system + run: brew update + - name: Install openssl + run: brew install openssl + - name: Install libev + run: brew install libev + - name: Install rst2man + run: brew install docutils + - name: Install clang + run: brew install llvm + - name: GCC/mkdir + run: mkdir build + working-directory: /Users/runner/work/pgagroal/pgagroal/ + - name: GCC/cmake + run: export CC=/usr/bin/gcc && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug .. + working-directory: /Users/runner/work/pgagroal/pgagroal/build/ + - name: GCC/make + run: make + working-directory: /Users/runner/work/pgagroal/pgagroal/build/ + - name: rm -Rf + run: rm -Rf build/ + working-directory: /Users/runner/work/pgagroal/pgagroal/ + - name: CLANG/mkdir + run: mkdir build + working-directory: /Users/runner/work/pgagroal/pgagroal/ + - name: CLANG/cmake + run: export CC=/usr/bin/clang && export OPENSSL_ROOT_DIR=`brew --prefix openssl` && cmake -DCMAKE_BUILD_TYPE=Debug .. + working-directory: /Users/runner/work/pgagroal/pgagroal/build/ + - name: CLANG/make + run: make + working-directory: /Users/runner/work/pgagroal/pgagroal/build/ diff --git a/AUTHORS b/AUTHORS index 6396f9c4..7a805e7d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,4 +6,5 @@ Will Leinweber Junduo Dong Luca Ferrari Nikita Bugrovsky -Lawrence Wu \ No newline at end of file +Lawrence Wu +Yongting You <2010youy01@gmail.com> diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fc6836e..94c34ae8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ message(STATUS "pgagroal ${VERSION_STRING}") include(CheckCCompilerFlag) include(CheckCSourceCompiles) +include(CheckLinkerFlag) include(FindPackageHandleStandardArgs) include(GNUInstallDirs) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e28102e6..51ce9027 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,48 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") ) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + find_program(HOMEBREW_EXECUTABLE brew) + if(EXISTS ${HOMEBREW_EXECUTABLE}) + execute_process( + COMMAND ${HOMEBREW_EXECUTABLE} --prefix + OUTPUT_VARIABLE HOMEBREW_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Homebrew found at ${HOMEBREW_PREFIX}") + endif() + + # + # Detecting OpenSSL + # + execute_process( + COMMAND ${HOMEBREW_EXECUTABLE} --prefix openssl + OUTPUT_VARIABLE HOMEBREW_OPENSSL + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(DEFINED HOMEBREW_OPENSSL) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${HOMEBREW_OPENSSL}/include") + else() + message(FATAL_ERROR "Homebrew's OpenSSL needed") + endif() + add_compile_options(-D_DARWIN_C_SOURCE) + add_compile_options(-DHAVE_OSX) + + # + # Include directories + # + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${LIBEV_INCLUDE_DIRS} + ${OPENSSL_INCLUDE_DIRS} + ) + + # + # Library directories + # + link_libraries( + ${LIBEV_LIBRARIES} + ${OPENSSL_LIBRARIES} + ) else() add_compile_options(-D_XOPEN_SOURCE=700) @@ -137,14 +178,15 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) endif() endif() - check_c_compiler_flag(-Wl,-z,relro HAS_RELRO) - if (HAS_RELRO) + check_c_compiler_flag(-Wl,arg HAS_LINKER) + check_linker_flag(C "-z relro" LINKER_HAS_RELRO) + if (HAS_LINKER AND LINKER_HAS_RELRO) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro") endif() - check_c_compiler_flag(-Wl,-z,now HAS_NOW) - if (HAS_NOW) + check_linker_flag(C "-z now" LINKER_HAS_NOW) + if (HAS_LINKER AND LINKER_HAS_NOW) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,now") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now") endif() @@ -199,14 +241,15 @@ if (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) endif() endif() - check_c_compiler_flag(-Wl,-z,relro HAS_RELRO) - if (HAS_RELRO) + check_c_compiler_flag(-Wl,arg HAS_LINKER) + check_linker_flag(C "-z relro" LINKER_HAS_RELRO) + if (HAS_LINKER AND HAS_RELRO) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro") endif() - check_c_compiler_flag(-Wl,-z,now HAS_NOW) - if (HAS_NOW) + check_linker_flag(C "-z now" LINKER_HAS_NOW) + if (HAS_LINKER AND LINKER_HAS_NOW) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,now") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now") endif() diff --git a/src/libpgagroal/utils.c b/src/libpgagroal/utils.c index 0949e6e5..c3498c3a 100644 --- a/src/libpgagroal/utils.c +++ b/src/libpgagroal/utils.c @@ -54,7 +54,7 @@ #endif extern char** environ; -#ifdef HAVE_LINUX +#if defined(HAVE_LINUX) || defined(HAVE_OSX) static bool env_changed = false; static int max_process_title_size = 0; #endif @@ -719,7 +719,7 @@ pgagroal_base64_decode(char* encoded, size_t encoded_length, char** raw, int* ra void pgagroal_set_proc_title(int argc, char** argv, char* s1, char* s2) { -#ifdef HAVE_LINUX +#if defined(HAVE_LINUX) || defined(HAVE_OSX) char title[MAX_PROCESS_TITLE_LENGTH]; size_t size; char** env = environ; diff --git a/src/main.c b/src/main.c index a1b64781..49908307 100644 --- a/src/main.c +++ b/src/main.c @@ -841,9 +841,9 @@ main(int argc, char** argv) #ifdef HAVE_LINUX sd_notifyf(0, "STATUS=max_connections is larger than the file descriptor limit (%ld available)", - flimit.rlim_cur - 30); + (long)(flimit.rlim_cur - 30)); #endif - errx(1, "max_connections is larger than the file descriptor limit (%ld available)", flimit.rlim_cur - 30); + errx(1, "max_connections is larger than the file descriptor limit (%ld available)", (long)(flimit.rlim_cur - 30)); } if (daemon)