Skip to content

Commit 9c172fe

Browse files
pytorchbotGregoryComermergennachin
authored
RPATH Fix for portable_lib Python Extension (#14442)
Co-authored-by: Gregory Comer <[email protected]> Co-authored-by: Mergen Nachin <[email protected]> fix from #13254 Fixes #14421.
1 parent 04abd8e commit 9c172fe

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

.ci/scripts/wheel/test_base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ class ModelTest:
4141

4242

4343
def run_tests(model_tests: List[ModelTest]) -> None:
44+
# Test that we can import the portable_lib module - verifies RPATH is correct
45+
print("Testing portable_lib import...")
46+
try:
47+
from executorch.extension.pybindings._portable_lib import ( # noqa: F401
48+
_load_for_executorch,
49+
)
50+
51+
print("✓ Successfully imported _load_for_executorch from portable_lib")
52+
except ImportError as e:
53+
print(f"✗ Failed to import portable_lib: {e}")
54+
raise
55+
4456
# Why are we doing this envvar shenanigans? Since we build the testers, which
4557
# uses buck, we cannot run as root. This is a sneaky of getting around that
4658
# test.

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,21 @@ if(EXECUTORCH_BUILD_PYBIND)
869869
target_compile_options(portable_lib PUBLIC ${_pybind_compile_options})
870870
target_link_libraries(portable_lib PRIVATE ${_dep_libs})
871871

872+
# Set RPATH to find PyTorch libraries relative to the installation location
873+
# This goes from executorch/extension/pybindings up to site-packages, then to
874+
# torch/lib
875+
if(APPLE)
876+
set_target_properties(
877+
portable_lib PROPERTIES BUILD_RPATH "@loader_path/../../../torch/lib"
878+
INSTALL_RPATH "@loader_path/../../../torch/lib"
879+
)
880+
else()
881+
set_target_properties(
882+
portable_lib PROPERTIES BUILD_RPATH "$ORIGIN/../../../torch/lib"
883+
INSTALL_RPATH "$ORIGIN/../../../torch/lib"
884+
)
885+
endif()
886+
872887
install(
873888
TARGETS portable_lib
874889
EXPORT ExecuTorchTargets

0 commit comments

Comments
 (0)