Skip to content

Commit

Permalink
Merge pull request #2506 from jimklimov/issue-2502
Browse files Browse the repository at this point in the history
Revise recipes for MacOS builds and general portability, and fix some `AX_REALPATH_LIB` aspects
  • Loading branch information
jimklimov authored Jul 4, 2024
2 parents 4bcaa70 + 0d9ab26 commit edf3c7e
Show file tree
Hide file tree
Showing 24 changed files with 759 additions and 150 deletions.
77 changes: 61 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ jobs:
BREW_MORE:
type: string
default: "" # e.g. "avahi" for all-driver tests
NUTCI_HOMEBREW_BASEDIR:
#HOMEBREW_PREFIX:
# Detected below at run-time
# See https://docs.brew.sh/Installation :
# * /opt/homebrew for Apple Silicon,
# * /usr/local for macOS Intel and
# * /home/linuxbrew/.linuxbrew for Linux
# TODO: Find a way to select one of the values based on the platform?
type: string
default: "/opt/homebrew" # since July 2024 CircleCI only serves Apple Silicon instances
#type: string
#default: "/opt/homebrew" # since July 2024 CircleCI only serves Apple Silicon instances
#default: "/usr/local" # was when CircleCI builders had x86

environment:
Expand All @@ -58,7 +59,7 @@ jobs:
BUILD_TYPE: << parameters.BUILD_TYPE >>
CI_BUILDDIR: << parameters.CI_BUILDDIR >>
BREW_MORE: << parameters.BREW_MORE >>
NUTCI_HOMEBREW_BASEDIR: << parameters.NUTCI_HOMEBREW_BASEDIR >>
#HOMEBREW_PREFIX: << parameters.HOMEBREW_PREFIX >>

# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
Expand All @@ -76,19 +77,42 @@ jobs:

# Note: MacOS default /bin/bash 3.x is too old for ci_build.sh
# Brew brings /usr/local/bin/bash 5.x as of this writing
# We also reinstall/relink openssl@3 because asciidoc deps pull
# in openssl@1 and MAYBE they conflict (cause lack of exposed
# symlinks).
- run:
name: "homebrew"
command: |-
HOMEBREW_NO_AUTO_UPDATE=1; export HOMEBREW_NO_AUTO_UPDATE;
brew install ccache bash libtool binutils autoconf automake git m4 pkg-config gd libusb neon net-snmp openssl $BREW_MORE
brew install ccache bash libtool binutils autoconf automake git m4 \
pkg-config aspell asciidoc docbook-xsl cppunit gd \
libusb neon net-snmp \
nss openssl \
libmodbus freeipmi powerman $BREW_MORE
#brew reinstall openssl@3
# https://github.com/Homebrew/legacy-homebrew/issues/15488
- run:
name: "homebrew-libtool"
name: "homebrew-relink"
command: |-
#find /usr /opt /lib* -name '*ltdl*' -ls 2>/dev/null || true
brew unlink libtool && brew link libtool
#find /usr /opt /lib* -name '*ltdl*' -ls 2>/dev/null || true
brew info openssl
#brew info openssl@3
#brew info [email protected]
#command -v pkg-config || true
#pkg-config --list-all || true
#HOMEBREW_PREFIX="`brew config | grep HOMEBREW_PREFIX: | awk '{print $2}'`"
#ls -la "${HOMEBREW_PREFIX}/lib/pkgconfig" || true
#ls -la "${HOMEBREW_PREFIX}/include/openssl" || true
#ls -la "${HOMEBREW_PREFIX}/include/openssl"/* || true
#find "${HOMEBREW_PREFIX}"/Cellar/openssl* -ls || true
pkg-config --libs --cflags nss
pkg-config --libs --cflags openssl || {
brew unlink openssl && brew link --force openssl
pkg-config --libs --cflags openssl ; }
brew unlink net-snmp && brew link --force net-snmp
- restore_cache:
keys:
Expand Down Expand Up @@ -124,11 +148,10 @@ jobs:
- run:
name: "ci_build"
command: |-
CI_CCACHE_SYMLINKDIR="${NUTCI_HOMEBREW_BASEDIR}/opt/ccache/libexec" \
HOMEBREW_PREFIX="`brew config | grep HOMEBREW_PREFIX: | awk '{print $2}'`" \
CANBUILD_NIT_TESTS=yes \
CFLAGS="$CC_STDVER -Wno-poison-system-directories -Wno-deprecated-declarations -I${NUTCI_HOMEBREW_BASEDIR}/include" \
CXXFLAGS="$CXX_STDVER -Wno-poison-system-directories -I${NUTCI_HOMEBREW_BASEDIR}/include" \
LDFLAGS="-L${NUTCI_HOMEBREW_BASEDIR}/lib -L/usr/local/lib" \
CFLAGS="$CC_STDVER" \
CXXFLAGS="$CXX_STDVER" \
./ci_build.sh
- run:
Expand All @@ -150,6 +173,9 @@ jobs:
- store_artifacts:
path: config.log

- store_artifacts:
path: config.nut_report_feature.log


# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
Expand All @@ -158,6 +184,7 @@ workflows:
jobs:
# Note: while "ccache" lists hordes of symlinks to gcc-XXX versions,
# in practice these toolkits are not installed (by default)
# or actually identify as clang

### This scenario is a subset of fightwarn-all below (modulo C standard),
### so disabled to not waste time from free CircleCI allowance limit:
Expand All @@ -169,19 +196,37 @@ workflows:
# CC_STDVER: "-std=gnu17"
# CXX_STDVER: "-std=gnu++17"

# - osx-xcode:
# name: "gnu11-gcc-xcode13_4_1-out-of-tree"
# CC: "gcc"
# CXX: "g++"
# CC_STDVER: "-std=gnu11"
# CXX_STDVER: "-std=gnu++11"
# # Try an out-of-tree build:
# CI_BUILDDIR: "obj"

# - osx-xcode:
# name: "c99-cxx11-gcc-xcode13_4_1-default-distcheck"
# CC: "gcc"
# CXX: "g++"
# CC_STDVER: "-std=c99"
# CXX_STDVER: "-std=c++11"
# # Try usual and distchecked build:
# BUILD_TYPE: "default"

- osx-xcode:
name: "gnu11-gcc-xcode13_4_1-out-of-tree"
CC: "gcc"
CXX: "g++"
name: "gnu11-clang-xcode13_4_1-out-of-tree"
CC: "clang"
CXX: "clang++"
CC_STDVER: "-std=gnu11"
CXX_STDVER: "-std=gnu++11"
# Try an out-of-tree build:
CI_BUILDDIR: "obj"

