Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
More updates to build scripts for more stable Mac build
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 31, 2023
1 parent 4ac2275 commit be7283e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 47 deletions.
11 changes: 1 addition & 10 deletions buildscripts/_build_getopts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,9 @@ done

read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)
BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build)}
if [ $OS = "MacOSX" ]; then
printf "MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET}\n"
PREFIX=${PREFIX:-${BUILD_DIR}/${OS}${MACOSX_DEPLOYMENT_TARGET}/${ARCH}}
else
PREFIX=${PREFIX:-${BUILD_DIR}/${OS}/${ARCH}}
fi

PREFIX=${PREFIX:-${ROOT_DIR}}
DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}/downloads}

printf "DEPENDENCY_DIR: ${DEPENDENCY_DIR}\n"
printf "PREFIX : ${PREFIX}\n"

if [ -z ${DEPENDENCY_ENV_VARS+x} ]; then
. ${SCRIPT_DIR}/set_compilers.sh

Expand Down
35 changes: 35 additions & 0 deletions buildscripts/build_macwheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# This script will build all versions of the MacOS wheels, for both Apple Silicon (arm64) and Intel (x86_64) and for a variety
# of OS versions.
#
# Copyright 2023 - David Minton
# This file is part of Swiftest.
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.
set -a
SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)
BUILD_DIR=$(mktemp -ut swiftest_build)
PREFIX=${ROOT_DIR}
DEPENDENCY_DIR=${BUILD_DIR}/downloads

# The versions of MacOS that we have development tools for
declare -a MACVER=("10.13" "11.0" "12.4" "13.0")

for MACOSX_DEPLOYMENT_TARGET in "${MACVER[@]}"; do
ARGS="-p ${PREFIX} -d ${DEPENDENCY_DIR} -m ${MACOSX_DEPLOYMENT_TARGET}"
if [ "${MACOSX_DEPLOYMENT_TARGET}" != "10.13" ]; then
${SCRIPT_DIR}/build_swiftest.sh ${ARGS}
cmake -P distclean.cmake
fi
arch -x86_64 /bin/bash -c "${SCRIPT_DIR}/build_swiftest.sh ${ARGS}"
cmake -P distclean.cmake
done
python3 -m build --sdist



21 changes: 7 additions & 14 deletions buildscripts/build_swiftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
set -a
if [ -z ${SCRIPT_DIR+x} ]; then SCRIPT_DIR=$(realpath $(dirname $0)); fi
ARGS=$@

. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}
ARGS="-p ${PREFIX} -d ${DEPENDENCY_DIR} -m ${MACOSX_DEPLOYMENT_TARGET}"

Expand All @@ -28,8 +29,6 @@ echo $OS $ARCH
printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n\n"
printf "Installing to ${PREFIX}\n"
printf "Dependency libraries in ${PREFIX}\n"
read -rsn1 -p"Press any key to continue";echo

${SCRIPT_DIR}/build_dependencies.sh ${ARGS}

