Skip to content

Commit

Permalink
[PYPI] Include static libs on windows (openvinotoolkit#25156)
Browse files Browse the repository at this point in the history
### Details:
 - Fixed regexp for patching cmake files
 - copy static libs on windows

### Tickets:
 - *ticket-id*
  • Loading branch information
mryzhov authored Jun 24, 2024
1 parent d3b3835 commit a255e30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/bindings/c/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
40 changes: 30 additions & 10 deletions src/bindings/python/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a255e30

Please sign in to comment.