Skip to content

Bug fixes for package netcdf-cxx4 on macOS, align netcdf-cxx4 with netcdf-fortran#29246

Merged
scheibelp merged 27 commits intospack:developfrom
climbfuji:bugfix/netcdf_cxx4_macos
Apr 14, 2022
Merged

Bug fixes for package netcdf-cxx4 on macOS, align netcdf-cxx4 with netcdf-fortran#29246
scheibelp merged 27 commits intospack:developfrom
climbfuji:bugfix/netcdf_cxx4_macos

Conversation

@climbfuji
Copy link
Copy Markdown
Contributor

This PR fixes a problem building netcdf-cxx4 (all the way up to the latest public release 4.3.1) on macOS with its semi case-sensitive file systems. An additional bug fix is required to get the correct library dependency on netcdf-c into the netcdf-cxx4 build on macOS, which uses libtool.

The PR also aligns the netcdf-cxx4 package config with the (better maintained) netcdf-fortran package config.

Fixes #29245
Fixes #26559

This PR was tested on macOS Monterey with [email protected] (and [email protected]), as well as on a Cray (NOAA-GFDL Gaea) with [email protected].

…e-sensitive filesystems; build package netcdf-cxx4 consistently with netcdf-fortran
variant('shared', default=True, description='Enable shared library')
variant('pic', default=True, description='Produce position-independent code (for shared libs)')
variant('doxygen', default=True, description='Enable doxygen docs')
variant('doc', default=False, description='Enable doxygen docs')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this renaming. Thank you!

# can correctly link to all the dependencies even when the
# building takes place outside of Spack environment, i.e.
# without Spack's compiler wrappers.
config_flags = [self.spec['netcdf-c'].libs.search_flags]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable config_flags is set but seems not to be used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from the netcdf-fortran package as well, but I missed returning the flags. Since you said it's not needed, I'll remove it here and in netcdf-fortran. Yes, I noticed that there are no .la files and I was wondering why netcdf-fortran had this code.

# On macOS, we also need to add this to ldflags
if self.spec.satisfies("platform=darwin"):
flags = [self.spec['netcdf-c'].libs.search_flags,
self.spec['netcdf-c'].libs.link_flags] + flags
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious to learn why you think link_flags should be added. As far as I know, the configure script appends -lnetcdf automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely needed on macOS (in this or another way). I built netcdf-c with spack and netcdf-fortran as-is in the current spack repo, but netcdf-cxx4 did not have the -L.../netcdf-c/lib -lnetcdf in the linker line.

if '+mpi' in netcdf_c_spec or '+parallel-netcdf' in netcdf_c_spec:
config_args.append('CC=%s' % self.spec['mpi'].mpicc)
config_args.append('FC=%s' % self.spec['mpi'].mpifc)
config_args.append('F77=%s' % self.spec['mpi'].mpif77)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt that setting FC and F77 is needed for this package. I would add setting CXX and check whether CC is needed. In any case, thanks for trying to make this consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, good point. I'll remove Fortran and check if we still need to set CC.

# Unidata has fixed this in their development track:
# https://github.com/Unidata/netcdf-cxx4/commit/41c0233cb964a3ee1d4e5db5448cd28d617925fb
os.rename('VERSION', 'config.VERSION')
super(NetcdfCxx4, self).build(spec, prefix)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you, please, check whether this can be replaced with (also for version 4.3.0):

patch('https://github.com/Unidata/netcdf-cxx4/commit/e7cc5bab02cf089dc79616456a0a951fee979fe9.patch',
      sha256='ba466b887c7ad2710e6d394046bc0742a2f4043d98bd21d5b08f33dc9d7f392d',
      when='@:4.3.1 platform=darwin')

I have used Unidata/netcdf-cxx4@e7cc5ba because that's the commit in the master upstream.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I got this - will update the sha hash in my next test:

==> Error: ChecksumError: sha256 checksum failed for /Users/heinzell/work/jedi-stack/spack-stack-new-joint/spack-stack-develop-20220215/cache/build_stage/spack-stage-u032oec1/e7cc5bab02cf089dc79616456a0a951fee979fe9.patch
    Expected ba466b887c7ad2710e6d394046bc0742a2f4043d98bd21d5b08f33dc9d7f392d but got 4ddf6db9dc0c5f754cb3d68b1dbef8c385cf499f6e5df8fbccae3749336ba84a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, should be 4ddf6db9dc0c5f754cb3d68b1dbef8c385cf499f6e5df8fbccae3749336ba84a indeed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to run spack clean -m after the update and before the attempt to build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I have learned (the hard way) that making spack forget isn't that easy ... The patch works just fine.

@skosukhin
Copy link
Copy Markdown
Member

skosukhin commented Feb 28, 2022

I have just realized that I contradict myself regarding the MPI wrappers. See #17051, which also explains why we need to add -lnetcdf (not only on MacOs).

Not that I really mind building with the MPI wrappers (btw, the comment in this PR refers to the Fortran-related documentation, is there one for C++?) but I normally try to avoid overlinking and would like to learn why exactly we should use the wrappers.

@climbfuji
Copy link
Copy Markdown
Contributor Author

I have just realized that I contradict myself regarding the MPI wrappers. See #17051, which also explains why we need to add -lnetcdf (not only on MacOs).

Not that I really mind building with the MPI wrappers (btw, the comment in this PR refers to the Fortran-related documentation, is there one for C++?) but I normally try to avoid overlinking and would like to learn why exactly we should use the wrappers.

I can try building without the MPI wrappers. Maybe that problem is solved by linking against the netcdf-c library. I remember I got the missing MPI symbols first, so I put the MPI wrappers in place, before I ran into and fixed the netcdf-c linker problem.

@skosukhin
Copy link
Copy Markdown
Member

@climbfuji thanks, please, keep in mind that the direct dependency on MPI might be unintended. For example, see #6632

@climbfuji
Copy link
Copy Markdown
Contributor Author

@climbfuji thanks, please, keep in mind that the direct dependency on MPI might be unintended. For example, see #6632

Without any MPI wrapper, I get this:

     393    In file included from /Users/heinzell/work/jedi-stack/spack-stack-new-joint/spack-stack-develop-20220215/envs/jedi-fv3.netcdfcxxtest.macos/install/clang/13.0.0/hdf5-1.12.1-i23lyyj/include/hdf5.h:22:
  >> 394    /Users/heinzell/work/jedi-stack/spack-stack-new-joint/spack-stack-develop-20220215/envs/jedi-fv3.netcdfcxxtest.macos/install/clang/13.0.0/hdf5-1.12.1-i23lyyj/include/H5public.h:63:10: fatal error: 'mpi.h' file not found
     395    #include <mpi.h>
     396             ^~~~~~~

Will try with just the mpicxx wrapper next.

@climbfuji
Copy link
Copy Markdown
Contributor Author

@climbfuji thanks, please, keep in mind that the direct dependency on MPI might be unintended. For example, see #6632

Without any MPI wrapper, I get this:

     393    In file included from /Users/heinzell/work/jedi-stack/spack-stack-new-joint/spack-stack-develop-20220215/envs/jedi-fv3.netcdfcxxtest.macos/install/clang/13.0.0/hdf5-1.12.1-i23lyyj/include/hdf5.h:22:
  >> 394    /Users/heinzell/work/jedi-stack/spack-stack-new-joint/spack-stack-develop-20220215/envs/jedi-fv3.netcdfcxxtest.macos/install/clang/13.0.0/hdf5-1.12.1-i23lyyj/include/H5public.h:63:10: fatal error: 'mpi.h' file not found
     395    #include <mpi.h>
     396             ^~~~~~~

Will try with just the mpicxx wrapper next.

Same problem with just the MPICXX wrapper, as expected.

@spackbot-app spackbot-app bot added the patch label Feb 28, 2022
@climbfuji climbfuji requested a review from skosukhin February 28, 2022 18:23
@skosukhin
Copy link
Copy Markdown
Member

@climbfuji could you, please, tell me which MPI library you use? I find it strange that Spack compiler wrapper does not inject the required -I/path/to/mpi_h flag.

@climbfuji
Copy link
Copy Markdown
Contributor Author

@climbfuji could you, please, tell me which MPI library you use? I find it strange that Spack compiler wrapper does not inject the required -I/path/to/mpi_h flag.

mpich-3.4.3 installed via homebrew (i.e. an external package for spack)

This makes it consistent with other packages from the NetCDF
constellation: always build the static libraries and additionally
build the shared ones when '+shared'.
This makes it consistent with other packages from the NetCDF
constellation: build the shared libraries with the PIC flag and
the static ones without it (the default for Autotools) when
'~pic', and build the static libraries with PIC when '+pic' (to
make them injectable into other shared libraries).
@climbfuji
Copy link
Copy Markdown
Contributor Author

@skosukhin @WardF I think this is ready to merge with your (Sergey's updates). Would you be able to review this? Thanks a lot in advance!

@climbfuji
Copy link
Copy Markdown
Contributor Author

@skosukhin @WardF I have tested this to the bones on numerous systems (macOS, Linux, Cray) with several compilers (clang, gnu, intel) in the last ten days. Can we get this merged? Thanks a lot in in advance for your time.

@climbfuji
Copy link
Copy Markdown
Contributor Author

@skosukhin @WardF I am sorry that I have to keep asking, but can we get this merged, please? It passed all the CI tests and works on all our platforms. I just updated the branch once again ... thanks very much!

@skosukhin
Copy link
Copy Markdown
Member

@climbfuji none of us can actually do the merge. All I can do is write LGTM.
@haampie I've picked you almost randomly :) could you, please, merge this or poke someone else who can do it? Thanks!

@climbfuji
Copy link
Copy Markdown
Contributor Author

@climbfuji none of us can actually do the merge. All I can do is write LGTM.
@haampie I've picked you almost randomly :) could you, please, merge this or poke someone else who can do it? Thanks!

Thanks, @skosukhin - appreciate your time.

@climbfuji
Copy link
Copy Markdown
Contributor Author

Any update on this PR?

@scheibelp scheibelp self-assigned this Apr 12, 2022
Copy link
Copy Markdown
Member

@scheibelp scheibelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a couple questions

(I can merge this once those are resolved)

@scheibelp scheibelp merged commit bb70e6f into spack:develop Apr 14, 2022
@scheibelp
Copy link
Copy Markdown
Member

Thanks!

@climbfuji
Copy link
Copy Markdown
Contributor Author

Thanks indeed!

@climbfuji climbfuji deleted the bugfix/netcdf_cxx4_macos branch April 14, 2022 17:18
joequant pushed a commit to hkphysics/spack that referenced this pull request Apr 17, 2022
Bug fixes for package netcdf-cxx4 so that it builds on macOS semi
case-sensitive filesystems; this includes additional changes to build
netcdf-cxx4 consistently with netcdf-fortran.

* netcdf-fortran: remove unused config_flags
* netcdf-fortran: avoid building without the optimization flags
* netcdf-cxx4: do not enforce autoreconf. This was a rudiment from the
  times when the package was fetched with git, which broke timestamp
  order of the automatically generated Autoconf files.
* netcdf-cxx4: inject PIC flags for C++ when '+pic'
* netcdf-cxx4: inject C/CXXFLAGS via the wrapper
* netcdf-cxx4: fix the underlinking problem for platforms other than darwin
  (add netcdf-c libs netcdf-cxx4 ldlibs flags)
* netcdf-cxx4: remove redundant extension of CPPFLAGS
* netcdf-cxx4: only need to use MPI compiler wrapper when building C
  (vs both C and C++)
* netcdf-cxx4: remove variant 'static'
  This makes it consistent with other packages from the NetCDF
  constellation: always build the static libraries and additionally
  build the shared ones when '+shared'.
* netcdf-cxx4: do not configure --with/--without-pic.
  This makes it consistent with other packages from the NetCDF
  constellation: build the shared libraries with the PIC flag and
  the static ones without it (the default for Autotools) when
  '~pic', and build the static libraries with PIC when '+pic' (to
  make them injectable into other shared libraries).
* netcdf-cxx4: run the tests serially
* netcdf-cxx4: build the plugins only when the tests are run

Co-authored-by: Sergey Kosukhin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make netcdf-cxx4 package config inconsistent with netcdf-fortran package config Installation issue: netcdf-cxx4 on MacOS BigSur

3 participants