- osx-xcode:
name: "c99-cxx11-gcc-xcode13_4_1-default-distcheck"
CC: "gcc"
CXX: "g++"
name: "c99-cxx11-clang-xcode13_4_1-default-distcheck"
CC: "clang"
CXX: "clang++"
CC_STDVER: "-std=c99"
CXX_STDVER: "-std=c++11"
# Try usual and distchecked build:
Expand Down
5 changes: 5 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ installed.
of more complex configurations (e.g. some line patterns that involve too
many double-quote characters) which are valid for NUT proper. [#657]
- NUT CI farm build recipes, documentation and some `m4`/`configure.ac`
sources updated to handle a much larger build scope on MacOS. Also
migrated the builders to Apple Silicon from x86 (deprecated by CircleCI).
[#2502]
Release notes for NUT 2.8.2 - what's new since 2.8.1
----------------------------------------------------
Expand Down
83 changes: 71 additions & 12 deletions ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,22 @@ fi
# (note: a "-" value requests to NOT use a CI_CCACHE_SYMLINKDIR;
# ccache may still be used via prefixing if the tool is found in
# the PATH, unless you export CI_CCACHE_USE=no also):
if [ -z "${CI_CCACHE_SYMLINKDIR-}" ] ; then
for D in \
propose_CI_CCACHE_SYMLINKDIR() {
echo \
"/usr/lib/ccache" \
"/mingw64/lib/ccache/bin" \
"/mingw32/lib/ccache/bin" \
"/usr/lib64/ccache" \
"/usr/libexec/ccache" \
"/usr/lib/ccache/bin" \
"/usr/local/lib/ccache" \
; do
"/usr/local/lib/ccache"

if [ -n "${HOMEBREW_PREFIX-}" ]; then
echo "${HOMEBREW_PREFIX}/opt/ccache/libexec"
fi
}
if [ -z "${CI_CCACHE_SYMLINKDIR-}" ] ; then
for D in `propose_CI_CCACHE_SYMLINKDIR` ; do
if [ -d "$D" ] ; then
if ( ls -la "$D" | grep -e ' -> .*ccache' >/dev/null) \
|| ( test -n "`find "$D" -maxdepth 1 -type f -exec grep -li ccache '{}' \;`" ) \
Expand Down Expand Up @@ -992,14 +998,6 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
fi
fi

# Note: Potentially there can be spaces in entries for multiple
# *FLAGS here; this should be okay as long as entry expands to
# one token when calling shell (may not be the case for distcheck)
CONFIG_OPTS+=("CFLAGS=-I${BUILD_PREFIX}/include ${CFLAGS}")
CONFIG_OPTS+=("CPPFLAGS=-I${BUILD_PREFIX}/include ${CPPFLAGS}")
CONFIG_OPTS+=("CXXFLAGS=-I${BUILD_PREFIX}/include ${CXXFLAGS}")
CONFIG_OPTS+=("LDFLAGS=-L${BUILD_PREFIX}/lib ${LDFLAGS}")

DEFAULT_PKG_CONFIG_PATH="${BUILD_PREFIX}/lib/pkgconfig"
SYSPKG_CONFIG_PATH="" # Let the OS guess... usually
case "`echo "$CI_OS_NAME" | tr 'A-Z' 'a-z'`" in
Expand All @@ -1023,6 +1021,59 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
;;
esac
;;
*darwin*|*macos*|*osx*)
# Architecture-dependent base dir, e.g.
# * /usr/local on macos x86
# * /opt/homebrew on macos Apple Silicon
if [ -n "${HOMEBREW_PREFIX-}" -a -d "${HOMEBREW_PREFIX-}" ]; then
SYS_PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/lib/pkgconfig"
CFLAGS="${CFLAGS-} -Wno-poison-system-directories -Wno-deprecated-declarations -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
#CPPFLAGS="${CPPFLAGS-} -Wno-poison-system-directories -Wno-deprecated-declarations -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
CXXFLAGS="${CXXFLAGS-} -Wno-poison-system-directories -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
LDFLAGS="${LDFLAGS-} -L${HOMEBREW_PREFIX}/lib"

# Net-SNMP "clashes" with system-provided tools (but no header/lib)
# so explicit args are needed
checkFSobj="${HOMEBREW_PREFIX}/opt/net-snmp/lib/pkgconfig"
if [ -d "$checkFSobj" -a ! -e "${HOMEBREW_PREFIX}/lib/pkgconfig/netsnmp.pc" ] ; then
echo "Homebrew: export flags for Net-SNMP"
SYS_PKG_CONFIG_PATH="$SYS_PKG_CONFIG_PATH:$checkFSobj"
#CONFIG_OPTS+=("--with-snmp-includes=-isystem ${HOMEBREW_PREFIX}/opt/net-snmp/include -I${HOMEBREW_PREFIX}/opt/net-snmp/include")
#CONFIG_OPTS+=("--with-snmp-libs=-L${HOMEBREW_PREFIX}/opt/net-snmp/lib")
fi

if [ -d "${HOMEBREW_PREFIX}/opt/net-snmp/include" -a -d "${HOMEBREW_PREFIX}/include/openssl" ]; then
# TODO? Check netsnmp.pc for Libs.private with
# -L/opt/homebrew/opt/[email protected]/lib
# or
# -L/usr/local/opt/openssl@3/lib
# among other options to derive the exact version
# it wants, and serve that include path here
echo "Homebrew: export configure options for Net-SNMP with default OpenSSL headers (too intimate on Homebrew)"
CONFIG_OPTS+=("--with-snmp-includes=-isystem ${HOMEBREW_PREFIX}/opt/net-snmp/include -I${HOMEBREW_PREFIX}/opt/net-snmp/include -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include")
CONFIG_OPTS+=("--with-snmp-libs=-L${HOMEBREW_PREFIX}/opt/net-snmp/lib -lnetsnmp")
fi

# A bit hackish to check this outside `configure`, but...
if [ -s "${HOMEBREW_PREFIX-}/include/ltdl.h" ] ; then
echo "Homebrew: export flags for LibLTDL"
# The m4 script clear default CFLAGS/LIBS so benefit from new ones
CONFIG_OPTS+=("--with-libltdl-includes=-isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include")
CONFIG_OPTS+=("--with-libltdl-libs=-L${HOMEBREW_PREFIX}/lib -lltdl")
fi

if [ -z "${XML_CATALOG_FILES-}" ] ; then
checkFSobj="${HOMEBREW_PREFIX}/etc/xml/catalog"
if [ -e "$checkFSobj" ] ; then
echo "Homebrew: export XML_CATALOG_FILES='$checkFSobj' for asciidoc et al"
XML_CATALOG_FILES="$checkFSobj"
export XML_CATALOG_FILES
fi
fi
else
echo "WARNING: It seems you are building on MacOS, but HOMEBREW_PREFIX is not set or valid; it can help with auto-detection of some features!"
fi
;;
esac
if [ -n "$SYS_PKG_CONFIG_PATH" ] ; then
if [ -n "$PKG_CONFIG_PATH" ] ; then
Expand All @@ -1037,6 +1088,14 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
CONFIG_OPTS+=("PKG_CONFIG_PATH=${DEFAULT_PKG_CONFIG_PATH}")
fi

# Note: Potentially there can be spaces in entries for multiple
# *FLAGS here; this should be okay as long as entry expands to
# one token when calling shell (may not be the case for distcheck)
CONFIG_OPTS+=("CFLAGS=-I${BUILD_PREFIX}/include ${CFLAGS}")
CONFIG_OPTS+=("CPPFLAGS=-I${BUILD_PREFIX}/include ${CPPFLAGS}")
CONFIG_OPTS+=("CXXFLAGS=-I${BUILD_PREFIX}/include ${CXXFLAGS}")
CONFIG_OPTS+=("LDFLAGS=-L${BUILD_PREFIX}/lib ${LDFLAGS}")

CONFIG_OPTS+=("--enable-keep_nut_report_feature")
CONFIG_OPTS+=("--prefix=${BUILD_PREFIX}")
CONFIG_OPTS+=("--sysconfdir=${BUILD_PREFIX}/etc/nut")
Expand Down
Loading

0 comments on commit edf3c7e

Please sign in to comment.