Updated package to build with skbuild

This commit is contained in:
Andrei Betlen 2023-03-23 13:54:14 -04:00
parent 5bd6efb18a
commit 465238b179
5 changed files with 25 additions and 37 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
_skbuild/
.envrc
models/

12
CMakeLists.txt Normal file
View 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)

View file

@ -5,7 +5,7 @@ from ctypes import c_int, c_float, c_double, c_char_p, c_void_p, c_bool, POINTER
import pathlib
# Load the library
libfile = pathlib.Path(__file__).parent.parent / "libllama.so"
libfile = pathlib.Path(__file__).parent / "libllama.so"
lib = ctypes.CDLL(str(libfile))

View file

@ -20,5 +20,10 @@ python = "^3.8.1"
black = "^23.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = [
"setuptools>=42",
"scikit-build>=0.13",
"cmake>=3.18",
"ninja",
]
build-backend = "setuptools.build_meta"

View file

@ -1,42 +1,11 @@
import os
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)
from skbuild import setup
setup(
name="llama_cpp",
description="A Python wrapper for llama.cpp",
version="0.0.1",
version="0.1.1",
author="Andrei Betlen",
author_email="abetlen@gmail.com",
license="MIT",
py_modules=["llama_cpp"],
ext_modules=[
Extension("libllama", ["vendor/llama.cpp"]),
],
cmdclass={"build_ext": build_ext_custom},
packages=['llama_cpp'],
)