Skip to content

Commit

Permalink
Merge pull request pistacheio#1263 from dgreatwood/macOSRealGccRunners
Browse files Browse the repository at this point in the history
Feat: Enable GCC Builds on macOS and in macos.yaml Workflow
  • Loading branch information
kiplingw authored Nov 21, 2024
2 parents e27dcc5 + 8baf4d9 commit fcf8a58
Show file tree
Hide file tree
Showing 34 changed files with 377 additions and 134 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,24 @@ jobs:
sanitizer: [ 'address', 'undefined', 'none' ]
tls: [ 'true', 'false' ]
def_debug: [ 'true', 'false' ]
exclude:
# GCC on macOS doesn't seem to have library asan or ubsan
- compiler: gcc
sanitizer: address
- compiler: gcc
sanitizer: undefined

runs-on: ${{ matrix.os }}

steps:
- name: Install dependencies (macOS)
if: contains(matrix.os, 'macos')
run: |
if [ ${{ matrix.compiler }} = gcc ]; then compiler=g++; else compiler="clang lld ?exact-name(libclang-rt-dev)"; fi
# Avoid doing "brew update" - the brew formulas that are
# preinstalled on the github runner image are likely
# consistent with the pre-installed software on the image. If
# we do "brew upate", and then install something new with
# we do "brew update", and then install something new with
# brew, and the "something new" depends on pre-installed
# software on the image, and there are new versions of the
# pre-installed software revealed by doing "brew update", then
Expand All @@ -63,7 +68,9 @@ jobs:
brew install lcov
brew install --quiet --cask doxygen
brew install googletest
if [ ${{ matrix.compiler }} != gcc ]; then
brew install googletest
fi
# brew install openssl # Already installed in base image
brew install rapidjson
# brew install libevent # Already installed in base image
Expand All @@ -75,8 +82,14 @@ jobs:

- name: Configure Meson
run: |
if [ ${{ matrix.compiler }} = gcc ]; then CXX=g++; else CXX=clang++; fi
export CXX
if [ ${{ matrix.compiler }} = gcc ]; then
source bldscripts/gccmacsetup.sh -y
else
export CXX=clang++
export CC=CXX
fi
echo "Using CXX $CXX, and CC $CC"
meson setup build \
-DPISTACHE_BUILD_TESTS=true -DPISTACHE_DEBUG=${{ matrix.def_debug }} -DPISTACHE_USE_SSL=${{ matrix.tls }} -DPISTACHE_BUILD_EXAMPLES=true -DPISTACHE_BUILD_DOCS=false -DPISTACHE_USE_CONTENT_ENCODING_DEFLATE=true \
--buildtype=debug -Db_coverage=true -Db_sanitize=${{ matrix.sanitizer }} -Db_lundef=false \
Expand Down Expand Up @@ -115,4 +128,3 @@ jobs:
sha256sum --check codecov.SHA256SUM
chmod +x codecov
./codecov
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Build files
/*build*/
/tests/build*/
/googletest/

# Soft links to favorite build convenience files
/build.sh
Expand Down
21 changes: 15 additions & 6 deletions Building on macOS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ follow the Homebrew instructions to install:
Then, install the necessary brew packages via terminal command line:
brew install meson
brew install doxygen
brew install googletest
brew install googletest (skip this if installing with gcc - see later)
brew install openssl
brew install rapidjson
brew install howard-hinnant-date
Expand All @@ -34,21 +34,30 @@ The meaning of each convenience script is as follows:
mesbuild.sh - build release version using meson
mestest.sh - test release version using meson
mesinstall.sh - install release version using meson

mesbuilddebug.sh - build debug version using meson
mestestdebug.sh - test debug version with meson
mesinstalldebug.sh - install debug version using meson

mesbuildflibev.sh - build version using meson forcing libevnet use
mestestflibev.sh - test version using meson with libevnet use
mestestflibev.sh - test version using meson with libevnet use
mesinstallflibev.sh - install version using meson with libevnet use

mesbuildflibevdebug.sh - build debug ver using meson forcing libevnet use
mestestflibevdebug.sh - test debug ver using meson with libevnet use
mestestflibevdebug.sh - test debug ver using meson with libevnet use
mesinstallflibevdebug.sh - install debug ver using meson with libevnet use

clean.sh - remove build directories



Building with GCC
-----------------

By default, Pistache on macOS builds with clang, which is the default
Apple compiler. If you prefer to use gcc, you can utilize the
gccmacsetup.sh script provided by Pistache before doing the build,
like this:
source bldscripts/gccmacsetup.sh
bldscripts/mesbuild.sh
bldscripts/mestest.sh
bldscripts/mesinstall.sh
17 changes: 11 additions & 6 deletions bldscripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@
# Execute this script from the parent directory by invoking:
# bldscripts/clean.sh

