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

Commit

Permalink
Merge pull request #22 from profminton/master
Browse files Browse the repository at this point in the history
Addition of continuous integration using cibuildwheels, scikit-build-core, and GitHub Actions
  • Loading branch information
carlislewishard authored and GitHub committed Sep 7, 2023
2 parents e7c27a4 + 741bfef commit ef89afd
Show file tree
Hide file tree
Showing 43 changed files with 2,947 additions and 847 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
env:
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_LINUX: x86_64 aarch64
with:
package-dir: .
output-dir: wheelhouse
config-file: "{package}/pyproject.toml"

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl


build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ swiftest_driver.sh
!README.swifter
dump*
!**/.gitignore
!.github/workflows/build_wheels.yml
!setup.py
!examples/**
!swiftest/**
!tests/**
*ipynb_checkpoints
**/.DS_Store
!version.txt
!LICENSE.txt
!requirements.txt
!pyproject.toml
**/_skbuild
Expand Down
36 changes: 13 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.6.0...3.27.1)

# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(swiftest VERSION ${VERSION} LANGUAGES C Fortran)
PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran VERSION ${VERSION})

IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler ${CMAKE_Fortran_COMPILER_ID} not recognized!")
ENDIF ()

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
Expand All @@ -29,28 +37,7 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
ENDIF()

# Ensure scikit-build modules
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
IF (NOT SKBUILD)
EXECUTE_PROCESS(
COMMAND "${Python3_EXECUTABLE}"
-c "import os, skbuild; print(os.path.dirname(skbuild.__file__))"
OUTPUT_VARIABLE SKBLD_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
FILE(TO_CMAKE_PATH ${SKBLD_DIR} SKBLD_DIR)
LIST(APPEND CMAKE_MODULE_PATH "${SKBLD_DIR}/resources/cmake")
MESSAGE(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules")
ENDIF()

# Detect when building against a conda environment set the _using_conda variable
# for use both in this file and in the parent
GET_FILENAME_COMPONENT(_python_bin_dir ${Python3_EXECUTABLE} DIRECTORY)
IF(EXISTS "${_python_bin_dir}/../conda-meta")
MESSAGE("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH")
SET(_using_conda On)
ELSE()
SET(_using_conda Off)
ENDIF()
FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Add our local modules to the module path
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
Expand All @@ -77,6 +64,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN})
# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})

# Set the name of the swiftest library
SET(SWIFTEST_LIBRARY swiftest)

# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})

Expand Down
10 changes: 10 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright 2023 - David Minton
The Swiftest development team: David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, Dana Singh, & Kaustub Anand

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.
30 changes: 6 additions & 24 deletions buildscripts/_build_getopts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ SCRIPT_DIR=$(realpath $(dirname $0))
ROOT_DIR=$(realpath ${SCRIPT_DIR}/..)

# Parse arguments
USTMT="Usage: ${0} <-d /path/to/dependency/source> [-p /prefix/path|{/usr/local}] [-m MACOSX_DEPLOYMENT_TARGET|{11.0}]"
PREFIX=/usr/local
DEPENDENCY_DIR="${ROOT_DIR}/_dependencies"
MACOSX_DEPLOYMENT_TARGET="13.0"
USTMT="Usage: ${0} [-d /path/to/dependency/source] [-p /prefix/path] [-m MACOSX_DEPLOYMENT_TARGET]"
MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"}

while getopts ":d:p:m:h" ARG; do
case "${ARG}" in
d)
Expand Down Expand Up @@ -46,26 +45,9 @@ while getopts ":d:p:m:h" ARG; do
done

read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh)

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="${CPATH} ${PREFIX}/include}"

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_HOME=${NCDIR}

DEPENDENCY_ENV_VARS=true
fi
BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build.XXXXXXXX)}
PREFIX=${PREFIX:-${ROOT_DIR}}
DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}}

mkdir -p ${DEPENDENCY_DIR}
mkdir -p ${PREFIX}/lib
Expand Down
22 changes: 0 additions & 22 deletions buildscripts/build_all.sh

This file was deleted.

