diff --git a/build/executorch-wheel-config.cmake b/build/executorch-wheel-config.cmake index 239fff67c1d..d4f3e12ecc8 100644 --- a/build/executorch-wheel-config.cmake +++ b/build/executorch-wheel-config.cmake @@ -21,9 +21,41 @@ # cmake_minimum_required(VERSION 3.19) -# Find prebuilt _portable_lib.so. This file should be installed under +# Find prebuilt _portable_lib..so. This file should be installed under # /executorch/share/cmake -find_library(_portable_lib_LIBRARY _portable_lib.so PATHS "${CMAKE_CURRENT_LIST_DIR}/../../extension/pybindings/") + +# Find python +if(DEFINED ENV{CONDA_DEFAULT_ENV} AND NOT $ENV{CONDA_DEFAULT_ENV} STREQUAL "base") + set(PYTHON_EXECUTABLE + python + ) +else() + set(PYTHON_EXECUTABLE + python3 + ) +endif() + +# Get the Python version and platform information +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))" + OUTPUT_VARIABLE EXT_SUFFIX + RESULT_VARIABLE SYSCONFIG_RESULT + ERROR_VARIABLE SYSCONFIG_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(RESULT_VARIABLE EQUAL 0) + message(STATUS "Sysconfig extension suffix: ${EXT_SUFFIX}") +else() + message(FATAL_ERROR "Failed to retrieve sysconfig config var EXT_SUFFIX: ${SYSCONFIG_ERROR}") +endif() + +find_library( + _portable_lib_LIBRARY + NAMES _portable_lib${EXT_SUFFIX} + PATHS "${CMAKE_CURRENT_LIST_DIR}/../../extension/pybindings/" +) + set(EXECUTORCH_LIBRARIES) set(EXECUTORCH_FOUND OFF) if(_portable_lib_LIBRARY) diff --git a/setup.py b/setup.py index ef027b451c3..ff1afa89bd6 100644 --- a/setup.py +++ b/setup.py @@ -687,10 +687,6 @@ def get_ext_modules() -> List[Extension]: return ext_modules -# Override extension suffix to be ".so", skipping package info such as -# "cpython-311-darwin" -os.environ["SETUPTOOLS_EXT_SUFFIX"] = ".so" - setup( version=Version.string(), # TODO(dbort): Could use py_modules to restrict the set of modules we