Skip to content
This repository has been archived by the owner on Feb 26, 2025. It is now read-only.

Commit

Permalink
follow libsonata's example, and publish wheels that statically use hd…
Browse files Browse the repository at this point in the history
…f5, to reduce h5py version conflicts
  • Loading branch information
mgeplf committed Apr 19, 2024
1 parent 54ffbd9 commit 4a8c02e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 97 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/publish-sdist-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ env:
CIBW_SKIP: 'cp35-* cp36-* cp37-* *-manylinux_i686 *-musllinux_* *-win32'
CIBW_BEFORE_TEST: pip install -r {project}/tests/requirement_tests.txt
CIBW_TEST_COMMAND: pytest -s -v {project}/tests
UNIXY_AEC_VERSION: 1.0.4
UNIXY_HDF5_VERSION: 1.14.2
UNIXY_HDF5_VERSION: 1.14.3
WINDOWS_HDF5: 1.14.2

jobs:
Expand All @@ -32,7 +31,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install cibuildwheel
run: |
Expand All @@ -51,48 +50,49 @@ jobs:
- name: Build wheels on Linux
if: runner.os == 'Linux'
env:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_BEFORE_ALL: |
yum -y install zlib-devel
CIBW_ENVIRONMENT_PASS: "STATIC_HDF5 CMAKE_PREFIX_PATH"
CIBW_BEFORE_BUILD: |
# CMake complains if the dependencies come from within the same tree
# as the source, so we'll just pretend they are elsewhere
mkdir -p $PWD/src-cache
ln -s $PWD/src-cache /opt/src-cache
bash ci/hdf5-build.sh /opt/src-cache
mkdir -p /host/home/runner/work/src-cache
ln -s /host/home/runner/work/src-cache /opt/hdf5-static
bash ci/hdf5-build.sh /opt/hdf5-static
run: |
export HDF5_ROOT=/opt/src-cache/install-
export CIBW_ENVIRONMENT_PASS=HDF5_ROOT
# used by setup.py to decide if to set `FindHDF5` to use static hdf5 libraries
export STATIC_HDF5=True
export CMAKE_PREFIX_PATH=/opt/hdf5-static/install-/install/
python -m cibuildwheel --output-dir dist
CIBW_MANYLINUX_X86_64_IMAGE=manylinux2014 python -m cibuildwheel --output-dir dist
CIBW_MANYLINUX_X86_64_IMAGE=manylinux_2_28 python -m cibuildwheel --output-dir dist
- name: Build wheels Mac OS
if: runner.os == 'macOS'
env:
CIBW_ENVIRONMENT_PASS: "HDF5_ROOT CMAKE_OSX_ARCHITECTURES MACOSX_DEPLOYMENT_TARGET"
CIBW_ENVIRONMENT_PASS: "STATIC_HDF5 CMAKE_PREFIX_PATH CMAKE_OSX_ARCHITECTURES MACOSX_DEPLOYMENT_TARGET"
CIBW_BEFORE_BUILD: |
# CMake complains if the dependencies come from within the same tree
# as the source, so we'll just pretend they are elsewhere
mkdir -p $PWD/src-cache
ln -s $PWD/src-cache /Users/runner/work/src-cache
bash ci/hdf5-build.sh /Users/runner/work/src-cache
run: |
# used by setup.py to decide if to set `FindHDF5` to use static hdf5 libraries
export STATIC_HDF5=True
# x86_64 macOS allows for cross compilation; first we do arm64,
# only for the 11.0 target; and store in the cache the compiled code...
export CIBW_ARCHS_MACOS="arm64"
export CMAKE_OSX_ARCHITECTURES="arm64"
export MACOSX_DEPLOYMENT_TARGET="11.0"
export HDF5_ROOT=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS
export CMAKE_PREFIX_PATH=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS/install
python -m cibuildwheel --output-dir dist
# ...and now we do both targets for x86_64
export CIBW_ARCHS_MACOS="x86_64"
export CMAKE_OSX_ARCHITECTURES="x86_64"
unset MACOSX_DEPLOYMENT_TARGET
export HDF5_ROOT=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS
export CMAKE_PREFIX_PATH=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS/install
python -m cibuildwheel --output-dir dist
- name: Cache HDF5 On Windows
Expand Down
106 changes: 27 additions & 79 deletions ci/hdf5-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,28 @@ set -e -x
export INPUT=$(cd $(dirname "$1") && pwd -P)/$(basename "$1")
export OUTPUT="$INPUT/install-$CIBW_ARCHS_MACOS"

: "${ZLIB_VERSION:=1.3}"
: "${UNIXY_AEC_VERSION:=1.0.4}"
: "${UNIXY_HDF5_VERSION:=1.14.2}"

function download_unpack_zlib {
pushd "$INPUT"
rm -rf "zlib-$ZLIB_VERSION"
echo "Downloading & unpacking ZLIB ${ZLIB_VERSION}"
curl -sLO https://zlib.net/fossils/zlib-$ZLIB_VERSION.tar.gz
tar xzf zlib-$ZLIB_VERSION.tar.gz
popd
}