source bldscripts/messetdirvars.sh
if [ -e "./${MESON_BUILD_DIR}" ]
MY_SCRIPT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source $MY_SCRIPT_DIR/helpers/messetdirvars.sh
source $MY_SCRIPT_DIR/helpers/adjbuilddirformesbuild.sh

if [ -e "${MESON_BUILD_DIR}" ]
then
rm -rf ${MESON_BUILD_DIR}
fi

source bldscripts/mesdebugsetdirvars.sh
if [ -e "./${MESON_BUILD_DIR}" ]
source $MY_SCRIPT_DIR/helpers/mesdebugsetdirvars.sh
source $MY_SCRIPT_DIR/helpers/adjbuilddirformesbuild.sh
if [ -e "${MESON_BUILD_DIR}" ]
then
rm -rf ${MESON_BUILD_DIR}
fi

source bldscripts/cmksetdirvars.sh
source $MY_SCRIPT_DIR/helpers/cmksetdirvars.sh
if [ -e "./${CMAKE_BUILD_DIR}" ]
then
rm -rf ${CMAKE_BUILD_DIR}
fi

source bldscripts/cmkdebugsetdirvars.sh
source $MY_SCRIPT_DIR/helpers/cmkdebugsetdirvars.sh
if [ -e "./${CMAKE_BUILD_DIR}" ]
then
rm -rf ${CMAKE_BUILD_DIR}
Expand Down
4 changes: 3 additions & 1 deletion bldscripts/cmkbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# To install (must be run from build directory):
# sudo make install

source bldscripts/cmksetdirvars.sh
MY_SCRIPT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source $MY_SCRIPT_DIR/helpers/cmksetdirvars.sh

if [ -e "./${CMAKE_BUILD_DIR}" ]
then
Expand Down
4 changes: 3 additions & 1 deletion bldscripts/cmkbuilddebug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# To install (must be run from build.debug directory):
# sudo make install

source bldscripts/cmkdebugsetdirvars.sh
MY_SCRIPT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source $MY_SCRIPT_DIR/helpers/cmkdebugsetdirvars.sh

if [ -e "./${CMAKE_BUILD_DIR}" ]
then
Expand Down
106 changes: 106 additions & 0 deletions bldscripts/gccmacsetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

#
# SPDX-FileCopyrightText: 2024 Duncan Greatwood
#
# SPDX-License-Identifier: Apache-2.0
#

# This script configures gcc on macOS. You should call it in each
# terminal from which you'll build Pistache with gcc.
# - Installs gcc if not yet installed
# - Configures the CXX and CC environment variables
# - Replaces brew googletest if needed and on user confirmation
#
# Use "source ..." to invoke the script, like:
# source bldscripts/gccmacsetup.sh
#
# Add the "-y' option to proceed to replace brew googletest if needed
# without prompting for confirmation, like this:
# source bldscripts/gccmacsetup.sh -y

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "Error: script was invoked directly, please invoke with source."
echo "Like this:"
echo " source $(printf %q "$BASH_SOURCE")$((($#)) && printf ' %q' "$@")"
exit 1
fi

if [ "$(uname)" != "Darwin" ]; then
echo "Error: This script is for use solely on macOS"
return 1
fi

if ! type "brew" > /dev/null; then
echo "Error: brew command not found. Please install Homebrew."
return 1
fi

gcc_installed_here="N"
if ! brew list gcc &>/dev/null; then
echo "Installing gcc with brew"
brew install gcc
gcc_installed_here="Y"
fi

