Updated package to build with skbuild
This commit is contained in:
parent
5bd6efb18a
commit
465238b179
5 changed files with 25 additions and 37 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
_skbuild/
|
||||||
|
|
||||||
.envrc
|
.envrc
|
||||||
|
|
||||||
models/
|
models/
|
||||||
|
|
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
cmake_minimum_required(VERSION 3.4...3.22)
|
||||||
|
|
||||||
|
project(llama_cpp)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||||
|
set(LLAMA_STATIC "Off")
|
||||||
|
set(BUILD_SHARED_LIBS "On")
|
||||||
|
|
||||||
|
add_subdirectory(vendor/llama.cpp)
|
||||||
|
|
||||||
|
install(TARGETS llama LIBRARY DESTINATION llama_cpp)
|
|
@ -5,7 +5,7 @@ from ctypes import c_int, c_float, c_double, c_char_p, c_void_p, c_bool, POINTER
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
# Load the library
|
# Load the library
|
||||||
libfile = pathlib.Path(__file__).parent.parent / "libllama.so"
|
libfile = pathlib.Path(__file__).parent / "libllama.so"
|
||||||
lib = ctypes.CDLL(str(libfile))
|
lib = ctypes.CDLL(str(libfile))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,10 @@ python = "^3.8.1"
|
||||||
black = "^23.1.0"
|
black = "^23.1.0"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = [
|
||||||
build-backend = "poetry.core.masonry.api"
|
"setuptools>=42",
|
||||||
|
"scikit-build>=0.13",
|
||||||
|
"cmake>=3.18",
|
||||||
|
"ninja",
|
||||||
|
]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
37
setup.py
37
setup.py
|
@ -1,42 +1,11 @@
|
||||||
import os
|
from skbuild import setup
|
||||||
import subprocess
|
|
||||||
from setuptools import setup, Extension
|
|
||||||
|
|
||||||
from distutils.command.build_ext import build_ext
|
|
||||||
|
|
||||||
|
|
||||||
class build_ext_custom(build_ext):
|
|
||||||
def run(self):
|
|
||||||
build_dir = os.path.join(os.getcwd(), "build")
|
|
||||||
src_dir = os.path.join(os.getcwd(), "vendor", "llama.cpp")
|
|
||||||
|
|
||||||
os.makedirs(build_dir, exist_ok=True)
|
|
||||||
|
|
||||||
cmake_flags = [
|
|
||||||
"-DLLAMA_STATIC=Off",
|
|
||||||
"-DBUILD_SHARED_LIBS=On",
|
|
||||||
"-DCMAKE_CXX_FLAGS=-fPIC",
|
|
||||||
"-DCMAKE_C_FLAGS=-fPIC",
|
|
||||||
]
|
|
||||||
subprocess.check_call(["cmake", src_dir, *cmake_flags], cwd=build_dir)
|
|
||||||
subprocess.check_call(["cmake", "--build", "."], cwd=build_dir)
|
|
||||||
|
|
||||||
# Move the shared library to the root directory
|
|
||||||
lib_path = os.path.join(build_dir, "libllama.so")
|
|
||||||
target_path = os.path.join(os.getcwd(), "libllama.so")
|
|
||||||
os.rename(lib_path, target_path)
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="llama_cpp",
|
name="llama_cpp",
|
||||||
description="A Python wrapper for llama.cpp",
|
description="A Python wrapper for llama.cpp",
|
||||||
version="0.0.1",
|
version="0.1.1",
|
||||||
author="Andrei Betlen",
|
author="Andrei Betlen",
|
||||||
author_email="abetlen@gmail.com",
|
author_email="abetlen@gmail.com",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
py_modules=["llama_cpp"],
|
packages=['llama_cpp'],
|
||||||
ext_modules=[
|
|
||||||
Extension("libllama", ["vendor/llama.cpp"]),
|
|
||||||
],
|
|
||||||
cmdclass={"build_ext": build_ext_custom},
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue