lapack,blas: allow for more flexible use of ILP64 interface

This commit is contained in:
Markus Kowalewski 2022-02-08 20:20:38 +01:00 committed by Markus Kowalewski
parent 7c5a72ae2e
commit 39210e89c2
No known key found for this signature in database
GPG key ID: 502A248E3FB4FF48
2 changed files with 33 additions and 27 deletions

View file

@ -1,7 +1,7 @@
{ lib, stdenv
, lapack-reference, openblasCompat, openblas
, lapack-reference, openblas
, isILP64 ? false
, blasProvider ? if isILP64 then openblas else openblasCompat }:
, blasProvider ? openblas }:
let
blasFortranSymbols = [
@ -32,10 +32,13 @@ let
blasImplementation = lib.getName blasProvider;
blasProvider' = if blasImplementation == "mkl"
then blasProvider
else blasProvider.override { blas64 = isILP64; };
in
assert isILP64 -> (blasImplementation == "openblas" && blasProvider.blas64) || blasImplementation == "mkl";
assert isILP64 -> blasImplementation == "mkl" || blasProvider'.blas64;
stdenv.mkDerivation {
pname = "blas";
@ -43,13 +46,13 @@ stdenv.mkDerivation {
outputs = [ "out" "dev" ];
meta = (blasProvider.meta or {}) // {
meta = (blasProvider'.meta or {}) // {
description = "${lib.getName blasProvider} with just the BLAS C and FORTRAN ABI";
};
passthru = {
inherit isILP64;
provider = blasProvider;
provider = blasProvider';
implementation = blasImplementation;
};
@ -62,10 +65,10 @@ stdenv.mkDerivation {
installPhase = (''
mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
libblas="${lib.getLib blasProvider}/lib/libblas${canonicalExtension}"
libblas="${lib.getLib blasProvider'}/lib/libblas${canonicalExtension}"
if ! [ -e "$libblas" ]; then
echo "$libblas does not exist, ${blasProvider.name} does not provide libblas."
echo "$libblas does not exist, ${blasProvider'.name} does not provide libblas."
exit 1
fi
@ -79,11 +82,11 @@ stdenv.mkDerivation {
'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
patchelf --set-soname libblas${canonicalExtension} $out/lib/libblas${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libblas${canonicalExtension}):${lib.getLib blasProvider}/lib" $out/lib/libblas${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libblas${canonicalExtension}
'' else if stdenv.hostPlatform.isDarwin then ''
install_name_tool \
-id $out/lib/libblas${canonicalExtension} \
-add_rpath ${lib.getLib blasProvider}/lib \
-add_rpath ${lib.getLib blasProvider'}/lib \
$out/lib/libblas${canonicalExtension}
'' else "") + ''
@ -99,10 +102,10 @@ Libs: -L$out/lib -lblas
Cflags: -I$dev/include
EOF
libcblas="${lib.getLib blasProvider}/lib/libcblas${canonicalExtension}"
libcblas="${lib.getLib blasProvider'}/lib/libcblas${canonicalExtension}"
if ! [ -e "$libcblas" ]; then
echo "$libcblas does not exist, ${blasProvider.name} does not provide libcblas."
echo "$libcblas does not exist, ${blasProvider'.name} does not provide libcblas."
exit 1
fi
@ -111,11 +114,11 @@ EOF
'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
patchelf --set-soname libcblas${canonicalExtension} $out/lib/libcblas${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libcblas${canonicalExtension}):${lib.getLib blasProvider}/lib" $out/lib/libcblas${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libcblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libcblas${canonicalExtension}
'' else if stdenv.hostPlatform.isDarwin then ''
install_name_tool \
-id $out/lib/libcblas${canonicalExtension} \
-add_rpath ${lib.getLib blasProvider}/lib \
-add_rpath ${lib.getLib blasProvider'}/lib \
$out/lib/libcblas${canonicalExtension}
'' else "") + ''
if [ "$out/lib/libcblas${canonicalExtension}" != "$out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
@ -135,6 +138,6 @@ EOF
mkdir -p $out/nix-support
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
ln -s $out/lib/libblas${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
ln -sf ${blasProvider}/include/* $dev/include
ln -sf ${blasProvider'}/include/* $dev/include
'');
}

View file

@ -1,7 +1,7 @@
{ lib, stdenv
, lapack-reference, openblasCompat, openblas
, lapack-reference, openblas
, isILP64 ? false
, lapackProvider ? if isILP64 then openblas else openblasCompat }:
, lapackProvider ? openblas }:
let
@ -11,10 +11,13 @@ let
else stdenv.hostPlatform.extensions.sharedLibrary;
lapackImplementation = lib.getName lapackProvider;
lapackProvider' = if lapackImplementation == "mkl"
then lapackProvider
else lapackProvider.override { blas64 = isILP64; };
in
assert isILP64 -> (lapackImplementation == "openblas" && lapackProvider.blas64) || lapackImplementation == "mkl";
assert isILP64 -> lapackImplementation == "mkl" || lapackProvider'.blas64;
stdenv.mkDerivation {
pname = "lapack";
@ -22,13 +25,13 @@ stdenv.mkDerivation {
outputs = [ "out" "dev" ];
meta = (lapackProvider.meta or {}) // {
description = "${lib.getName lapackProvider} with just the LAPACK C and FORTRAN ABI";
meta = (lapackProvider'.meta or {}) // {
description = "${lib.getName lapackProvider'} with just the LAPACK C and FORTRAN ABI";
};
passthru = {
inherit isILP64;
provider = lapackProvider;
provider = lapackProvider';
implementation = lapackImplementation;
};
@ -41,10 +44,10 @@ stdenv.mkDerivation {
installPhase = (''
mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
liblapack="${lib.getLib lapackProvider}/lib/liblapack${canonicalExtension}"
liblapack="${lib.getLib lapackProvider'}/lib/liblapack${canonicalExtension}"
if ! [ -e "$liblapack" ]; then
echo "$liblapack does not exist, ${lapackProvider.name} does not provide liblapack."
echo "$liblapack does not exist, ${lapackProvider'.name} does not provide liblapack."
exit 1
fi
@ -53,7 +56,7 @@ stdenv.mkDerivation {
'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
patchelf --set-soname liblapack${canonicalExtension} $out/lib/liblapack${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapack${canonicalExtension}):${lapackProvider}/lib" $out/lib/liblapack${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapack${canonicalExtension}):${lapackProvider'}/lib" $out/lib/liblapack${canonicalExtension}
'' else "") + ''
if [ "$out/lib/liblapack${canonicalExtension}" != "$out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
@ -70,10 +73,10 @@ Cflags: -I$dev/include
Libs: -L$out/lib -llapack
EOF
liblapacke="${lib.getLib lapackProvider}/lib/liblapacke${canonicalExtension}"
liblapacke="${lib.getLib lapackProvider'}/lib/liblapacke${canonicalExtension}"
if ! [ -e "$liblapacke" ]; then
echo "$liblapacke does not exist, ${lapackProvider.name} does not provide liblapacke."
echo "$liblapacke does not exist, ${lapackProvider'.name} does not provide liblapacke."
exit 1
fi
@ -82,7 +85,7 @@ EOF
'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
patchelf --set-soname liblapacke${canonicalExtension} $out/lib/liblapacke${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapacke${canonicalExtension}):${lib.getLib lapackProvider}/lib" $out/lib/liblapacke${canonicalExtension}
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapacke${canonicalExtension}):${lib.getLib lapackProvider'}/lib" $out/lib/liblapacke${canonicalExtension}
'' else "") + ''
if [ -f "$out/lib/liblapacke.so.3" ]; then
@ -102,6 +105,6 @@ EOF
mkdir -p $out/nix-support
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
ln -s $out/lib/liblapack${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
ln -sf ${lapackProvider}/include/* $dev/include
ln -sf ${lapackProvider'}/include/* $dev/include
'');
}