if ! [ "x$CXX" = "x" ] && [ ${#CXX} -ge 6 ]; then
if [ ${CXX:0:4} = g++- ] || [ ${CXX:0:4} = gcc- ]; then
if [ "x$gcc_installed_here" = "xY" ]; then
echo "Success: gcc installed and configured"
else
echo "Success: gcc already configured, exiting"
fi
return 0
fi
fi

gcc_lns=`brew list gcc | grep "bin/g++-[0-9][0-9]" | sort -r`
gcc_fstln=`echo "$gcc_lns" | head -1`
export CXX=`basename $gcc_fstln`
if [ "x$CXX" = "x" ] || [ ${#CXX} -lt 6 ] || ! [ ${CXX:0:4} = g++- ]; then
echo "Error: CXX (which has value: $CXX) not configured"
return 1
fi

gcc_lns=`brew list gcc | grep "bin/gcc-[0-9][0-9]" | sort -r`
gcc_fstln=`echo "$gcc_lns" | head -1`
export CC=`basename $gcc_fstln`
if [ "x$CC" = "x" ] || [ ${#CC} -lt 6 ] || ! [ ${CC:0:4} = gcc- ]; then
echo "Error: CC (which has value: $CC) not configured"
return 1
fi

echo "Success: CXX is $CXX; CC is $CC"

if brew list googletest &>/dev/null; then
echo ""
echo "You have brew's googletest installed"
echo "Brew's googletest may not be compatible with building with gcc"
replace_gt="N"
if [ $# -ge 1 ] && [ $1 = "-y" ]; then
replace_gt="Y"
else
read -e -p \
'Replace googletest with gcc-compatible version (uses sudo)? [y/N]> '
if [[ "$REPLY" == [Yy]* ]]; then
replace_gt="Y"
fi
fi
if [ "x$replace_gt" = "xY" ]; then
echo "Replacing googletest"
brew remove googletest

git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
echo ""
echo "Installing gcc-compatible googletest using \"sudo make install\""
sudo make install
cd "../.."
else
echo "You may see undefined symbols if linking Pistache's tests"
fi
fi
42 changes: 42 additions & 0 deletions bldscripts/helpers/adjbuilddirformesbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Bash Script (for sourcing)

#
# SPDX-FileCopyrightText: 2024 Duncan Greatwood
#
# SPDX-License-Identifier: Apache-2.0
#

# Do not execute this script directly. In can be sourced into other
# scripts that need it.

# This script checks for the existence of a directory
# "~/mesbuild/<project-dir>"; if that directory exists,
# $MESON_BUILD_DIR is set to point to a subdirectory within it. In
# this way, if desired we can keep the build dir well away from the
# sources.

# On macOS, it also checks if we're building with gcc, and, if we are,
# it appends ".gcc" to MESON_BUILD_DIR.

if [ ! "x$HOME" = "x" ]; then
if [ -d "$HOME/mesbuild" ]; then
gitprojroot=$(git rev-parse --show-toplevel)
if [ ! "x$gitprojroot" = "x" ] && [ -d "$gitprojroot" ]; then
gitprojrootleaf=$(basename $gitprojroot)
bldpathbase="$HOME/mesbuild/$gitprojrootleaf"
if [ -d "$bldpathbase" ]; then
MESON_BUILD_DIR="$bldpathbase/$MESON_BUILD_DIR"
else
echo "Create dir $bldpathbase if you prefer to build there"
fi
fi
fi
fi

if [ "$(uname)" = "Darwin" ]; then
if ! [ "x$CXX" = "x" ] && [ ${#CXX} -ge 6 ]; then
if [ ${CXX:0:4} = g++- ] || [ ${CXX:0:4} = gcc- ]; then
MESON_BUILD_DIR="$MESON_BUILD_DIR.gcc"
fi
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Sets CMAKE_BUILD_DIR and CMAKE_PREFIX_DIR
#
# Use by:
# source bldscripts/cmkdebugsetdirvars.sh
# source helpers/cmkdebugsetdirvars.sh


MY_ARCH_NM=x86
Expand All @@ -19,7 +19,7 @@ else
MY_ARCH_NM=a64
fi
fi


if [ "$(uname)" == "Darwin" ]; then
CMAKE_BUILD_DIR=build${MY_ARCH_NM}.cmk.mac.debug
Expand All @@ -28,4 +28,3 @@ else
CMAKE_BUILD_DIR=build${MY_ARCH_NM}.cmk.debug
CMAKE_PREFIX_DIR=/usr/local
fi

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Sets CMAKE_BUILD_DIR and CMAKE_PREFIX_DIR
#
# Use by:
# source bldscripts/cmksetdirvars.sh
# source helpers/cmksetdirvars.sh


MY_ARCH_NM=x86
Expand All @@ -19,7 +19,7 @@ else
MY_ARCH_NM=a64
fi
fi


if [ "$(uname)" == "Darwin" ]; then
CMAKE_BUILD_DIR=build${MY_ARCH_NM}.cmk.mac
Expand All @@ -28,4 +28,3 @@ else
CMAKE_BUILD_DIR=build${MY_ARCH_NM}.cmk
CMAKE_PREFIX_DIR=/usr/local
fi

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
# Sets MESON_BUILD_DIR and MESON_PREFIX_DIR
#
# Use by:
# source bldscripts/mesdebugflibevsetdirvars.sh
# source helpers/mesdebugflibevsetdirvars.sh

MY_HELPER_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [ "$(uname)" == "Darwin" ]; then
echo "Error: Don't force libevent on macOS, libevent is on by default"
Expand All @@ -26,4 +28,4 @@ if [ "$(uname)" == "NetBSD" ]; then
fi

PST_DIR_SUFFIX=".flibev.debug"
source bldscripts/messetdirvarsfinish.sh
source $MY_HELPER_DIR/messetdirvarsfinish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
# Sets MESON_BUILD_DIR and MESON_PREFIX_DIR
#
# Use by:
# source bldscripts/mesdebugsetdirvars.sh
# source helpers/mesdebugsetdirvars.sh

PST_DIR_SUFFIX=".debug"
source bldscripts/messetdirvarsfinish.sh
MY_HELPER_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

PST_DIR_SUFFIX=".debug"
source $MY_HELPER_DIR/messetdirvarsfinish.sh
Loading

0 comments on commit fcf8a58

Please sign in to comment.