Skip to content

Commit

Permalink
cibuildwheel integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mtasic85 committed Jul 7, 2024
1 parent 33c93fb commit aa8627c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ setuptools = "^70.2.0"
cibuildwheel = "^2.19.2"

[build-system]
requires = ["poetry-core", "cibuildwheel"]
requires = ["poetry-core", "setuptools", "cibuildwheel"]
build-backend = "poetry.core.masonry.api"
47 changes: 45 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from setuptools import setup
from setuptools import setup, find_packages
from setuptools.command.build_ext import build_ext
import subprocess
import os
import shutil

setup()
class CustomBuildExtCommand(build_ext):
def run(self):
env = os.environ.copy()
env['CXXFLAGS'] = '-DSHARED_LIB'
env['LDFLAGS'] = '-shared -o libllama-cli.so'

subprocess.run(['rm', '-rf', 'llama.cpp'])
subprocess.run(['rm', '-rf', 'llama/libllama-cli.so'])
subprocess.run(['git', 'clone', 'https://github.com/ggerganov/llama.cpp.git'])
subprocess.run(['patch', 'llama.cpp/examples/main/main.cpp', 'main_shared_library_0.patch'])
subprocess.run(['make', '-C', 'llama.cpp', '-j', 'llama-cli'], check=True, env=env)

shutil.copy("llama.cpp/libllama-cli.so", "llama/libllama-cli.so")

# Ensure the build directory exists and copy the shared library to the build directory
build_lib_dir = os.path.join(self.build_lib, 'llama')
os.makedirs(build_lib_dir, exist_ok=True)
self.copy_file('llama/libllama-cli.so', os.path.join(build_lib_dir, 'libllama-cli.so'))

super().run()

setup(
name='llama-cpp-cffi',
version='0.0.2',
description='Python binding for llama.cpp using cffi',
author='Marko Tasic',
author_email='mtasic85@gmail.com',
url='https://github.com/mtasic85/llama-cpp-cffi',
packages=find_packages(),
include_package_data=True,
package_data={'llama': ['libllama-cli.so']},
cmdclass={
'build_ext': CustomBuildExtCommand,
},
install_requires=[
'attrs>=23.2.0',
'huggingface-hub>=0.23.4',
'cffi>=1.16.0',
],
)

0 comments on commit aa8627c

Please sign in to comment.