Repository: spack/spack

Issue:
petsc build error after update to hdf5 1.12


### Spack version
Current `develop` branch.

### Steps to reproduce the issue

```console
$ spack install petsc@3.7.7 ^superlu_dist@5.1.3_
```
(The `superlu_dist` version is required until #15551 is merged, an related issue.)

leads to:
```console
/gpfs/alpine/fus123/proj-shared/kaig1/spack/opt/spack/linux-rhel7-power9le/gcc-8.1.1/hdf5-1.12.0-env7kt2iczm4znpvefw4cqb6pbi767a3/include/H5version.h:746:23: error: too few arguments to function 'H5Oget_info3'
   #define H5Oget_info H5Oget_info3
                       ^~~~~~~~~~~~
/tmp/kaig1/spack-stage/spack-stage-petsc-3.7.7-v2q6fsmywzszwwjov2nog6fppzwujepz/spack-src/include/petscviewerhdf5.h:34:37: note: in definition of macro 'PetscStackCallHDF5'
     PetscStackPush(#func);_status = func args;PetscStackPop; if (_status) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in HDF5 call %s() Status %d",#func,(int)_status); \
                                     ^~~~
/tmp/kaig1/spack-stage/spack-stage-petsc-3.7.7-v2q6fsmywzszwwjov2nog6fppzwujepz/spack-src/src/sys/classes/viewer/impls/hdf5/hdf5v.c:729:24: note: in expansion of macro 'H5Oget_info'
     PetscStackCallHDF5(H5Oget_info,(obj, &info));
                        ^~~~~~~~~~~
```

This happens because of an incompatible API change in HDF5 1.12. It affects other packages, too, e.g., #15252.

I can see various options to work around this, ie., limiting hdf5 to :1.10.99, adding `-DH5_USE_110_API`, or updating the code to work with the new API, which in particular for old versions of petsc doesn't seem desirable.

@balay



Discussion:
Perhaps the following change for now.

```
diff --git a/var/spack/repos/builtin/packages/petsc/package.py b/var/spack/repos/builtin/packages/petsc/package.py
index b58fa0c3c..2146a2bdc 100644
--- a/var/spack/repos/builtin/packages/petsc/package.py
+++ b/var/spack/repos/builtin/packages/petsc/package.py
@@ -145,7 +145,7 @@ class Petsc(Package):
     depends_on('metis@5:~int64', when='@3.8:+metis~int64')
     depends_on('metis@5:+int64', when='@3.8:+metis+int64')
 
-    depends_on('hdf5+mpi+hl+fortran', when='+hdf5+mpi')
+    depends_on('hdf5@:1.10.99+mpi+hl+fortran', when='+hdf5+mpi')
     depends_on('zlib', when='+hdf5')
     depends_on('parmetis', when='+metis+mpi')
     depends_on('valgrind', when='+valgrind')
```
PETSc currently defaults to buiding hdf5 with --with-default-api-version=v18 - and this works with hdf5-1.10.2 - but I guess this approach limits usage.. 
We should make PETSc workout that default. We can define `H5_USE_18_API` in the PETSc source that calls HDF5, though it might not be sufficient for other optional packages (like MED, which I already had to patch to get working with HDF5-1.12 built our way).
I think going forward it seems reasonable that petsc should support HDF5 1.12, either by supporting the changed API directly, or by turning on the compat macro. In the spack world, I guess you don't have to worry about dependent packages because they should either support newer hdf5 or specify the need for an older one, so spack will then do the right thing and use the (hopefully existing) least common denominator.

However, for current/past releases I'd say patching them up is not realistic, so I like the solution of requiring hdf5 <= 1.10 in the spack package in that case.

This should resolve your issue; at least it works in my test with hdf5-1.12. It isn't effectively tested by PETSc's test suite (which builds its own HDF5 in a way that works with MED), so it'd be handy if someone other than me could confirm.
https://gitlab.com/petsc/petsc/-/merge_requests/2613
> Current `develop` branch.

@germasch Just a very minor note on reporting. We ask for the output of: 
```
$ spack --version
0.14.0-276-14e2c42bc
```
since `develop` is a moving target, and the output above will give us the hash of the commit you're on in case it's needed :slightly_smiling_face: 

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/petsc/package.py b/var/spack/repos/builtin/packages/petsc/package.py
--- a/var/spack/repos/builtin/packages/petsc/package.py
+++ b/var/spack/repos/builtin/packages/petsc/package.py
@@ -24,6 +24,7 @@ class Petsc(Package):
     version('develop', branch='master')
     version('xsdk-0.2.0', tag='xsdk-0.2.0')
 
+    version('3.12.4', sha256='56a941130da93bbacb3cfa74dcacea1e3cd8e36a0341f9ced09977b1457084c3')
     version('3.12.3', sha256='91f77d7b0f54056f085b9e27938922db3d9bb1734a2e2a6d26f43d3e6c0cf631')
     version('3.12.2', sha256='d874b2e198c4cb73551c2eca1d2c5d27da710be4d00517adb8f9eb3d6d0375e8')
     version('3.12.1', sha256='b72d895d0f4a79acb13ebc782b47b26d10d4e5706d399f533afcd5b3dba13737')
@@ -145,7 +146,7 @@ class Petsc(Package):
     depends_on('metis@5:~int64', when='@3.8:+metis~int64')
     depends_on('metis@5:+int64', when='@3.8:+metis+int64')
 
-    depends_on('hdf5+mpi+hl+fortran', when='+hdf5+mpi')
+    depends_on('hdf5@:1.10.99+mpi+hl+fortran', when='+hdf5+mpi')
     depends_on('zlib', when='+hdf5')
     depends_on('parmetis', when='+metis+mpi')
     depends_on('valgrind', when='+valgrind')


Test patch: