runtime subproject mixes CMake build tree artifacts with install tree artifacts

Open
#2,451 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
cmake
Domain
build-system

Research direction

Start by tracing the runtime CMake configuration, especially CMAKE_LIBRARY_OUTPUT_DIRECTORY and the ExternalProject_Add setup for accelerate-lapacke. Compare the build-tree and install-tree paths, then choose and document a consistent approach; done means runtime/build/lib no longer mixes artifacts from both trees and the build and packaging flow still succeeds.

Written by the indexing model from the issue text.

Description

enhancement runtime

Impact:

As the libraries in runtime manually set the RPATH/RUNPATH to $ORIGIN/@loader_path for the build tree artifacts and then continue to use the build tree artifacts for further building and packaging (wheel), this is probably nitpicky and won't have any impact.

Description:

When building the runtime subproject, the variable CMAKE_LIBRARY_OUTPUT_DIRECTORY is used to place the build tree artifacts into a common location runtime/build/lib. The accelerate-lapacke dependency on the other hand is installed into this directory. This breaks the fundamental CMake principle of separating build tree and install tree.

ChatGPT had this to say (exerpt):

The CMake docs and common guidance on Discourse repeatedly emphasize separating build tree and install tree, and using target-based install/export mechanisms instead.

One could argue, that in this project, when the runtime subproject has been built, the build process is not finished, so we're still operating in the build tree. Unfortunately, because the LAPACKE build is a nested sub-project with a distinct build directory, CMAKE_LIBRARY_OUTPUT_DIRECTORY does not propagate to it. The LAPACKE library is installed alongside the other libraries.

Solutions:

You could either use a more fragile approach, skip the install step for accelerate-lapacke and copy the build tree artifacts of the reference lapack build to runtime/build/lib. But the path to the reference lapack build directory would be hard-coded and fragile.

ExternalProject_Add(
    ...
    INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy_directory_if_different "<BINARY_DIR>/_deps/reference-lapack-build/lib" "${CMAKE_BINARY_DIR}/lib"
    ...
)

This way, all artifacts in runtime/build/lib would be build tree artifacts.

The other approach would be to make runtime a standalone, installable project. For this, all the other CMake libraries in runtime would have to define install()'s for each target. Then, you could install the whole runtime project before using it in the top-level project or packaging it into a wheel.

Dominant language
Python
Stars
234
Forks
84
Avg merge
3d 11h
Merged PRs (30d)
78

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PennyLaneAI/catalyst

All issues in PennyLaneAI/catalyst

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.