Skip to content

Commit b3932c0

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Add back extension suffix for portable lib shared object in pip wheel (#6363)
Summary: Initially our portable lib prebuilt library is named as: ``` _portable_lib.cpython-310-x86_64-linux-gnu.so ``` Where it includes an `EXT_SUFFIX` `cpython-310-x86_64-linux-gnu` consists of architecture and build OS information. This is enforced by `setuptools` following PEP 3149 and there's no good way to change this behavior. #5961 was an attempt to rename the .so filename at **packaging** stage to `_portable_lib.so`, so that it is easier to be found by `find_package()` macro in CMake. However #5961 is breaking the other prebuilt libraries such as `libcustom_ops_aot_lib.so` which depends on the original `_portable_lib.cpython-310-x86_64-linux-gnu.so` name in its RPATH. This PR is a fix that reverts #5961 and restore the full name during packaging, but try to match the `EXT_SUFFIX` in CMake to be able to find the .so file. Pull Request resolved: #6363 Test Plan: ```bash EXECUTORCH_BUILD_PYBIND=ON python setup.py bdist_wheel # build wheel including _portable_lib.*.so pip install dist/executorch-0.5.0a0+7510f8c-cp310-cp310-linux_x86_64.whl python -c "from executorch.extension.llm.custom_ops import sdpa_with_kv_cache" # Run torchao script to make sure find_package() works push ao/torchao/experimental bash build_torchao_ops.sh executorch ``` Does not throw `_portable_lib.cpython-310-x86_64-linux-gnu.so` not found error. Reviewed By: kirklandsign Differential Revision: D64635137 Pulled By: larryliu0820 fbshipit-source-id: 7e54ea15361ae63acb8324538ea4982e95d6f07a
1 parent 4d7b294 commit b3932c0

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

build/executorch-wheel-config.cmake

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,41 @@
2121
#
2222
cmake_minimum_required(VERSION 3.19)
2323

24-
# Find prebuilt _portable_lib.so. This file should be installed under
24+
# Find prebuilt _portable_lib.<EXT_SUFFIX>.so. This file should be installed under
2525
# <site-packages>/executorch/share/cmake
26-
find_library(_portable_lib_LIBRARY _portable_lib.so PATHS "${CMAKE_CURRENT_LIST_DIR}/../../extension/pybindings/")
26+
27+
# Find python
28+
if(DEFINED ENV{CONDA_DEFAULT_ENV} AND NOT $ENV{CONDA_DEFAULT_ENV} STREQUAL "base")
29+
set(PYTHON_EXECUTABLE
30+
python
31+
)
32+
else()
33+
set(PYTHON_EXECUTABLE
34+
python3
35+
)
36+
endif()
37+
38+
# Get the Python version and platform information
39+
execute_process(
40+
COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
41+
OUTPUT_VARIABLE EXT_SUFFIX
42+
RESULT_VARIABLE SYSCONFIG_RESULT
43+
ERROR_VARIABLE SYSCONFIG_ERROR
44+
OUTPUT_STRIP_TRAILING_WHITESPACE
45+
)
46+
47+
if(RESULT_VARIABLE EQUAL 0)
48+
message(STATUS "Sysconfig extension suffix: ${EXT_SUFFIX}")
49+
else()
50+
message(FATAL_ERROR "Failed to retrieve sysconfig config var EXT_SUFFIX: ${SYSCONFIG_ERROR}")
51+
endif()
52+
53+
find_library(
54+
_portable_lib_LIBRARY
55+
NAMES _portable_lib${EXT_SUFFIX}
56+
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../extension/pybindings/"
57+
)
58+
2759
set(EXECUTORCH_LIBRARIES)
2860
set(EXECUTORCH_FOUND OFF)
2961
if(_portable_lib_LIBRARY)

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,6 @@ def get_ext_modules() -> List[Extension]:
687687
return ext_modules
688688

689689

690-
# Override extension suffix to be ".so", skipping package info such as
691-
# "cpython-311-darwin"
692-
os.environ["SETUPTOOLS_EXT_SUFFIX"] = ".so"
693-
694690
setup(
695691
version=Version.string(),
696692
# TODO(dbort): Could use py_modules to restrict the set of modules we

0 commit comments

Comments
 (0)