From 68054131646f5734a56cb710c3c572fafc6fbb19 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 15 Oct 2024 03:45:16 -0700 Subject: [PATCH] Add logic to accomodate for windows output dir --- CMakeLists.txt | 79 ++++++++++++++++++++++++++------------ nexa/gguf/bark/bark_cpp.py | 19 +++++---- 2 files changed, 66 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec1402b7..7cf561c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,33 +149,62 @@ if(BARK_BUILD) -DBUILD_SHARED_LIBS=ON -DBARK_BUILD_EXAMPLES=OFF BUILD_ALWAYS 1 - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . --target install + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + $, + ${CMAKE_CURRENT_BINARY_DIR}/bark_build/bin/$/ggml${CMAKE_SHARED_LIBRARY_SUFFIX}, + ${CMAKE_CURRENT_BINARY_DIR}/bark_build/lib/libggml${CMAKE_SHARED_LIBRARY_SUFFIX}> + ${CMAKE_CURRENT_BINARY_DIR}/bark_install/$,bin,lib>/ ) endif() # Install the built libraries to the final destination -install( - DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ - ${CMAKE_CURRENT_BINARY_DIR}/llama_install/lib/ - ${CMAKE_CURRENT_BINARY_DIR}/bark_install/lib/ - DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib - USE_SOURCE_PERMISSIONS - FILES_MATCHING - PATTERN "*.dll" - PATTERN "*.so" - PATTERN "*.dylib" -) +if(WIN32) + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/llama_install/bin/ + ${CMAKE_CURRENT_BINARY_DIR}/bark_install/bin/ + DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + USE_SOURCE_PERMISSIONS + FILES_MATCHING + PATTERN "*.dll" + ) -install( - DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ - ${CMAKE_CURRENT_BINARY_DIR}/llama_install/lib/ - ${CMAKE_CURRENT_BINARY_DIR}/bark_install/lib/ - DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib - USE_SOURCE_PERMISSIONS - FILES_MATCHING - PATTERN "*.dll" - PATTERN "*.so" - PATTERN "*.dylib" -) \ No newline at end of file + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/llama_install/bin/ + ${CMAKE_CURRENT_BINARY_DIR}/bark_install/bin/ + DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + USE_SOURCE_PERMISSIONS + FILES_MATCHING + PATTERN "*.dll" + ) +else() + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/llama_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/bark_install/lib/ + DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + USE_SOURCE_PERMISSIONS + FILES_MATCHING + PATTERN "*.so" + PATTERN "*.dylib" + ) + + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/stable_diffusion_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/llama_install/lib/ + ${CMAKE_CURRENT_BINARY_DIR}/bark_install/lib/ + DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + USE_SOURCE_PERMISSIONS + FILES_MATCHING + PATTERN "*.so" + PATTERN "*.dylib" + ) +endif() \ No newline at end of file diff --git a/nexa/gguf/bark/bark_cpp.py b/nexa/gguf/bark/bark_cpp.py index 3141212e..6772858f 100644 --- a/nexa/gguf/bark/bark_cpp.py +++ b/nexa/gguf/bark/bark_cpp.py @@ -19,23 +19,28 @@ def _load_shared_library(lib_base_name: str): # Construct the paths to the possible shared library names _base_path = pathlib.Path(__file__).parent.parent.resolve() - _lib_path = _base_path / f"lib/lib{lib_base_name}{lib_ext}" + _lib_paths = [ + _base_path / f"lib/lib{lib_base_name}{lib_ext}", + _base_path / f"lib/{lib_base_name}{lib_ext}", + ] if "BARK_CPP_LIB" in os.environ: lib_base_name = os.environ["BARK_CPP_LIB"] _lib = pathlib.Path(lib_base_name) _base_path = _lib.parent.resolve() - _lib_path = _lib.resolve() + _lib_paths = [_lib.resolve()] # Add the library directory to the DLL search path on Windows (if needed) if sys.platform == "win32" and sys.version_info >= (3, 8): os.add_dll_directory(str(_base_path)) - if _lib_path.exists(): - try: - return ctypes.CDLL(str(_lib_path)) - except Exception as e: - raise RuntimeError(f"Failed to load shared library '{_lib_path}': {e}") + # Try to load the shared library, handling potential errors + for _lib_path in _lib_paths: + if _lib_path.exists(): + try: + return ctypes.CDLL(str(_lib_path)) + except Exception as e: + raise RuntimeError(f"Failed to load shared library '{_lib_path}': {e}") raise FileNotFoundError( f"Shared library with base name '{lib_base_name}' not found"