Files
MX_Pmodule/crystfel/build
T
duan_jandClaude Fable 5.1 9dea762f97 crystfel: bundle HDF5 1.14.6, meson/ninja via uv lock (py3.12), add 0.13.0-rh9
Ra build node has no hdf5-devel/h5cc/hdf5.pc, so meson setup died with
'Dependency "hdf5" not found'. Build now compiles HDF5 (autotools, libdir
lib64 to match crystfel's $ORIGIN/../lib64 RPATH) into $PREFIX and lets
meson find it via $PREFIX/bin/h5cc. meson/ninja come from pyproject.toml +
uv.lock synced into a scratch venv on uv-managed Python 3.12 (system
python 3.9 is EOL for meson >= 1.12).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-27 11:09:58 +01:00

76 lines
4.0 KiB
Python
Executable File

#!/usr/bin/env modbuild
# upstream INSTALL.md: meson setup build && meson compile && meson install.
# default pbuild::prep downloads + sha-verifies the tarballs in files/config.yaml:
# crystfel is unpacked at $SRC_DIR root (strip_dirs:1), the hdf5 tarball is only
# copied there (unpacker: none) and unpacked by hand into $SRC_DIR/hdf5 below.
#
# meson/ninja: Ra's system meson is too old (meson.build wants >= 0.60) and its
# system python is 3.9 (EOL; meson >= 1.12 needs >= 3.10) -> uv syncs the
# versions pinned in pyproject.toml/uv.lock into a throwaway venv on a
# uv-managed Python 3.12, both kept in the build scratch dir, not in $PREFIX.
#
# hdf5: the Ra build node has no hdf5-devel / h5cc / hdf5.pc, so meson's
# dependency('hdf5') fails. HDF5 is compiled into $PREFIX first (autotools, NOT
# cmake: meson's hdf5 config-tool rejects a cmake-built h5cc) and meson finds it
# through $PREFIX/bin/h5cc. --libdir=lib64 matches the $ORIGIN/../lib64 RPATH
# crystfel bakes into its binaries, so the module needs no LD_LIBRARY_PATH.
#
# cd into SRC_DIR explicitly: hooks are not guaranteed to start there, and a
# wrong cwd silently builds nothing (modbuild has no errexit in hooks).
crystfel::env() {
# modbuild's shell strips ~/.local/bin from PATH; override with UV=/path/to/uv if needed
UV="${UV:-$HOME/.local/bin/uv}"
# ~/.cache/uv hits the home disk quota; shared cache reuses wheels across MX builds
export UV_CACHE_DIR="/opt/psi/MX/.uv-cache"
export UV_PROJECT_ENVIRONMENT="${SRC_DIR}/../meson-venv"
export UV_PYTHON_INSTALL_DIR="${SRC_DIR}/../uv-python"
# venv first (meson, ninja), then PREFIX (h5cc for meson's hdf5 lookup)
export PATH="${UV_PROJECT_ENVIRONMENT}/bin:${PREFIX}/bin:${PATH}"
cd "${SRC_DIR}" || std::die 42 "cannot cd to SRC_DIR=${SRC_DIR}"
}
pbuild::configure() {
crystfel::env
[[ -x "$UV" ]] || std::die 42 "uv not found at $UV - run: pip3 install --user uv (or set UV=/path/to/uv)"
for t in flex bison make; do
command -v "$t" >/dev/null || std::die 42 "$t not on PATH - crystfel/hdf5 need it (dnf install $t)"
done
# --locked: die if pyproject.toml and uv.lock disagree instead of silently re-resolving
"$UV" sync --locked --python 3.12 --project "${BUILDBLOCK_DIR}" \
|| std::die 42 "uv sync failed - no meson/ninja venv (PyPI/GitHub reachable? uv.lock stale -> uv lock)"
# HDF5 into $PREFIX: serial, C only, no test suite (halves the build time).
# HDF5_CONFIG_ABORT makes configure die when zlib is missing instead of
# silently building without deflate; szip is not on Ra, so it is switched off
# rather than aborting on it.
mkdir -p hdf5 && tar -xzf hdf5-*.tar.gz -C hdf5 --strip-components=1 \
|| std::die 42 "hdf5 tarball unpack failed - is hdf5-*.tar.gz in ${SRC_DIR}? (prep copies it there)"
( cd hdf5 \
&& HDF5_CONFIG_ABORT=yes ./configure --prefix="${PREFIX}" --libdir="${PREFIX}/lib64" \
--enable-build-mode=production --disable-tests --with-zlib=yes --with-szlib=no \
&& make -j"${JOBS}" && make install ) \
|| std::die 42 "hdf5 build failed - see ${SRC_DIR}/hdf5/config.log (zlib-devel missing?)"
[[ -x "${PREFIX}/bin/h5cc" ]] || std::die 42 "h5cc missing from ${PREFIX}/bin - meson cannot find hdf5 without it"
meson setup build --prefix="${PREFIX}" --libdir=lib64 \
|| std::die 42 "meson setup failed - check build/meson-logs/meson-log.txt"
}
pbuild::compile() {
crystfel::env
meson compile -C build || std::die 42 "meson compile failed"
}
pbuild::install() {
crystfel::env
meson install -C build || std::die 42 "meson install failed"
[[ -x "${PREFIX}/bin/indexamajig" ]] || std::die 42 "indexamajig missing from ${PREFIX}/bin after install"
# ldd follows the whole closure (libcrystfel -> libhdf5): a "not found" here
# means the RPATH/libdir assumption above broke and the module would not run
if ldd "${PREFIX}/bin/indexamajig" | grep "not found"; then
std::die 42 "unresolved shared libs (above) - hdf5 libdir vs crystfel RPATH mismatch"
fi
}