Commit 7075004
RPATH Fix for portable_lib Python Extension (#13254)
RPATH Fix for portable_lib Python Extension
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
(cherry picked from commit 38062f8)1 parent 8e85857 commit 7075004
2 files changed
+28
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
799 | 811 | | |
800 | 812 | | |
801 | 813 | | |
| |||
0 commit comments