From 9046690c73d913972e510566f03fad33fbe7eaf1 Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Wed, 27 Dec 2023 17:27:10 -0800 Subject: [PATCH] hdf5: refactor to reduce downstream closure size * Only build static libs by default when stdenv.hostPlatform.isStatic * Add separate -bin output * Move h5hlcc/c++ dev binaries to -dev output * Default to building with C++ support to cut down on duplicated hdf5/hdf5-cpp in downstream closures --- .../interpreters/gnudatalanguage/default.nix | 6 ++-- pkgs/tools/misc/hdf5/default.nix | 29 +++++++++++++++++-- pkgs/top-level/all-packages.nix | 5 +++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/pkgs/development/interpreters/gnudatalanguage/default.nix b/pkgs/development/interpreters/gnudatalanguage/default.nix index f4d364fcd144..54b5c5898c87 100644 --- a/pkgs/development/interpreters/gnudatalanguage/default.nix +++ b/pkgs/development/interpreters/gnudatalanguage/default.nix @@ -78,13 +78,15 @@ let if hdf5-forced != null then hdf5-forced else - hdf5.override { + hdf5.override ({ usev110Api = useHdf5v110Api; mpiSupport = enableMPI; inherit mpi; szipSupport = enableSzip; inherit szip; - }; + } // lib.optionalAttrs enableMPI { + cppSupport = false; + }); netcdf-custom = if netcdf-forced != null then netcdf-forced diff --git a/pkgs/tools/misc/hdf5/default.nix b/pkgs/tools/misc/hdf5/default.nix index 89702cfd1a7f..0620f1e29e09 100644 --- a/pkgs/tools/misc/hdf5/default.nix +++ b/pkgs/tools/misc/hdf5/default.nix @@ -3,7 +3,7 @@ , fetchurl , cmake , removeReferencesTo -, cppSupport ? false +, cppSupport ? true , fortranSupport ? false , fortran , zlibSupport ? true @@ -13,6 +13,7 @@ , mpiSupport ? false , mpi , enableShared ? !stdenv.hostPlatform.isStatic +, enableStatic ? stdenv.hostPlatform.isStatic , javaSupport ? false , jdk , usev110Api ? false @@ -58,7 +59,7 @@ stdenv.mkDerivation rec { ; }; - outputs = [ "out" "dev" ]; + outputs = [ "out" "dev" "bin" ]; nativeBuildInputs = [ removeReferencesTo cmake ] ++ optional fortranSupport fortran; @@ -72,6 +73,7 @@ stdenv.mkDerivation rec { cmakeFlags = [ "-DHDF5_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake" + "-DBUILD_STATIC_LIBS=${lib.boolToString enableStatic}" ] ++ lib.optional stdenv.isDarwin "-DHDF5_BUILD_WITH_INSTALL_NAME=ON" ++ lib.optional cppSupport "-DHDF5_BUILD_CPP_LIB=ON" ++ lib.optional fortranSupport "-DHDF5_BUILD_FORTRAN=ON" @@ -85,10 +87,33 @@ stdenv.mkDerivation rec { postInstall = '' find "$out" -type f -exec remove-references-to -t ${stdenv.cc} '{}' + + moveToOutput 'bin/' "''${!outputBin}" moveToOutput 'bin/h5cc' "''${!outputDev}" moveToOutput 'bin/h5c++' "''${!outputDev}" moveToOutput 'bin/h5fc' "''${!outputDev}" moveToOutput 'bin/h5pcc' "''${!outputDev}" + moveToOutput 'bin/h5hlcc' "''${!outputDev}" + moveToOutput 'bin/h5hlc++' "''${!outputDev}" + '' + lib.optionalString enableShared + # The shared build creates binaries with -shared suffixes, + # so we remove these suffixes. + '' + mv ''${!outputBin}/bin/h5clear{-shared,} + mv ''${!outputBin}/bin/h5copy{-shared,} + mv ''${!outputBin}/bin/h5debug{-shared,} + mv ''${!outputBin}/bin/h5delete{-shared,} + mv ''${!outputBin}/bin/h5diff{-shared,} + mv ''${!outputBin}/bin/h5dump{-shared,} + mv ''${!outputBin}/bin/h5format_convert{-shared,} + mv ''${!outputBin}/bin/h5import{-shared,} + mv ''${!outputBin}/bin/h5jam{-shared,} + mv ''${!outputBin}/bin/h5ls{-shared,} + mv ''${!outputBin}/bin/h5mkgrp{-shared,} + mv ''${!outputBin}/bin/h5repack{-shared,} + mv ''${!outputBin}/bin/h5repart{-shared,} + mv ''${!outputBin}/bin/h5stat{-shared,} + mv ''${!outputBin}/bin/h5unjam{-shared,} + mv ''${!outputBin}/bin/h5watch{-shared,} ''; enableParallelBuilding = true; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bb25cff7c785..efad037f38b6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9195,7 +9195,10 @@ with pkgs; hdf5_1_10 = callPackage ../tools/misc/hdf5/1.10.nix { }; - hdf5-mpi = hdf5.override { mpiSupport = true; }; + hdf5-mpi = hdf5.override { + mpiSupport = true; + cppSupport = false; + }; hdf5-cpp = hdf5.override { cppSupport = true; };