Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.10+][1/n] Add conditional archiving for libmpdec module #106

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions multipy/runtime/interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -46,20 +49,31 @@ 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(
cpython
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(
Expand Down
1 change: 0 additions & 1 deletion multipy/runtime/interpreter/CMakePythonModules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down