diff --git a/multipy/runtime/interpreter/CMakeLists.txt b/multipy/runtime/interpreter/CMakeLists.txt index 2b458b4d..6bb4c016 100644 --- a/multipy/runtime/interpreter/CMakeLists.txt +++ b/multipy/runtime/interpreter/CMakeLists.txt @@ -4,6 +4,7 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. + SET(INTERPRETER_DIR "${DEPLOY_DIR}/interpreter" ) SET(INTERPRETER_DIR "${DEPLOY_DIR}/interpreter" PARENT_SCOPE) @@ -13,17 +14,19 @@ include_directories(BEFORE "${PYTORCH_ROOT}/torch/include/torch/csrc/api/include SET(MULTIPY_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../../utils") # Build cpython +SET(CPYTHON_VERSION 3.8 CACHE STRING "Default version of Cpython to bundle.") +SET(CPYTHON_VERSION_GIT_TAG 3.8.6 CACHE STRING "Git tag for default version of Cpython to bundle.") SET(PYTHON_INSTALL_DIR "${INTERPRETER_DIR}/cpython") -SET(PYTHON_INC_DIR "${PYTHON_INSTALL_DIR}/include/python3.8") -SET(PYTHON_INC_DIR "${PYTHON_INSTALL_DIR}/include/python3.8" PARENT_SCOPE) -SET(PYTHON_LIB "${PYTHON_INSTALL_DIR}/lib/libpython3.8.a") +SET(PYTHON_INC_DIR "${PYTHON_INSTALL_DIR}/include/python${CPYTHON_VERSION}") +SET(PYTHON_INC_DIR "${PYTHON_INSTALL_DIR}/include/python${CPYTHON_VERSION}" PARENT_SCOPE) +SET(PYTHON_LIB "${PYTHON_INSTALL_DIR}/lib/libpython${CPYTHON_VERSION}.a") SET(PYTHON_BIN "${PYTHON_INSTALL_DIR}/bin/python3") include(ExternalProject) ExternalProject_Add( cpython PREFIX cpython GIT_REPOSITORY https://github.com/python/cpython.git - GIT_TAG v3.8.6 + GIT_TAG v${CPYTHON_VERSION_GIT_TAG} UPDATE_COMMAND "" PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/cpython_patch.diff BUILD_IN_SOURCE True @@ -46,10 +49,20 @@ include(GoogleTest) # We find the built python modules, this is confusing because python build already outputs # the modules in a strange nested path, and then that path is relative to the # Cmake ExternalProject root in the cmake build dir. +## From test devsrvr ExternalProject_Get_property(cpython SOURCE_DIR) -SET(PYTHON_MODULE_DIR "${SOURCE_DIR}/build/temp.linux-x86_64-3.8/${SOURCE_DIR}/Modules") +SET(PYTHON_MODULE_DIR "${SOURCE_DIR}/build/temp.linux-x86_64-${CPYTHON_VERSION}/${SOURCE_DIR}/Modules") SET(PYTHON_STDLIB_DIR "${SOURCE_DIR}/Lib") -SET(PYTHON_STDLIB "${PYTHON_INSTALL_DIR}/lib/libpython_stdlib3.8.a") +SET(PYTHON_STDLIB "${PYTHON_INSTALL_DIR}/lib/libpython_stdlib${CPYTHON_VERSION}.a") + +if(${CPYTHON_VERSION} MATCHES "3\.(7|8)") + SET(PYTHON_MEM_MODULE "${PYTHON_MODULE_DIR}/_decimal/libmpdec/memory.o") + SET(LEGACY_PARSER_MODULE "${PYTHON_MODULE_DIR}/parsermodule.o") +elseif(${CPYTHON_VERSION} MATCHES "3\.(9|1[0-9]*)") + SET(PYTHON_MEM_MODULE "${PYTHON_MODULE_DIR}/_decimal/libmpdec/mpalloc.o") + SET(LEGACY_PARSER_MODULE "") +endif() + # Then we use a hardcoded list of expected module names and include them in our lib include("CMakePythonModules.txt") ExternalProject_Add_Step( @@ -57,9 +70,10 @@ ExternalProject_Add_Step( archive_stdlib DEPENDEES install BYPRODUCTS ${PYTHON_STDLIB} - COMMAND ar -rc ${PYTHON_STDLIB} ${PYTHON_MODULES} + COMMAND ar -rc ${PYTHON_STDLIB} ${PYTHON_MODULES} ${PYTHON_MEM_MODULE} ${LEGACY_PARSER_MODULE} VERBATIM ) + # Get python typing extension, needed by torch SET(TYPING_PKG "${INTERPRETER_DIR}/third_party/typing_extensions.py") ExternalProject_Add( diff --git a/multipy/runtime/interpreter/CMakePythonModules.txt b/multipy/runtime/interpreter/CMakePythonModules.txt index c6bc9cab..61eb8d35 100644 --- a/multipy/runtime/interpreter/CMakePythonModules.txt +++ b/multipy/runtime/interpreter/CMakePythonModules.txt @@ -39,7 +39,6 @@ SET(PYTHON_MODULES ${PYTHON_MODULE_DIR}/nismodule.o ${PYTHON_MODULE_DIR}/_opcode.o ${PYTHON_MODULE_DIR}/ossaudiodev.o - ${PYTHON_MODULE_DIR}/parsermodule.o ${PYTHON_MODULE_DIR}/_pickle.o ${PYTHON_MODULE_DIR}/_posixsubprocess.o ${PYTHON_MODULE_DIR}/pyexpat.o ${PYTHON_MODULE_DIR}/expat/xmlparse.o ${PYTHON_MODULE_DIR}/expat/xmlrole.o ${PYTHON_MODULE_DIR}/expat/xmltok.o