From 6aad7120179b2bdeabc4d56f98c8ba923f441ac3 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:49:05 -0400 Subject: [PATCH] Restructured MacOS build scripts and prepared for GitHub actions. --- .github/workflows/build_wheels.yml | 25 +++++++++ .gitignore | 1 + buildscripts/_build_getopts.sh | 23 +-------- buildscripts/build_dependencies.sh | 5 ++ buildscripts/build_macwheels.sh | 44 ---------------- buildscripts/build_swiftest.sh | 66 ------------------------ buildscripts/get_lomp.sh | 83 ++++++++++++++++++++++++++++++ pyproject.toml | 41 ++++++++++++++- 8 files changed, 154 insertions(+), 134 deletions(-) create mode 100644 .github/workflows/build_wheels.yml delete mode 100755 buildscripts/build_macwheels.sh delete mode 100755 buildscripts/build_swiftest.sh create mode 100755 buildscripts/get_lomp.sh diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 000000000..9b7a32427 --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,25 @@ +name: swiftest + +on: [push] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04, macos-11, macos-12, macos-13] + + steps: + - uses: actions/checkout@v3 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.15.0 + with: + package-dir: . + output-dir: wheelhouse + config-file: "{package}/pyproject.toml" + + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl \ No newline at end of file diff --git a/.gitignore b/.gitignore index e68502d0f..ab0e8d718 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ swiftest_driver.sh !README.swifter dump* !**/.gitignore +!.github/workflows/build_wheels.yml !setup.py !examples/** !swiftest/** diff --git a/buildscripts/_build_getopts.sh b/buildscripts/_build_getopts.sh index fc9728db7..ac9e9586b 100755 --- a/buildscripts/_build_getopts.sh +++ b/buildscripts/_build_getopts.sh @@ -15,7 +15,7 @@ ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) # Parse arguments USTMT="Usage: ${0} [-d /path/to/dependency/source] [-p /prefix/path] [-m MACOSX_DEPLOYMENT_TARGET]" -MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"11.0"} +MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"} while getopts ":d:p:m:h" ARG; do case "${ARG}" in @@ -49,27 +49,6 @@ BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build.XXXXXXXX)} PREFIX=${PREFIX:-${ROOT_DIR}} DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}} -if [ -z ${DEPENDENCY_ENV_VARS+x} ]; then - . ${SCRIPT_DIR}/set_compilers.sh - - LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH}" - CPPFLAGS="${CPPFLAGS} -isystem ${PREFIX}/include" - LDFLAGS="${LDFLAGS} -L${PREFIX}/lib" - CPATH="${PREFIX}/include:${CPATH}" - - HDF5_ROOT="${PREFIX}" - HDF5_LIBDIR="${HDF5_ROOT}/lib" - HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" - HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" - NCDIR="${PREFIX}" - NFDIR="${PREFIX}" - NETCDF_FORTRAN_HOME=${NFDIR} - NETCDF_INCLUDE=${NFDIR}/include - NETCDF_HOME=${NCDIR} - - DEPENDENCY_ENV_VARS=true -fi - mkdir -p ${DEPENDENCY_DIR} mkdir -p ${PREFIX}/lib mkdir -p ${PREFIX}/include diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 645465d22..ee8efb0f7 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -25,6 +25,11 @@ printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" printf "Installing to ${PREFIX}\n" printf "\n" +# Get the OpenMP Libraries +if [ $OS == "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi + set -e ${SCRIPT_DIR}/build_zlib.sh ${ARGS} ${SCRIPT_DIR}/build_hdf5.sh ${ARGS} diff --git a/buildscripts/build_macwheels.sh b/buildscripts/build_macwheels.sh deleted file mode 100755 index 49acbec91..000000000 --- a/buildscripts/build_macwheels.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/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.0" "13.0") - -for MACOSX_DEPLOYMENT_TARGET in "${MACVER[@]}"; do - ARGS="-p ${PREFIX} -d ${DEPENDENCY_DIR} -m ${MACOSX_DEPLOYMENT_TARGET}" - printf "**********************************************************************\n" - printf "ARGS: ${ARGS}\n" - printf "**********************************************************************\n" - - if [ "${MACOSX_DEPLOYMENT_TARGET}" != "10.13" ]; then - ${SCRIPT_DIR}/build_dependencies.sh ${ARGS} - ${SCRIPT_DIR}/build_swiftest.sh ${ARGS} - cmake -P distclean.cmake - fi - - if [ "${MACOSX_DEPLOYMENT_TARGET}" != "13.0" ]; then - ${SCRIPT_DIR}/intelbash.sh ${SCRIPT_DIR}/build_dependencies.sh ${ARGS} - ${SCRIPT_DIR}/intelbash.sh ${SCRIPT_DIR}/build_swiftest.sh ${ARGS} - cmake -P distclean.cmake - fi -done -python3 -m build --sdist - - - diff --git a/buildscripts/build_swiftest.sh b/buildscripts/build_swiftest.sh deleted file mode 100755 index 3f0af181d..000000000 --- a/buildscripts/build_swiftest.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# This script will build the Swiftest package. It is assumed that compatible dependencies have been built already before this is run -# -# 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 -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}" - -# Determine if we are in the correct directory (the script can either be run from the Swiftest project root directory or the -# buildscripts directory) -if [ ! -f "${ROOT_DIR}/setup.py" ]; then - echo "Error: setup.py not found" - exit 1 -fi - -read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh) -echo $OS $ARCH - -if [ $OS = "Linux" ]; then - cibuildwheel --platform linux -else - SKBUILD_CONFIGURE_OPTIONS="-DBUILD_SHARED_LIBS=ON -DUSE_SIMD=OFF" - SKBUILD_CONFIGURE_OPTIONS="${SKBUILD_CONFIGURE_OPTIONS} -DMACHINE_CODE_VALUE=\"generic\"" - - NETCDF_FORTRAN_HOME=${ROOT_DIR} - NETCDF_INCLUDE=${ROOT_DIR}/include - - 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 "LIBS: ${LIBS}\n" - printf "CFLAGS: ${CFLAGS}\n" - printf "FFLAGS: ${FFLAGS}\n" - printf "FCFLAGS: ${FCFLAGS}\n" - printf "CPPFLAGS: ${CPPFLAGS}\n" - printf "CPATH: ${CPATH}\n" - printf "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}\n" - printf "LDFLAGS: ${LDFLAGS}\n" - printf "LIBS: ${LIBS}\n" - printf "NETCDF_FORTRAN_HOME: ${NETCDF_FORTRAN_HOME}\n" - printf "NETCDF_INCLUDE: ${NETCDF_INCLUDE}\n" - printf "SKBUILD_CONFIGURE_OPTIONS: ${SKBUILD_CONFIGURE_OPTIONS}\n" - printf "MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET}\n" - printf "*********************************************************\n" - - cibuildwheel --platform macos -fi \ No newline at end of file diff --git a/buildscripts/get_lomp.sh b/buildscripts/get_lomp.sh new file mode 100755 index 000000000..6b56e5b3c --- /dev/null +++ b/buildscripts/get_lomp.sh @@ -0,0 +1,83 @@ +#!/bin/bash +# This script will download the correct OpenMP library for a given MacOS deployment target +# +# 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. + +# Determine the platform and architecture +SCRIPT_DIR=$(realpath $(dirname $0)) +set -a +ARGS=$@ +. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +printf "MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET}\n" + +TARGET_MAJOR=`echo $MACOSX_DEPLOYMENT_TARGET | cut -d. -f1` +TARGET_MINOR=`echo $MACOSX_DEPLOYMENT_TARGET | cut -d. -f2` +TARGET_REV=`echo $MACOSX_DEPLOYMENT_TARGET | cut -d. -f3` + +#Figure out which version to get +case $TARGET_MAJOR in + 13) + OMPVER="14.0.6" + DVER="20" + ;; + 12) + if ((TARGET_MINOR>=5)); then + OMPVER="14.0.6" + DVER="20" + else + OMPVER="13.0.0" + DVER="21" + fi + ;; + 11) + if ((TARGET_MINOR>=3)); then + OMPVER="12.0.1" + DVER="20" + else + OMPVER="11.0.1" + DVER="20" + fi + ;; + 10) + DVER="17" + case $TARGET_MINOR in + 15) + case $TARGET_REV in + 4) + OMPVER="10.0.0" + ;; + 2) + OMPVER="9.0.1" + ;; + esac + ;; + 14) + case $TARGET_REV in + 4) + OMPVER="8.0.1" + ;; + 3) + OMPVER="7.1.0" + ;; + esac + ;; + *) + OMPVER="7.1.0" + ;; + esac + ;; +esac + +filename="openmp-${OMPVER}-darwin${DVER}-Release.tar.gz" +#Download and install the libraries +printf "Downloading ${filename}\n" +curl -O https://mac.r-project.org/openmp/${filename} && \ + sudo tar fvxz ${filename} -C / && \ + rm ${filename} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 25fbd2a2b..3ea08b70c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,10 +60,47 @@ test-requires = ['pytest'] skip = "cp312-* pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" build-verbosity = 1 +[tool.cibuildwheel.macos.environment] +ROOT_DIR="$(pwd)" +ARCH="$(uname -m)" +MACOSX_DEPLOYMENT_TARGET="$(sw_vers --ProductVersion)" +PREFIX="${ROOT_DIR}" +LD_LIBRARY_PATH="/usr/local/lib:${PREFIX}/lib:${HOMEBREW_PREFIX}/lib" +LDFLAGS="-Wl,-rpath,${ROOT_DIR}/lib -Wl,-rpath,${PREFIX}/lib -Wl,-rpath,/usr/local/lib -Wl,-no_compact_unwind -L${PREFIX}/lib" +CPATH="/usr/local/include:${PREFIX}/include:${HOMEBREW_PREFIX}/include:${ROOT_DIR}/include" +CPPFLAGS="-isystem ${PREFIX}/include -isystem /usr/local/include" +LIBS="-lomp" +CFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wno-deprecated-non-prototype -arch ${ARCH}" +FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" +FFFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" +HDF5_ROOT="${PREFIX}" +HDF5_LIBDIR="${HDF5_ROOT}/lib" +HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" +NETCDF_FORTRAN_HOME="${PREFIX}" +NETCDF_INCLUDE="${PREFIX}" +NCDIR="${PREFIX}" +NFDIR="${PREFIX}" +FC="${HOMEBREW_PREFIX}/bin/gfortran-12" +CC="/usr/bin/clang" +CXX="/usr/bin/clang++" +CPP="/usr/bin/cpp" +AR="/usr/bin/ar" +NM="/usr/bin/nm" +RANLIB="/usr/bin/ranlib" + +[tool.cibuildwheel.macos] +before-all = [ + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${TMPDIR}/swiftest.build -m ${MACOSX_DEPLOYMENT_TARGET}" +] + [tool.cibuildwheel.linux] -repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel}" -environment = {NETCDF_FORTRAN_HOME="/usr/local", NETCDF_INCLUDE="/usr/local/include", LD_LIBRARY_PATH="/usr/local/lib:/project/lib", CPATH="/usr/local/include:/project/include"} before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" ] +[tool.cibuildwheel.linux.environment] +NETCDF_FORTRAN_HOME="/usr/local" +NETCDF_INCLUDE="/usr/local/include" +LD_LIBRARY_PATH="/usr/local/lib:/project/lib" +CPATH="/usr/local/include:/project/include"