if [ $OS = "Linux" ]; then
Expand All @@ -38,27 +37,23 @@ else
SKBUILD_CONFIGURE_OPTIONS="-DBUILD_SHARED_LIBS=ON -DUSE_SIMD=OFF"
SKBUILD_CONFIGURE_OPTIONS="${SKBUILD_CONFIGURE_OPTIONS} -DMACHINE_CODE_VALUE=\"generic\""
OMPROOT=${DEVTOOLDIR}/MacOSX${MACOSX_DEPLOYMENT_TARGET}/${ARCH}/usr/local
rsync -a ${OMPROOT}/lib/libgfortran*dylib ${ROOT_DIR}/lib/
rsync -a ${OMPROOT}/lib/libgomp*dylib ${ROOT_DIR}/lib/
rsync -a ${OMPROOT}/lib/libomp*dylib ${ROOT_DIR}/lib/
rsync -a ${OMPROOT}/lib/libquadmath*dylib ${ROOT_DIR}/lib/
rsync -va ${OMPROOT}/* ${ROOT_DIR}/

NETCDF_FORTRAN_HOME=${ROOT_DIR}
NETCDF_INCLUDE=${ROOT_DIR}/include

CPPFLAGS="${CPPFLAGS} -Xclang -fopenmp"
LIBS="${LIBS} -lomp"
LDFLAGS="-Wl,-rpath,${OMPROOT}/lib -Wl,-rpath,${ROOT_DIR}/lib"
CPATH="${OMPROOT}/include:${CPATH}"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
CPPFLAGS="-Xclang -fopenmp"
LIBS="-lomp"
LDFLAGS="-Wl,-rpath,${ROOT_DIR}/lib"
CPATH="${ROOT_DIR}/include"
LD_LIBRARY_PATH="${ROOT_DIR}/lib"
LIBRARY_PATH="${LD_LIBRARY_PATH}"
cd $ROOT_DIR

printf "\n"
printf "*********************************************************\n"
printf "* BUILDING SWIFTEST *\n"
printf "*********************************************************\n"
printf "OMPROOT: ${OMPROOT}\n"
printf "LIBS: ${LIBS}\n"
printf "CFLAGS: ${CFLAGS}\n"
printf "FFLAGS: ${FFLAGS}\n"
Expand All @@ -74,7 +69,5 @@ else
printf "MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET}\n"
printf "*********************************************************\n"

python3 -m pip install build pip
python3 -m build --sdist
cibuildwheel --platform macos
fi
38 changes: 18 additions & 20 deletions buildscripts/set_compilers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,42 @@ case "$OS" in
;;
esac


set -a
# Only replace compiler definitions if they are not already set
case $OS in
Linux)
FC=${FC:-$(command -v gfortran)}
CC=${CC:-$(command -v gcc)}
CXX=${CXX:-$(command -v g++)}
CPP=${CPP:-$(command -v cpp)}
FC=${$(command -v gfortran)}
CC=${$(command -v gcc)}
CXX=${$(command -v g++)}
CPP=${$(command -v cpp)}
;;
MacOSX)
COMPILER_PREFIX=${COMPILER_PREFIX:-"/usr"}
CC=${CC:-${COMPILER_PREFIX}/bin/clang}
CXX=${CXX:-${COMPILER_PREFIX}/bin/clang++}
CPP=${CPP:-${COMPILER_PREFIX}/bin/cpp}
AR=${AR:-${COMPILER_PREFIX}/bin/ar}
NM=${NM:-${COMPILER_PREFIX}/bin/nm}
RANLIB=${RANLIB:-${COMPILER_PREFIX}/bin/ranlib}
COMPILER_PREFIX="/usr"
CC=${COMPILER_PREFIX}/bin/clang
CXX=${COMPILER_PREFIX}/bin/clang++
CPP=${COMPILER_PREFIX}/bin/cpp
AR=${COMPILER_PREFIX}/bin/ar
NM=${COMPILER_PREFIX}/bin/nm
RANLIB=${COMPILER_PREFIX}/bin/ranlib

# Use custom gfortran location for a given MacOS Target version if vailable
FROOT=${DEVTOOLDIR}/MacOSX${MACOSX_DEPLOYMENT_TARGET}/${ARCH}/usr/local
printf "FROOT: ${FROOT}\n"
if [ -f ${FROOT}/bin/gfortran ]; then
FC=${FROOT}/bin/gfortran
else
FC=${FC:-$(command -v gfortran)}
FC=$(command -v gfortran)
FROOT=$(realpath $(dirname $(command -v $FC))/..)
fi
if [ ! -f ${FC} ]; then
printf "No working fortran compiler found!\n"
exit 1
fi
LD_LIBRARY_PATH="${COMPILER_PREFIX}/lib:${FROOT}/lib:${LD_LIBRARY_PATH}"
LDFLAGS="${LDFLAGS} -Wl,-rpath,${COMPILER_PREFIX}/lib -Wl,-no_compact_unwind"
CPPFLAGS="${CPPFLAGS} -isystem ${COMPILER_PREFIX}/include"
LIBS="${LIBS}"
CPATH="${FROOT}/include:${CPATH}"
CXXFLAGS="${CFLAGS} ${CXXFLAGS}"
FCFLAGS="${CFLAGS} ${FCFLAGS}"
CFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wno-deprecated-non-prototype ${CFLAGS}"
LDFLAGS="-Wl,-no_compact_unwind"
CFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wno-deprecated-non-prototype"
LD_LIBRARY_PATH=""
CPATH=""
;;
*)
printf "Unknown compiler type: ${OS}\n"
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ IF (NOT BUILD_SHARED_LIBS AND NOT WINOPT)
# SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}"
# Fortran "-static-libquadmath"
# )

IF (USE_OPENMP)
SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}"
Fortran "-lgomp"
Fortran "-lomp"
"-lgomp"
)
ENDIF (USE_OPENMP)
ENDIF ()
Expand Down
4 changes: 3 additions & 1 deletion distclean.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ELSE()
SET(TOPDIR "${CMAKE_SOURCE_DIR}")
ENDIF()

SET(CIBW_DIR "_skbuild" "swiftest.egg-info")
SET(CIBW_DIR "_skbuild" "swiftest.egg-info" "_cmake_test_compile")

MACRO(GET_PARENT_DIRECTORIES search_string return_list grandparents)
FILE(GLOB_RECURSE new_list ${search_string})
Expand All @@ -46,8 +46,10 @@ FILE(GLOB_RECURSE CMAKEINSTALL "${TOPDIR}/*cmake_install.cmake"
FILE(GLOB_RECURSE MAKEFILE "${TOPDIR}/*Makefile")
FILE(GLOB_RECURSE CMAKETESTFILES "${TOPDIR}/*CTestTestfile.cmake")
SET(TOPDIRECTORIES "${TOPDIR}/lib"
"${TOPDIR}/libexec"
"${TOPDIR}/bin"
"${TOPDIR}/include"
"${TOPDIR}/share"
)

# CMake has trouble finding directories recursively, so locate these
Expand Down

0 comments on commit be7283e

Please sign in to comment.