Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BLAS/LAPACK support for macOS and Linux #9

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
19 changes: 10 additions & 9 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
# one for each Python version
os: [ubuntu-latest]
arch: [aarch64]
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: ubuntu-latest
arch: x86_64
Expand All @@ -166,23 +166,23 @@ jobs:
boost-arch: x86
boost-toolset: msvc
boost-platform-version: 2022
boost-version: "1.85.0"
boost-version: "1.86.0"
- os: macos-14
arch: arm64
boost-arch: aarch64
boost-toolset: clang
# Since we only use the headers, we can use the platform version for this
# macos version
boost-platform-version: "14"
boost-version: "1.85.0"
boost-version: "1.86.0"
- os: macos-13
arch: x86_64
boost-arch: x86
boost-toolset: clang
# Since we only use the headers, we can use the platform version for this
# macos version
boost-platform-version: "13"
boost-version: "1.85.0"
boost-version: "1.86.0"
fail-fast: false
steps:
- name: Checkout the repository
Expand Down Expand Up @@ -236,8 +236,8 @@ jobs:
if: runner.os != 'Linux'
uses: actions/cache@v4
with:
key: ${{ matrix.os }}-${{ matrix.arch }}-0
path: ${{ runner.temp }}/cache
key: ${{ matrix.os }}-${{ matrix.arch }}-1
path: ${{ github.workspace }}/cache

# Windows-only steps
- name: Set Up Nuget
Expand All @@ -247,7 +247,8 @@ jobs:
with:
python-version: 3.12
if: runner.os == 'Windows'
- run: bash ./cibw_before_all_windows.sh "${{ runner.temp }}"
- name: Build required libraries
run: bash ./cibw_before_all_windows.sh "${{ github.workspace }}"
if: runner.os == 'Windows'
- name: Set up CIBW environment
# On Windows, Boost_ROOT needs to have \ replaced by / because that's what
Expand All @@ -263,7 +264,7 @@ jobs:

# macOS-only steps
- name: Build required libraries
run: bash ./cibw_before_all_macos.sh "${{ runner.temp }}"
run: bash ./cibw_before_all_macos.sh "${{ github.workspace }}"
if: runner.os == 'macOS'
# Force installation to resolve Python 3.8 bug (https://github.com/pypa/cibuildwheel/pull/1871#issuecomment-2161613619)
- name: Hack for 3.8 bug
Expand All @@ -280,7 +281,7 @@ jobs:
if: runner.os == 'macOS'

- name: Build wheels
uses: pypa/[email protected].2
uses: pypa/[email protected].3
env:
CIBW_ENVIRONMENT_LINUX: CT_SKIP_SLOW=1 CANTERA_TEST_DIR=/host/${{ steps.download-test-files.outputs.test-root }}
CIBW_ENVIRONMENT_WINDOWS: CT_SKIP_SLOW=1 CMAKE_BUILD_PARALLEL_LEVEL=4
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache
hdf5-*
HighFive-*
*.tar.gz
85 changes: 39 additions & 46 deletions cibw_before_all_macos.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ set -eo pipefail
function setup_github_env {
if [[ "$GITHUB_ENV" != "" ]]; then
echo "HDF5_DIR=${HDF5_DIR}" | tee -a $GITHUB_ENV
echo "LIBAEC_DIR=${LIBAEC_DIR}" | tee -a $GITHUB_ENV
echo "ZLIB_DIR=${ZLIB_DIR}" | tee -a $GITHUB_ENV
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" | tee -a $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" | tee -a $GITHUB_ENV
echo "DYLD_FALLBACK_LIBRARY_PATH=${HDF5_DIR}/lib:${ZLIB_DIR}/lib:${LIBAEC_DIR}/lib" | tee -a $GITHUB_ENV
echo "DYLD_FALLBACK_LIBRARY_PATH=${HDF5_DIR}/lib" | tee -a $GITHUB_ENV
fi
}

Expand All @@ -51,22 +49,19 @@ if [[ "$1" == "" ]] ; then
exit 1
fi
PROJECT_PATH="$1"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ARCH=$(uname -m)

HDF5_VERSION="1.14.5"
ZLIB_VERSION="1.3.1"
LIBAEC_VERSION="1.0.6"