74 changes: 10 additions & 64 deletions buildscripts/build_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,6 @@ set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}

ZLIB_VER="1.3"
HDF5_VER="1_14_2"
NC_VER="4.9.2"
NF_VER="4.6.1"

printf "*********************************************************\n"
printf "* FETCHING DEPENCENCY SOURCES *\n"
printf "*********************************************************\n"
printf "Copying files to ${DEPENDENCY_DIR}\n"
mkdir -p ${DEPENDENCY_DIR}
if [ ! -d ${DEPENDENCY_DIR}/zlib-${ZLIB_VER} ]; then
[ -d ${DEPENDENCY_DIR}/zlib-* ] && rm -rf ${DEPENDENCY_DIR}/zlib-*
curl -L https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/zlib-${ZLIB_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

printf "Checking if HDF5 source exists\n"
if [[ (-d ${DEPENDENCY_DIR}/hdfsrc) && (-f ${DEPENDENCY_DIR}/hdfsrc/README.md) ]]; then
OLDVER=$(grep version ${DEPENDENCY_DIR}/hdfsrc/README.md | awk '{print $3}' | sed 's/\./_/g')
printf "Existing copy of HDF5 source detected\n"
printf "Existing version : ${OLDVER}\n"
printf "Requested version: ${HDF5_VER}\n"
if [ "$OLDVER" != "${HDF5_VER}" ]; then
printf "Existing version of HDF5 source doesn't match requested. Deleting\n"
rm -rf ${DEPENDENCY_DIR}/hdfsrc
fi
fi

if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then
curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

if [ ! -d ${DEPENDENCY_DIR}/netcdf-c-${NC_VER} ]; then
[ -d ${DEPENDENCY_DIR}/netcdf-c-* ] && rm -rf ${DEPENDENCY_DIR}/netcdf-c-*
curl -s -L https://github.com/Unidata/netcdf-c/archive/refs/tags/v${NC_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

if [ ! -d ${DEPENDENCY_DIR}/netcdf-fortran-${NF_VER} ]; then
[ -d ${DEPENDENCY_DIR}/netcdf-fortran-* ] && rm -rf ${DEPENDENCY_DIR}/netcdf-fortran-*
curl -s -L https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v${NF_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

cd $ROOT_DIR
printf "*********************************************************\n"
printf "* STARTING DEPENDENCY BUILD *\n"
Expand All @@ -66,34 +25,21 @@ printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n"
printf "Installing to ${PREFIX}\n"
printf "\n"

set -e
if [ ! -f ${PREFIX}/lib/libz.a ]; then
${SCRIPT_DIR}/build_zlib.sh ${ARGS}
else
echo "Found: ${PREFIX}/lib/libz.a"
fi

if [ ! -f ${PREFIX}/lib/libhdf5.a ]; then
${SCRIPT_DIR}/build_hdf5.sh ${ARGS}
else
echo "Found: ${PREFIX}/lib/libhdf5.a"
# Get the OpenMP Libraries
if [ $OS = "MacOSX" ]; then
${SCRIPT_DIR}/get_lomp.sh ${ARGS}
fi


if [ ! -f ${PREFIX}/lib/libnetcdf.a ]; then
${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS}
else
echo "Found: ${PREFIX}/lib/libnetcdf.a"
fi

if [ ! -f ${PREFIX}/lib/libnetcdff.a ]; then
${SCRIPT_DIR}/build_netcdf-fortran.sh ${ARGS}
else
echo "Found: ${PREFIX}/lib/libnetcdff.a"
fi
set -e
${SCRIPT_DIR}/build_zlib.sh ${ARGS}
${SCRIPT_DIR}/build_hdf5.sh ${ARGS}
${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS}
${SCRIPT_DIR}/build_netcdf-fortran.sh ${ARGS}

printf "\n"
printf "*********************************************************\n"
printf "* DEPENDENCIES ARE BUILT *\n"
printf "*********************************************************\n"
printf "Dependencys are installed to: ${PREFIX}\n\n"


30 changes: 25 additions & 5 deletions buildscripts/build_hdf5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,32 @@ set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}

HDF5_VER="1_14_2"
printf "*********************************************************\n"
printf "* FETCHING HDF5 SOURCE *\n"
printf "*********************************************************\n"
printf "Copying files to ${DEPENDENCY_DIR}\n"

printf "Checking if HDF5 source exists\n"
if [[ (-d ${DEPENDENCY_DIR}/hdfsrc) && (-f ${DEPENDENCY_DIR}/hdfsrc/README.md) ]]; then
OLDVER=$(grep version ${DEPENDENCY_DIR}/hdfsrc/README.md | awk '{print $3}' | sed 's/\./_/g')
printf "Existing copy of HDF5 source detected\n"
printf "Existing version : ${OLDVER}\n"
printf "Requested version: ${HDF5_VER}\n"
if [ "$OLDVER" != "${HDF5_VER}" ]; then
printf "Existing version of HDF5 source doesn't match requested. Deleting\n"
rm -rf ${DEPENDENCY_DIR}/hdfsrc
fi
fi

if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then
curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi


printf "\n"
printf "*********************************************************\n"
printf "* BUILDING HDF5 STATIC LIBRARY *\n"
printf "* BUILDING HDF5 LIBRARY *\n"
printf "*********************************************************\n"
printf "LIBS: ${LIBS}\n"
printf "CFLAGS: ${CFLAGS}\n"
Expand All @@ -35,7 +58,7 @@ if [ $OS = "MacOSX" ]; then
printf "echo arm-apple-darwin" > bin/config.sub
fi
fi
COPTS="--disable-shared --enable-build-mode=production --enable-tests=no --enable-tools=no --disable-fortran --disable-java --disable-cxx --prefix=${PREFIX} --with-zlib=${PREFIX}"
COPTS="--enable-build-mode=production --enable-tests=no --enable-tools=no --disable-fortran --disable-java --disable-cxx --prefix=${PREFIX} --with-zlib=${PREFIX}"
./configure ${COPTS}
make
if [ -w ${PREFIX} ]; then
Expand All @@ -48,6 +71,3 @@ if [ $? -ne 0 ]; then
printf "hdf5 could not be compiled.\n"
exit 1
fi

make distclean

24 changes: 16 additions & 8 deletions buildscripts/build_netcdf-c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ set -a
ARGS=$@
. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS}


