Skip to content

fix: use find_library instead of assuming library extension #66

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

Merged
merged 4 commits into from
Sep 15, 2023
Merged
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ if (MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

add_subdirectory(ggml)

add_library(clip
Expand All @@ -264,6 +266,9 @@ if (BUILD_SHARED_LIBS)
set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(clip PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(clip PRIVATE CLIP_SHARED CLIP_BUILD)
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})
install(TARGETS ggml clip
LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/examples/python_bindings/clip_cpp)
endif()

add_subdirectory(models)
Expand Down
13 changes: 8 additions & 5 deletions examples/python_bindings/clip_cpp/clip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ctypes
from ctypes.util import find_library
import os
from typing import List, Dict, Any

Expand All @@ -8,11 +9,13 @@
this_dir = os.path.abspath(os.path.dirname(__file__))

# Load the shared library
path_to_dll = os.environ.get("CLIP_DLL", this_dir)
os.chdir(path_to_dll)
ggml_lib = ctypes.CDLL("./libggml.so")
clip_lib = ctypes.CDLL("./libclip.so")
os.chdir(cur_dir)
ggml_lib_path, clip_lib_path = find_library("ggml"), find_library("clip")
if ggml_lib_path is None or clip_lib_path is None:
raise RuntimeError(f"Could not find shared libraries. Please copy to the current working directory or supply the "
f"correct LD_LIBRARY_PATH/DYLD_LIBRARY_PATH.")

ggml_lib = ctypes.CDLL(ggml_lib_path)
clip_lib = ctypes.CDLL(clip_lib_path)


# Define the ctypes structures
Expand Down
16 changes: 16 additions & 0 deletions scripts/build-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#/bin/bash

# Change to the project directory
cd "$(dirname "$0")"/..

rm -rf ./build

mkdir build

cd build

cmake -DBUILD_SHARED_LIBS=ON -DCLIP_NATIVE=OFF ..

make

make install
4 changes: 4 additions & 0 deletions format.sh → scripts/format.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#/bin/bash

# Change to the project directory
cd "$(dirname "$0")"/..

find . -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' \) ! -path "./ggml/*" ! -path "./build/*" -exec clang-format -i {} +