HDF5_VERSION="1.14.4.3"
LIBAEC_VERSION="1.1.3"
HDF5_PATCH_VERSION=${HDF5_VERSION}
HIGHFIVE_VERSION="2.10.0"
# Replace the last dot with a dash because that's what some of the files in this
# release have done.
HDF5_PATCH_VERSION=${HDF5_VERSION%.*}-${HDF5_VERSION##*.}
# HDF5_PATCH_VERSION=${HDF5_VERSION%.*}-${HDF5_VERSION##*.}

HDF5_DIR="${PROJECT_PATH}/cache/hdf5/${HDF5_VERSION}-${ARCH}"
ZLIB_DIR="${PROJECT_PATH}/cache/zlib/${ZLIB_VERSION}-${ARCH}"
LIBAEC_DIR="${PROJECT_PATH}/cache/libaec/${LIBAEC_VERSION}-${ARCH}"

LD_LIBRARY_PATH="${ZLIB_DIR}/lib:${LD_LIBRARY_PATH}"
HIGHFIVE_DIR="${PROJECT_PATH}/cache/highfive/${HIGHFIVE_VERSION}-${ARCH}"

# When compiling HDF5, we should use the minimum across all Python versions for a given
# arch, for versions see for example a more updated version of the following:
Expand All @@ -79,8 +74,9 @@ else
fi

lib_name=libhdf5.dylib
inc_name=highfive.hpp

if [ -f ${HDF5_DIR}/lib/${lib_name} ]; then
if [ -f ${HDF5_DIR}/lib/${lib_name} ] && [ -f ${HIGHFIVE_DIR}/include/highfive/${inc_name} ]; then
echo "using cached build"
setup_github_env
exit 0
Expand All @@ -92,50 +88,47 @@ brew install ninja cmake

pushd ${PROJECT_PATH}

curl -fsSLO "https://github.com/madler/zlib/releases/download/v${ZLIB_VERSION}/zlib-${ZLIB_VERSION}.tar.gz"
tar -xzf zlib-${ZLIB_VERSION}.tar.gz

mkdir -p zlib-${ZLIB_VERSION}/build
pushd zlib-${ZLIB_VERSION}/build
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX=${ZLIB_DIR} \
-DZLIB_BUILD_EXAMPLES=OFF \
..

ninja install
popd

curl -fsSLO "https://gitlab.dkrz.de/k202009/libaec/uploads/45b10e42123edd26ab7b3ad92bcf7be2/libaec-${LIBAEC_VERSION}.tar.gz"
tar -xzf libaec-${LIBAEC_VERSION}.tar.gz
mkdir -p libaec-${LIBAEC_VERSION}/build
pushd libaec-${LIBAEC_VERSION}
patch -p0 < ${SCRIPT_DIR}/libaec_cmakelists.patch
pushd build
curl -fsSLO "https://github.com/HDFGroup/hdf5/releases/download/hdf5_${HDF5_VERSION}/hdf5-${HDF5_PATCH_VERSION}.tar.gz"
tar -xzf hdf5-${HDF5_PATCH_VERSION}.tar.gz
mkdir -p hdf5-${HDF5_PATCH_VERSION}/build
pushd hdf5-${HDF5_PATCH_VERSION}/build

cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${LIBAEC_DIR} \
-DBUILD_TESTING=OFF \
-DCMAKE_INSTALL_PREFIX=${HDF5_DIR} \
-DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
-DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \
-DHDF5_BUILD_EXAMPLES:BOOL=OFF \
-DHDF5_BUILD_TOOLS:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF \
-DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ \
-DZLIB_PACKAGE_NAME:STRING=zlib \
-DZLIB_TGZ_NAME:STRING=zlib-${ZLIB_VERSION}.tar.gz \
-DZLIB_TGZ_ORIGPATH:STRING=https://github.com/madler/zlib/releases/download/v${ZLIB_VERSION} \
-DZLIB_USE_LOCALCONTENT:BOOL=OFF \
-DLIBAEC_PACKAGE_NAME:STRING=libaec \
-DLIBAEC_TGZ_NAME:STRING=libaec-${LIBAEC_VERSION}.tar.gz \
-DLIBAEC_TGZ_ORIGPATH:STRING=https://github.com/MathisRosenhauer/libaec/releases/download/v${LIBAEC_VERSION} \
-DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \
-DHDF_PACKAGE_NAMESPACE:STRING=ct_ \
..

ninja install
popd
popd

curl -fsSLO "https://github.com/HDFGroup/hdf5/releases/download/hdf5_${HDF5_VERSION}/hdf5-${HDF5_PATCH_VERSION}.tar.gz"
tar -xzf hdf5-${HDF5_PATCH_VERSION}.tar.gz
mkdir -p hdf5-${HDF5_PATCH_VERSION}/build
pushd hdf5-${HDF5_PATCH_VERSION}/build
curl -fsSLO https://github.com/BlueBrain/HighFive/archive/refs/tags/v${HIGHFIVE_VERSION}.tar.gz
tar -xzf v${HIGHFIVE_VERSION}.tar.gz
mkdir -p HighFive-${HIGHFIVE_VERSION}/build
pushd HighFive-${HIGHFIVE_VERSION}/build

cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DZLIB_ROOT=${ZLIB_DIR} \
-Dlibaec_ROOT=${LIBAEC_DIR} \
-DCMAKE_INSTALL_PREFIX=${HDF5_DIR} \
-DHDF5_ENABLE_Z_LIB_SUPPORT=ON \
-DHDF5_ENABLE_SZIP_SUPPORT=ON \
-DHDF5_BUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DHDF5_ROOT=${HDF5_DIR} \
-DCMAKE_INSTALL_PREFIX=${HIGHFIVE_DIR} \
-DHIGHFIVE_USE_BOOST:BOOL=OFF \
-DHIGHFIVE_UNIT_TESTS:BOOL=OFF \
-DHIGHFIVE_EXAMPLES:BOOL=OFF \
-DHIGHFIVE_BUILD_DOCS:BOOL=OFF \
..

ninja install
Expand Down
2 changes: 1 addition & 1 deletion cibw_before_all_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export LINK="/LIBPATH:$PROJECT_PATH\zlib-msvc-x64\build\native\lib_release"
export ZLIB_ROOT="$PROJECT_PATH\zlib-msvc-x64\build\native"

# HDF5
export HDF5_VERSION="1.14.4.3"
export HDF5_VERSION="1.14.5"
export HDF5_VSVERSION="17-64"
export HDF5_DIR="$PROJECT_PATH/cache/hdf5/$HDF5_VERSION"

Expand Down
19 changes: 6 additions & 13 deletions get_hdf5_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,23 @@
import requests

HDF5_URL = "https://github.com/HDFGroup/hdf5/releases/download/hdf5_{dotted_version}/hdf5-{dashed_version}.zip"
ZLIB_ROOT = environ.get("ZLIB_ROOT")

CMAKE_CONFIGURE_CMD = [
"cmake",
"-DBUILD_SHARED_LIBS:BOOL=ON",
"-DCMAKE_BUILD_TYPE:STRING=RELEASE",
"-DHDF5_BUILD_CPP_LIB=OFF",
"-DHDF5_BUILD_HL_LIB=ON",
"-DHDF5_BUILD_HL_LIB=OFF",
"-DHDF5_BUILD_TOOLS:BOOL=OFF",
"-DBUILD_TESTING:BOOL=OFF",
"-DHDF5_BUILD_EXAMPLES:BOOL=OFF",
]
if ZLIB_ROOT:
CMAKE_CONFIGURE_CMD += [
"-DHDF5_ENABLE_Z_LIB_SUPPORT=ON",
f"-DZLIB_INCLUDE_DIR={ZLIB_ROOT}\\include",
f"-DZLIB_LIBRARY_RELEASE={ZLIB_ROOT}\\lib_release\\zlib.lib",
f"-DZLIB_LIBRARY_DEBUG={ZLIB_ROOT}\\lib_debug\\zlibd.lib",
]
CMAKE_BUILD_CMD = ["cmake", "--build"]
CMAKE_INSTALL_ARG = ["--target", "install", "--config", "Release"]
CMAKE_INSTALL_PATH_ARG = "-DCMAKE_INSTALL_PREFIX={install_path}"
CMAKE_HDF5_LIBRARY_PREFIX = ["-DHDF5_EXTERNAL_LIB_PREFIX=h5py_"]
CMAKE_HDF5_LIBRARY_PREFIX = ["-DHDF5_EXTERNAL_LIB_PREFIX=ct_"]
REL_PATH_TO_CMAKE_CFG = "hdf5-{version}"
DEFAULT_VERSION = "1.14.3.3"
DEFAULT_VERSION = "1.14.5"
VSVERSION_TO_GENERATOR = {
"9": "Visual Studio 9 2008",
"10": "Visual Studio 10 2010",
Expand Down Expand Up @@ -190,7 +183,7 @@ def main():
install_path = environ.get("HDF5_DIR")
version = environ.get("HDF5_VERSION", DEFAULT_VERSION)
vs_version = environ.get("HDF5_VSVERSION")
use_prefix = True if environ.get("H5PY_USE_PREFIX") is not None else False
use_prefix = True if environ.get("HDF5_USE_PREFIX") is not None else False

if install_path is not None:
if not exists(install_path):
Expand All @@ -208,7 +201,7 @@ def main():
print("using cached hdf5", file=stderr)
if install_path is not None:
print("hdf5 files: ", file=stderr)
for dirpath, dirnames, filenames in walk(install_path):
for dirpath, _, filenames in walk(install_path):
for file in filenames:
print(" * " + pjoin(dirpath, file))

Expand Down
Loading