NC_VER="4.9.2"

printf "*********************************************************\n"
printf "* FETCHING NETCDF-C SOURCE *\n"
printf "*********************************************************\n"
printf "Copying files to ${DEPENDENCY_DIR}\n"

if [ ! -d ${DEPENDENCY_DIR}/netcdf-c-${NC_VER} ]; then
[ -d ${DEPENDENCY_DIR}/netcdf-c-* ] && rm -rf ${DEPENDENCY_DIR}/netcdf-c-*
curl -s -L https://github.com/Unidata/netcdf-c/archive/refs/tags/v${NC_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR}
fi

printf "\n"
printf "*********************************************************\n"
printf "* BUILDING NETCDF-C STATIC LIBRARY *\n"
printf "* BUILDING NETCDF-C LIBRARY *\n"
printf "*********************************************************\n"
printf "LIBS: ${LIBS}\n"
printf "CFLAGS: ${CFLAGS}\n"
Expand All @@ -30,10 +43,7 @@ printf "HDF5_ROOT: ${HDF5_ROOT}\n"
printf "*********************************************************\n"

cd ${DEPENDENCY_DIR}/netcdf-c-*
COPTS="--disable-shared --disable-dap --disable-byterange --disable-testsets --prefix=${PREFIX}"
if [ ! $OS = "MacOSX" ]; then
COPTS="${COPTS} --disable-libxml2"
fi
COPTS="--disable-testsets --disable-nczarr --prefix=${PREFIX}"
printf "COPTS: ${COPTS}\n"
./configure $COPTS
make && make check
Expand All @@ -47,6 +57,4 @@ fi
if [ $? -ne 0 ]; then
printf "netcdf-c could not be compiled."\n
exit 1
fi

make distclean
fi
Loading

0 comments on commit ef89afd

Please sign in to comment.