Skip to content

Fix find_package case for pre-installed Ginkgo#100

Open
rho-novatron wants to merge 3 commits into
Helmholtz-AI-Energy:mainfrom
rho-novatron:feature/fix-ginkgo-find-package
Open

Fix find_package case for pre-installed Ginkgo#100
rho-novatron wants to merge 3 commits into
Helmholtz-AI-Energy:mainfrom
rho-novatron:feature/fix-ginkgo-find-package

Conversation

@rho-novatron
Copy link
Copy Markdown
Contributor

@rho-novatron rho-novatron commented Mar 27, 2026

Problem

Two CMake issues prevented using a pre-installed Ginkgo (e.g. from conda) and broke wheel packaging:

  1. Case mismatch in find_package: find_package(ginkgo QUIET) (lowercase) fails to find a pre-installed Ginkgo on case-sensitive filesystems (Linux). Ginkgo upstream installs its CMake config as GinkgoConfig.cmake in lib/cmake/Ginkgo/, but CMake's find_package(ginkgo) searches for ginkgoConfig.cmake — a case mismatch.

  2. Absolute install destination breaks wheel packaging: install(DIRECTORY ... DESTINATION ${Python_SITELIB}) used an absolute path, which bypasses CMAKE_INSTALL_PREFIX. Since py-build-cmake uses a staging directory as the install prefix to collect files for the wheel, the absolute destination wrote files directly to site-packages — the compiled .so binding was never included in the wheel.

Additionally, install(IMPORTED_RUNTIME_ARTIFACTS ginkgo ...) references bare targets that only exist when Ginkgo is built from source via FetchContent. When using a pre-installed Ginkgo, these targets don't exist and the build fails.

Changes

  • find_package(Ginkgo QUIET) instead of find_package(ginkgo QUIET) to match GinkgoConfig.cmake
  • Guard install(IMPORTED_RUNTIME_ARTIFACTS ...) with if(NOT Ginkgo_FOUND) — Ginkgo shared libraries only need to be bundled when built from source
  • Use relative DESTINATION (${PY_BUILD_CMAKE_MODULE_NAME}) instead of absolute ${Python_SITELIB} so files are installed into the staging area where py-build-cmake picks them up for the wheel
  • Add trailing / to source DIRECTORY to install contents, not the directory itself (avoids pyGinkgo/pyGinkgo/ nesting)

Testing

Verified that:

  • pip wheel . produces a wheel containing the compiled .so binding (~823KB vs 12KB before)
  • pip install <wheel> followed by import pyGinkgo succeeds
  • Ginkgo is found from conda without triggering FetchContent

- Use find_package(Ginkgo) instead of find_package(ginkgo) to match the
  upstream GinkgoConfig.cmake naming on case-sensitive filesystems
- Guard install(IMPORTED_RUNTIME_ARTIFACTS) with if(NOT Ginkgo_FOUND) since
  bare targets (ginkgo, ginkgo_device, ...) only exist when Ginkgo is built
  from source via FetchContent, not when using a pre-installed package
@greole
Copy link
Copy Markdown
Collaborator

greole commented Mar 27, 2026

Thanks! I am also currently experimenting distributing ginkgo via wheels or similar. I think we can have a look at pytorch or jax.

The install(DIRECTORY) used an absolute DESTINATION (${Python_SITELIB})
which bypasses CMAKE_INSTALL_PREFIX. Since py-build-cmake uses a staging
directory as the install prefix to collect files for the wheel, the
absolute path wrote files directly to the real site-packages instead of
the staging area, resulting in wheels missing the compiled .so binding.

- Use relative DESTINATION (${PY_BUILD_CMAKE_MODULE_NAME}) so files are
  installed under CMAKE_INSTALL_PREFIX where py-build-cmake picks them up
- Add trailing / to source DIRECTORY to install contents, not the
  directory itself (avoids pyGinkgo/pyGinkgo/ nesting)
@rho-novatron
Copy link
Copy Markdown
Contributor Author

Thanks! I am also currently experimenting distributing ginkgo via wheels or similar. I think we can have a look at pytorch or jax.

Nice! I just managed to get conda packages for ginkgo working with both cuda and cpu builds, with and without mpi! If you want to test it, there's a recipe here: https://github.com/rho-novatron/staged-recipes/tree/ginkgo . The pixi run build-linux seems to work. I just made it for our own use here at Novatron, but if you want to start from that and fix it for submission to conda-forge that would be awesome.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes CMake configuration and install logic so a pre-installed Ginkgo (e.g., conda) is discoverable on case-sensitive systems and wheel builds install into the staging prefix correctly.

Changes:

  • Switch find_package call to find_package(Ginkgo QUIET) and update the corresponding _FOUND variable usage.
  • Update install rules to use a relative DESTINATION and avoid nesting by adding a trailing / to the installed directory.
  • Guard installation of Ginkgo runtime artifacts so it only runs when Ginkgo is fetched/built from source.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt
Comment on lines +185 to +186
install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME})
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

PY_BUILD_CMAKE_MODULE_NAME is used as the install() destination, but it isn’t defined anywhere in this project (only provided by py-build-cmake). This breaks the documented plain-CMake workflow (cmake --install .) because the install destination becomes empty and files get installed into the install prefix root. Consider adding a fallback (e.g., default to ${PROJECT_NAME} or ${Python_SITELIB}/${PROJECT_NAME} when PY_BUILD_CMAKE_MODULE_NAME is not defined), or make the destination configurable via an option/cache variable.

Copilot uses AI. Check for mistakes.
Comment thread CMakeLists.txt
Comment on lines 184 to +185
message(STATUS "Install path: ${Python_SITELIB}")
install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
DESTINATION ${Python_SITELIB})
install(
IMPORTED_RUNTIME_ARTIFACTS
ginkgo
ginkgo_device
ginkgo_hip
ginkgo_cuda
ginkgo_omp
ginkgo_dpcpp
ginkgo_reference
DESTINATION
${Python_SITELIB}/${PROJECT_NAME})
install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The status message still prints Install path: ${Python_SITELIB}, but the install destination was changed to ${PY_BUILD_CMAKE_MODULE_NAME}. This is now misleading when diagnosing packaging/install issues; it should report the actual computed install destination (including any fallback logic) rather than the old Python_SITELIB value.

Copilot uses AI. Check for mistakes.
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.

@copilot apply changes based on this feedback

Comment thread CMakeLists.txt
Comment on lines 182 to 183
set(CMAKE_INSTALL_RPATH ${Python_SITELIB}/${PROJECT_NAME})

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

CMAKE_INSTALL_RPATH is still set using the absolute ${Python_SITELIB}/${PROJECT_NAME} path, even though installation is now intended to go through a staging prefix for wheel builds. This can embed a build-environment-specific absolute RPATH into the extension, which is problematic for wheel relocatability. Consider setting an RPATH relative to the installed module location (e.g., $ORIGIN) or deriving it from the actual install destination instead of Python_SITELIB.

Copilot uses AI. Check for mistakes.
Comment thread CMakeLists.txt Outdated
Copy link
Copy Markdown
Collaborator

@greole greole left a comment

Choose a reason for hiding this comment

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

LGTM!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants