Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS: Cannot pip install from source due to hard-coded RPATH #826

Open
dpad opened this issue Oct 3, 2024 · 1 comment
Open

MacOS: Cannot pip install from source due to hard-coded RPATH #826

dpad opened this issue Oct 3, 2024 · 1 comment

Comments

@dpad
Copy link
Contributor

dpad commented Oct 3, 2024

Describe the bug
The current settings for the RPATH (path where the linker tries to find linked libraries) seem to be hard-coded to the absolute build directory for MacOS builds. This affects pip-based installation for MacOS, in particular for cases where pip copies the source code into the temporary build directory. The following cases are affected (on MacOS only):

  • pip install . -- works because the source code is not copied and points to the local build directory dist3
  • pip install Basilisk*.tar.gz -- i.e. installing source distribution does not work, because pip will unzip the source into a temporary directory
  • pip install git+https://github.com/AVSLab/basilisk.git -- as above

I'm not 100% sure what the correct fix is for setting the RPATH appropriately, but the following patch at least seems to work when I asked someone with a MacOS to test it.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
   set(CMAKE_SKIP_BUILD_RPATH FALSE) # use, i.e. don't skip the full RPATH for the build tree
   set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) # when building, don't use the install RPATH already (but later on when
                                            # installing)
-  set(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/Basilisk") # the RPATH to be used when installing
+  set(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/Basilisk"  # the RPATH to be used when installing
+      # Also add relative paths so we can install from wheel/sdist.
+      # TODO: Is there a proper way to set relative library paths without just
+      # guessing how many parent ".." directories to use?
+      "@loader_path"
+      "@loader_path/.."
+      "@loader_path/../.."
+  )
 
   # don't add the automatically determined parts of the RPATH which point to directories outside the build tree to the
   # install RPATH

To reproduce
Steps to reproduce the behavior:

  1. On a MacOS, Try to install the source directly from git: pip install git+https://github.com/AVSLab/basilisk.git
  2. Run something with Basilisk, see errors about missing libraries

Desktop (please complete the following information):

  • OS: MacOS
@dpad dpad changed the title MacOS: Setting RPATH appropriately for portable wheels across platforms MacOS: RPATH is hard-coded to absolute build directory path, cannot install from source Oct 3, 2024
@dpad dpad changed the title MacOS: RPATH is hard-coded to absolute build directory path, cannot install from source MacOS: Cannot pip install from source due to hard-coded RPATH Oct 3, 2024
@sassy-asjp
Copy link
Contributor

Note that the patch for macOS mirrors what is already happening in Linux:

set(CMAKE_INSTALL_RPATH "\$ORIGIN/../../")

Since I think that the files get put into the install directory by pip, instead of running some cmake generated installation command, it might be the best possible without really fiddling with how pip is installing the files.

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

No branches or pull requests

2 participants