Skip to content

Bug fixes for netcdf-c cmake build#2384

Open
climbfuji wants to merge 20 commits into
spack:developfrom
climbfuji:bugfix/netcdf_c_cmake_build_spack_pkgs
Open

Bug fixes for netcdf-c cmake build#2384
climbfuji wants to merge 20 commits into
spack:developfrom
climbfuji:bugfix/netcdf_c_cmake_build_spack_pkgs

Conversation

@climbfuji
Copy link
Copy Markdown
Contributor

@climbfuji climbfuji commented Nov 12, 2025

Description

This PR fixes two bugs in the netcdf-c cmake build that we identified and fixed in our fork.

  1. ncgen is missing rpaths for hdf5 and won't run - see JCSDA@27bc9e5
  2. Bug fixto find MPI functions when build system is cmake. See CMake can't find MPI_Comm_f2c resulting in unsafe cast in nc_create_par_fortran Unidata/netcdf-c#3199 for details. The solution adopted here is the same as the suggestion made in CMake can't find MPI_Comm_f2c resulting in unsafe cast in nc_create_par_fortran Unidata/netcdf-c#3199, which looks like will make its way into the authoritative codebase soon

Note. This patch is admittedly a bit of a hack. But given the overall state of the netcdf-c CMake build system I believe that this duct-tape solution is good enough. I hope that a overhaul of the entire CMake build for the package will solve this problem in a better way.

Testing

Both patches were tested in https://github.com/JCSDA/spack-stack branch feature/update_to_spack_v1 for intel-oneapi-compilers + intel-oneapi-mpi and gcc + openmpi.

@climbfuji
Copy link
Copy Markdown
Contributor Author

"@when" is not working as expected, will fix together with the style errors.

@climbfuji
Copy link
Copy Markdown
Contributor Author

Reverting to draft while I am still working on this

@climbfuji climbfuji marked this pull request as draft November 12, 2025 13:23
…ith intel-oneapi-compilers+intel-oneapi-mpi and gcc+openmpi
…o bugfix/netcdf_c_cmake_build_spack_pkgs
@climbfuji climbfuji marked this pull request as ready for review November 13, 2025 02:38
@climbfuji
Copy link
Copy Markdown
Contributor Author

@skosukhin @WardF This is ready for your review. I found that the original logic to check if the function exists in CMake was not working reliably. It worked for gcc + openmpi when I included the MPI link libraries as in my original attempt. It didn't work for Intel OneAPI. And I think it wouldn't work for many other MPI providers, because there is no way add an #include mpi.h into the CheckFunctionExists.c cmake file that is used for the test.

I will give this a test on one of the Cray machines that I have access to, but the caveat is that the machine doesn't use they Cray compiler wrappers in our spack config (it uses the vendor compilers like on non-Cray machines).

@climbfuji
Copy link
Copy Markdown
Contributor Author

@skosukhin @WardF This is ready for your review. I found that the original logic to check if the function exists in CMake was not working reliably. It worked for gcc + openmpi when I included the MPI link libraries as in my original attempt. It didn't work for Intel OneAPI. And I think it wouldn't work for many other MPI providers, because there is no way add an #include mpi.h into the CheckFunctionExists.c cmake file that is used for the test.

I will give this a test on one of the Cray machines that I have access to, but the caveat is that the machine doesn't use they Cray compiler wrappers in our spack config (it uses the vendor compilers like on non-Cray machines).

Update. I tested this on a number of machines, including Cray systems with at least two compilers (GNU and Intel LLVM). For each system/compiler/mpi combination the symbols MPI_{Comm,Info}_f2c are found with this patch.

@climbfuji
Copy link
Copy Markdown
Contributor Author

Pinging the reviewers to take a look at this PR, please. Thanks!

@climbfuji
Copy link
Copy Markdown
Contributor Author

Pinging the reviewers to take a look at this PR, please. Thanks!

Pinging all the reviewers once more before asking the spack developers to proceed w/o approval. Thanks very much in advance!

@skosukhin @WardF @johnwparent

Comment thread repos/spack_repo/builtin/packages/netcdf_c/package.py Outdated
Comment thread repos/spack_repo/builtin/packages/netcdf_c/package.py
Explicitly set CMAKE_INSTALL_RPATH_USE_LINK_PATH to TRUE
Comment thread repos/spack_repo/builtin/packages/netcdf_c/package.py
Comment thread repos/spack_repo/builtin/packages/netcdf_c/package.py
@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent Is there anything I can do to move this PR forward? Thanks!

@johnwparent
Copy link
Copy Markdown
Contributor

@johnwparent Is there anything I can do to move this PR forward? Thanks!

Nothing from your end, more a bandwidth issue from my end, will be getting to this shortly!

@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent Is there anything I can do to move this PR forward? Thanks!

Nothing from your end, more a bandwidth issue from my end, will be getting to this shortly!

Thanks, very much appreciated!

@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent Did you have a chance to look at this? Thank you.

Otherwise CMake will choke on a Windows escape character if based in the C: drive

Signed-off-by: John Parent <john.parent@kitware.com>
@johnwparent
Copy link
Copy Markdown
Contributor

@johnwparent Did you have a chance to look at this? Thank you.

Thanks for the ping, resolved by #4293

@climbfuji
Copy link
Copy Markdown
Contributor Author

climbfuji commented Apr 14, 2026

@johnwparent Did you have a chance to look at this? Thank you.

Thanks for the ping, resolved by #4293

This PR does more/other stuff than #4293. Which part of this PR #2384 is resolved by #4293?

@johnwparent
Copy link
Copy Markdown
Contributor

@johnwparent Did you have a chance to look at this? Thank you.

Thanks for the ping, resolved by #4293

This PR does more/other stuff than #4293. Which part of this PR #2384 is resolved by #4293?

Sorry, should have been clear, the CI failure I promised to look into is fixed by that PR

@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent Did you have a chance to look at this? Thank you.

Thanks for the ping, resolved by #4293

This PR does more/other stuff than #4293. Which part of this PR #2384 is resolved by #4293?

Sorry, should have been clear, the CI failure I promised to look into is fixed by that PR

Ahh, that makes sense. I'll wait for #4293 to be merged then. Thanks!

@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent I pulled in your changes from #4293 and the basic unit tests now pass for Windows. The gitlab-ci tests are still being queued.

@climbfuji
Copy link
Copy Markdown
Contributor Author

@johnwparent What do we need to do to move your PR forward so that I can update this PR and we can review & merge?

@johnwparent
Copy link
Copy Markdown
Contributor

@johnwparent What do we need to do to move your PR forward so that I can update this PR and we can review & merge?

@climbfuji I just need to be able to successfully reproduce the paraview build failure locally. So far no dice. I'll let you know as soon as that's ready

@johnwparent
Copy link
Copy Markdown
Contributor

Blocker fix is merged, let's rebase and LGTM

…o bugfix/netcdf_c_cmake_build_spack_pkgs
@climbfuji
Copy link
Copy Markdown
Contributor Author

Blocker fix is merged, let's rebase and LGTM

Thanks, done! Please take another look.

@climbfuji
Copy link
Copy Markdown
Contributor Author

This error is new, I haven't changed anything, though, just pulled in develop:

spack.repo.RepoError: cannot load package 'netcdf-c' from the 'builtin' repository: NetcdfC.patch() got an unexpected keyword argument 'sha256'

Copy link
Copy Markdown
Contributor

@johnwparent johnwparent left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

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.

3 participants