Skip to content

Instantly share code, notes, and snippets.

@Alexander-Barth
Created July 16, 2020 07:39
Show Gist options
  • Save Alexander-Barth/362485088fe112bd305c75313eba15c1 to your computer and use it in GitHub Desktop.
Save Alexander-Barth/362485088fe112bd305c75313eba15c1 to your computer and use it in GitHub Desktop.
HDF5 BB
using BinaryBuilder
# Collection of sources required to build HDF5
name = "HDF5"
version = v"1.12.0"
sources = [
GitSource("https://github.com/steven-varga/hdf5.git",
"b49b22d6882d97b1ec01d482822955bd8e923203"),
# Crib MacOS binaries from PyPI
FileSource("https://files.pythonhosted.org/packages/2c/47/e0d58be6f292684a4541d10b1da953542ff679f3ffc6096bee73634832b1/h5py-2.10.0-cp27-cp27m-macosx_10_6_intel.whl", "ecf4d0b56ee394a0984de15bceeb97cbe1fe485f1ac205121293fc44dcf3f31f"),
# Native build for arm
ArchiveSource("https://github.com/JuliaPackaging/Yggdrasil/releases/download/HDF5-arm-linux-gnueabihf-v1.10.5/hdf5-arm-linux-gnueabihf-v1.10.5.tar.gz", "12797e8f8b864dd1a5846c09a3efa21439844f76507483b373690b22bc2f09d7"),
]
# Bash recipe for building across all platforms
script = raw"""
CMAKE_ARGS=()
if [[ ${target} == arm-linux-* ]]; then
apk add qemu-arm
QEMU=qemu-arm
fi
if [[ ${target} == aarch64-linux-* ]]; then
apk add qemu-aarch64
QEMU=qemu-aarch64
fi
if [[ ${target} == powerpc64le-linux-* ]]; then
apk add qemu-ppc64le
QEMU=qemu-ppc64le
fi
if [ -n "$QEMU" ]; then
echo -e '#!/bin/sh\nexec '$QEMU' -L /opt/'$target/$target'/sys-root/ "$@"' > /tmp/emulator
chmod +x /tmp/emulator
CMAKE_ARGS+=("-DCMAKE_CROSSCOMPILING_EMULATOR=/tmp/emulator")
fi
# still necesarry
if [[ ${target} == x86_64-linux-* ]] || [[ ${target} == i686-linux-* ]]; then
# no enumlator
echo -e '#!/bin/sh\nexec "$@"' > /tmp/emulator
chmod +x /tmp/emulator
CMAKE_ARGS+=("-DCMAKE_CROSSCOMPILING_EMULATOR=/tmp/emulator")
fi
if [[ ${target} == *-w64-mingw32 ]]; then
apk add wine freetype
# wine64 works also on Windows(:i686)
CMAKE_ARGS+=("-DCMAKE_CROSSCOMPILING_EMULATOR=wine64")
fi
if [ ${target} == "x86_64-w64-mingw32" ]; then
apk add wine freetype
CMAKE_ARGS+=("-DCMAKE_CROSSCOMPILING_EMULATOR=wine64")
fi
if [[ ${target} == x86_64-apple-darwin* ]]; then
# previous method
cd ${WORKSPACE}/srcdir/
WHL_FILE="h5py-*macosx*.whl"
LIBSDIR=.dylibs
unzip "${WHL_FILE}"
mv h5py/${LIBSDIR}/lib{sz,aec,hdf5}* ${prefix}/lib
for f in ${prefix}/lib/lib{sz,aec,hdf5}*; do
install_name_tool -change $(basename h5py/${LIBSDIR}/libz*.${dlext}*) libz.1.${dlext} ${f}
done
# Use headers from the ARM build, with the hope that they'll be fine
# -> actually, the header files are from a different version and the library
cp ${WORKSPACE}/srcdir/hdf5-arm-linux-gnueabihf-*/include/* "${prefix}/include"
else
# cross-compile
cd ${WORKSPACE}/srcdir/hdf5/
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${prefix} \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DHDF5_BUILD_CPP_LIB=OFF \
-DONLY_SHARED_LIBS=ON \
-DHDF5_BUILD_HL_LIB=ON \
-DHDF5_ENABLE_Z_LIB_SUPPORT=ON \
-DHDF5_ENABLE_SZIP_SUPPORT=OFF \
-DHDF5_ENABLE_SZIP_ENCODING=OFF \
-DBUILD_TESTING=OFF \
"${CMAKE_ARGS[@]}"
make -j${nproc}
make install
fi
if [ ${target} == "x86_64-w64-mingw32" ]; then
cp $prefix/bin/hdf5.dll $prefix/bin/libhdf5.dll
cp $prefix/bin/hdf5_hl.dll $prefix/bin/libhdf5_hl.dll
fi
install_license ${WORKSPACE}/srcdir/hdf5/COPYING*
"""
# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
#platforms = supported_platforms()
platforms = [
Linux(:i686, libc=:glibc),
Linux(:x86_64, libc=:glibc),
Linux(:aarch64, libc=:glibc),
Linux(:armv7l, libc=:glibc, call_abi=:eabihf),
Linux(:powerpc64le, libc=:glibc),
Linux(:i686, libc=:musl),
Linux(:x86_64, libc=:musl),
Linux(:aarch64, libc=:musl),
Linux(:armv7l, libc=:musl, call_abi=:eabihf),
#MacOS(:x86_64),
# FreeBSD(:x86_64),
#Windows(:i686),
Windows(:x86_64),
]
# The products that we will ensure are always built
products = [
LibraryProduct("libhdf5", :libhdf5),
LibraryProduct("libhdf5_hl", :libhdf5_hl),
]
# Dependencies that must be installed before this package can be built
dependencies = [
Dependency("Zlib_jll"),
]
# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment