Skip to content

Commit

Permalink
setup-hooks/audit-blas.sh: init
Browse files Browse the repository at this point in the history
Add a simple hook that makes sure blas and lapack are linked to the
right place.
  • Loading branch information
matthewbauer committed Apr 17, 2020
1 parent 7841b42 commit d83e9c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkgs/build-support/setup-hooks/audit-blas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ensure that we are always linking against “libblas.so.3” and
# “liblapack.so.3”.

auditBlas() {
local dir="$prefix"
[ -e "$dir" ] || return 0

local i
while IFS= read -r -d $'\0' i; do
if ! isELF "$i"; then continue; fi

if $OBJDUMP -p "$i" | grep 'NEEDED' | awk '{ print $2; }' | grep -q '\(libmkl_rt.so\|libopenblas.so.0\)'; then
echo "$i refers to a specific implementation of BLAS or LAPACK."
echo "This prevents users from switching BLAS/LAPACK implementations."
echo "Add \`blas' or \`lapack' to buildInputs instead of \`mkl' or \`openblas'."
exit 1
fi

(IFS=:
for dir in "$(patchelf --print-rpath "$i")"; do
if [ -f "$dir/libblas.so.3" ] || [ -f "$dir/libblas.so" ]; then
if [ "$dir" != "@blas@/lib" ]; then
echo "$dir is not allowed to contain a library named libblas.so.3"
exit 1
fi
fi
if [ -f "$dir/liblapack.so.3" ] || [ -f "$dir/liblapack.so" ]; then
if [ "$dir" != "@lapack@/lib" ]; then
echo "$dir is not allowed to contain a library named liblapack.so.3"
exit 1
fi
fi
done)
done < <(find "$dir" -type f -print0)
}

fixupOutputHooks+=(auditBlas)
4 changes: 4 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ in

### BUILD SUPPORT

auditBlasHook = makeSetupHook
{ name = "auto-blas-hook"; deps = [ blas lapack ]; }
../build-support/setup-hooks/audit-blas.sh;

autoreconfHook = makeSetupHook
{ deps = [ autoconf automake gettext libtool ]; }
../build-support/setup-hooks/autoreconf.sh;
Expand Down

0 comments on commit d83e9c9

Please sign in to comment.