From a255e30277b8eb5275bc00104bea6be3607fdce3 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Mon, 24 Jun 2024 23:46:40 +0200 Subject: [PATCH] [PYPI] Include static libs on windows (#25156) ### Details: - Fixed regexp for patching cmake files - copy static libs on windows ### Tickets: - *ticket-id* --- src/bindings/c/src/CMakeLists.txt | 8 +++++- src/bindings/python/wheel/setup.py | 40 ++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/bindings/c/src/CMakeLists.txt b/src/bindings/c/src/CMakeLists.txt index 7803630cd0594b..106106ed7eaced 100644 --- a/src/bindings/c/src/CMakeLists.txt +++ b/src/bindings/c/src/CMakeLists.txt @@ -50,9 +50,15 @@ export(TARGETS ${TARGET_NAME} NAMESPACE openvino:: ov_cpack_add_component(${OV_CPACK_COMP_CORE_C} HIDDEN) ov_cpack_add_component(${OV_CPACK_COMP_CORE_C_DEV} HIDDEN) +if(BUILD_SHARED_LIBS) + set(archive_comp CORE_C_DEV) +else() + set(archive_comp CORE_C) +endif() + install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets RUNTIME DESTINATION ${OV_CPACK_RUNTIMEDIR} COMPONENT ${OV_CPACK_COMP_CORE_C} ${OV_CPACK_COMP_CORE_C_EXCLUDE_ALL} - ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${OV_CPACK_COMP_CORE_C} ${OV_CPACK_COMP_CORE_C_EXCLUDE_ALL} + ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${OV_CPACK_COMP_${archive_comp}} ${OV_CPACK_COMP_${archive_comp}_EXCLUDE_ALL} LIBRARY DESTINATION ${OV_CPACK_LIBRARYDIR} COMPONENT ${OV_CPACK_COMP_CORE_C} ${OV_CPACK_COMP_CORE_C_EXCLUDE_ALL} NAMELINK_COMPONENT ${OV_CPACK_COMP_LINKS} ${OV_CPACK_COMP_LINKS_EXCLUDE_ALL} INCLUDES DESTINATION ${OV_CPACK_INCLUDEDIR}) diff --git a/src/bindings/python/wheel/setup.py b/src/bindings/python/wheel/setup.py index 91eb1d9111a0bf..cad51e5ca0acc8 100644 --- a/src/bindings/python/wheel/setup.py +++ b/src/bindings/python/wheel/setup.py @@ -14,7 +14,7 @@ import logging as log from fnmatch import fnmatchcase from pathlib import Path -from shutil import copyfile, rmtree +from shutil import copyfile, rmtree, move from setuptools import setup, find_namespace_packages, Extension, Command from setuptools.command.build_ext import build_ext from setuptools.command.build_clib import build_clib @@ -175,7 +175,14 @@ DATA_INSTALL_CFG = { "core_dev": { "name": "core_dev", - "prefix": f"{BUILD_BASE}/libs.dev", + "prefix": f"{BUILD_BASE}/libs.core.dev", + "install_dir": "runtime", + "binary_dir": OPENVINO_BINARY_DIR, + "source_dir": OPENVINO_SOURCE_DIR + }, + "core_c_dev": { + "name": "core_c_dev", + "prefix": f"{BUILD_BASE}/libs.core_c.dev", "install_dir": "runtime", "binary_dir": OPENVINO_BINARY_DIR, "source_dir": OPENVINO_SOURCE_DIR @@ -422,7 +429,7 @@ def copy_package_libs(self, src_dirs): for src_dir in src_dirs: # additional blacklist filter, just to fix cmake install issues blacklist_patterns = [ # static libraries and PBD files - "^.*\\.a$", "^.*\\.lib$", "^.*\\.pdb$", + "^.*\\.a$", "^.*\\.pdb$", # TBB debug libraries "^.*_debug\\.dll$", "^.*_debug\\.\\d*\\.dylib$", "^.*_debug\\.so\\.\\d*$", # hwloc static libs on Windows @@ -453,24 +460,37 @@ def copy_package_data(self, src_dirs): """Collect package data files from preinstalled dirs and put to the subpackage.""" package_dir = os.path.join(PACKAGE_DIR, WHEEL_PACKAGE_DIR) os.makedirs(package_dir, exist_ok=True) + package_clibs_dir = os.path.join(PACKAGE_DIR, WHEEL_LIBS_INSTALL_DIR) + os.makedirs(package_clibs_dir, exist_ok=True) replacements = { # change the path where the libraries are installed (runtime/lib/intel64/Release -> openvino/libs) - f"{OV_RUNTIME_LIBS_DIR}": f"{WHEEL_LIBS_INSTALL_DIR}", + r"({_IMPORT_PREFIX})\/(.*)\/(.*.[lib|dylib|so|dll])": rf"\1/{WHEEL_LIBS_INSTALL_DIR}/\3", # change the path where the include files are installed (runtime/include -> openvino/include) r"({_IMPORT_PREFIX})\/(.*)\/(include)": rf"\1/{WHEEL_PACKAGE_DIR}/\3", - # changed the lib version (2024.3.0 -> 2430) - r"(.so).(\d\d)(\d\d).(\d+).(\d+)": r"\1.\3\4\5" + # change the libs versions (so.2024.3.0 -> so.2430 or 2024.3.0.dylib -> 2430.dylib) + r"(.so)?.(\d\d)(\d\d).(\d+).(\d+)(.dylib)?": r"\1.\3\4\5\6", } for src_dir in src_dirs: src, dst = Path(src_dir), Path(package_dir) - shutil.copytree(src, dst, dirs_exist_ok=True) - # patch cmake configurations - for file_path in Path(dst).rglob("*.cmake"): + # move the static libs to the directory with the shared libraries + for file_path in Path(src).rglob("*.lib"): + file_name = os.path.basename(file_path) if file_path.is_file(): - replace_strings_in_file(file_path, replacements) + dst_file = os.path.join(package_clibs_dir, file_name) + move(file_path, dst_file) + self.announce(f"Move {file_path} to {dst_file}", level=3) + + if os.path.isdir(src) and os.listdir(src): + # copy the rest of the files to the package directly + shutil.copytree(src, dst, dirs_exist_ok=True) + + # patch cmake configurations + for file_path in Path(dst).rglob("*.cmake"): + if file_path.is_file(): + replace_strings_in_file(file_path, replacements) def copy_file(src, dst, verbose=False, dry_run=False):