function download_unpack_libaec {
pushd "$INPUT"
rm -rf "libaec-$UNIXY_AEC_VERSION"
echo "Downloading & unpacking aec ${UNIXY_AEC_VERSION}"
curl -fsSLO "https://gitlab.dkrz.de/k202009/libaec/uploads/ea0b7d197a950b0c110da8dfdecbb71f/libaec-${UNIXY_AEC_VERSION}.tar.gz"
tar zxf "libaec-$UNIXY_AEC_VERSION.tar.gz"
popd
}
: "${UNIXY_HDF5_VERSION:=1.14.3}"

function download_unpack_hdf5 {
pushd "$INPUT"
rm -rf hdf5-$UNIXY_HDF5_VERSION
echo "Downloading & unpacking HDF5 ${UNIXY_HDF5_VERSION}"
curl -fsSLO "https://www.hdfgroup.org/ftp/HDF5/releases/hdf5-${UNIXY_HDF5_VERSION%.*}/hdf5-$UNIXY_HDF5_VERSION/src/hdf5-$UNIXY_HDF5_VERSION.tar.gz"
tar xzf "hdf5-$UNIXY_HDF5_VERSION.tar.gz"
local name=CMake-hdf5-$UNIXY_HDF5_VERSION.tar.gz
if [[ ! -e $name ]]; then
echo "Downloading & unpacking HDF5 ${UNIXY_HDF5_VERSION}"
curl -fsSLO "https://www.hdfgroup.org/ftp/HDF5/releases/hdf5-${UNIXY_HDF5_VERSION%.*}/hdf5-$UNIXY_HDF5_VERSION/src/$name"
fi
tar xzf "$name"
popd
}

if [[ "$OSTYPE" == "darwin"* ]]; then
lib_name=libhdf5.dylib
NPROC=$(sysctl -n hw.ncpu)
else
lib_name=libhdf5.so
NPROC=$(nproc)
fi

if [[ -f "$OUTPUT/lib/$lib_name" ]]; then
INSTALL="$OUTPUT/install"

if [[ -f "$INSTALL/lib/libhdf5.a" ]]; then
echo "using cached build"
else
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -53,60 +35,26 @@ else
export CFLAGS="$CFLAGS -arch $CIBW_ARCHS_MACOS"
export CPPFLAGS="$CPPFLAGS -arch $CIBW_ARCHS_MACOS"
export CXXFLAGS="$CXXFLAGS -arch $CIBW_ARCHS_MACOS"

download_unpack_zlib

pushd "$INPUT/zlib-$ZLIB_VERSION"
./configure \
--archs="-arch $CIBW_ARCHS_MACOS" \
--prefix="$OUTPUT"
make
make install
popd

ZLIB_ARG="--with-zlib=$OUTPUT"

if [[ "$CIBW_ARCHS_MACOS" = "arm64" ]]; then
HOST_ARG="--host=aarch64-apple-darwin"
fi
fi

echo "Building & installing libaec"
download_unpack_libaec
pushd "$INPUT/libaec-$UNIXY_AEC_VERSION"
./configure \
--prefix="$OUTPUT" \
${HOST_ARG} \
--enable-static=no

make -j "$NPROC"
make install
popd

echo "Building & installing hdf5"
download_unpack_hdf5
pushd "$INPUT/hdf5-$UNIXY_HDF5_VERSION"
./configure \
--prefix="$OUTPUT" \
--with-szlib="$OUTPUT" \
${HOST_ARG} \
${ZLIB_ARG} \
--enable-build-mode=production \
--enable-tools=no \
--enable-tests=no \
--enable-static=no

# {
# work around for crosscompile getting: `./H5detect: Bad CPU type in executable`
# so build it on the host architecture instead
pushd src
( export ARCHFLAGS= ; make H5detect H5make_libsettings CFLAGS= CCLDFLAGS= CXXFLAGS= CPPFLAGS= )
popd
# }

make -j "$NPROC"
make install
popd

file "$OUTPUT"/lib/*
cmake -B "$OUTPUT/build" -G'Unix Makefiles' \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_SHARED_LIBS=OFF \
-DHDF5_BUILD_UTILS=OFF \
-DHDF5_BUILD_HL_LIB=OFF \
-DHDF5_BUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DHDF5_BUILD_TOOLS=OFF \
-DHDF5_ENABLE_SZIP_ENCODING=OFF \
-DHDF5_ENABLE_Z_LIB_SUPPORT=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL" \
-S "$INPUT/CMake-hdf5-$UNIXY_HDF5_VERSION/hdf5-$UNIXY_HDF5_VERSION"

cmake --build "$OUTPUT/build" -j "$NPROC"
cmake --install "$OUTPUT/build"
fi

find "$OUTPUT"
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def build_extension(self, ext):

build_args = ['--config', cfg]

if "STATIC_HDF5" in os.environ:
cmake_args += ["-DHDF5_USE_STATIC_LIBRARIES=True", ]

cmake_args += ['-DCMAKE_BUILD_TYPE={}'.format(cfg),
'-DMorphIO_CXX_WARNINGS=OFF',
'-GNinja',
Expand Down

0 comments on commit 4a8c02e

Please sign in to comment.