|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import sys |
| 4 | +import platform |
| 5 | +from setuptools import setup, find_packages |
| 6 | +from setuptools.dist import Distribution |
| 7 | +from setuptools.command.build_py import build_py as build_py_orig |
| 8 | + |
| 9 | +class BinaryDistribution(Distribution): |
| 10 | + """Distribution that includes binary components.""" |
| 11 | + def has_ext_modules(self): |
| 12 | + return True |
| 13 | + |
| 14 | +class CustomBuildPy(build_py_orig): |
| 15 | + """Custom build command to copy the appropriate shared library.""" |
| 16 | + def run(self): |
| 17 | + # Determine platform and architecture |
| 18 | + current_platform = sys.platform |
| 19 | + machine = platform.machine().lower() |
| 20 | + |
| 21 | + # Map sys.platform to your binaries directory |
| 22 | + if current_platform.startswith("linux"): |
| 23 | + platform_key = "linux_" + machine |
| 24 | + lib_extension = ".so" |
| 25 | + elif current_platform.startswith("darwin"): |
| 26 | + platform_key = "macos_" + machine |
| 27 | + lib_extension = ".dylib" |
| 28 | + elif current_platform.startswith("win"): |
| 29 | + platform_key = "windows_" + machine |
| 30 | + lib_extension = ".dll" |
| 31 | + else: |
| 32 | + raise RuntimeError(f"Unsupported platform: {current_platform}") |
| 33 | + |
| 34 | + # Define the path to the shared library. TODO: This is a hack to get the path to the shared library. We need to find a better way to do this for multiple platforms. |
| 35 | + source_so = os.path.abspath(os.path.join(os.path.dirname(__file__), f'../cmake-build-debug/libNeonPy/liblibNeonPy{lib_extension}')) |
| 36 | + |
| 37 | + # Define the destination directory within the build directory |
| 38 | + destination_dir = os.path.join(self.build_lib, 'neon', 'lib', platform_key) |
| 39 | + destination_so = os.path.join(destination_dir, os.path.basename(source_so)) |
| 40 | + |
| 41 | + # Ensure the destination directory exists |
| 42 | + os.makedirs(destination_dir, exist_ok=True) |
| 43 | + |
| 44 | + # Copy the shared library to the destination directory |
| 45 | + try: |
| 46 | + shutil.copy2(source_so, destination_so) |
| 47 | + print(f"Copied {source_so} to {destination_so}") |
| 48 | + except IOError as e: |
| 49 | + print(f"Error copying {source_so} to {destination_so}: {e}") |
| 50 | + raise e |
| 51 | + |
| 52 | + # Continue with the standard build process |
| 53 | + super().run() |
| 54 | + |
| 55 | +setup( |
| 56 | + name="neon", |
| 57 | + version="0.1.0", |
| 58 | + packages=find_packages(), |
| 59 | + package_data={ |
| 60 | + "neon": [ |
| 61 | + "**/*.h", # Include all .h files recursively |
| 62 | + ] |
| 63 | + }, |
| 64 | + include_package_data=True, |
| 65 | + distclass=BinaryDistribution, |
| 66 | + cmdclass={ |
| 67 | + 'build_py': CustomBuildPy, |
| 68 | + }, |
| 69 | + python_requires=">=3.10", # This should be the minimum version of python that warp supports. |
| 70 | + # TODO: We need to add warp to the requirements later. Currently we're using a custom build of warp. |
| 71 | + install_requires=[ |
| 72 | + "numpy>=2.0", |
| 73 | + "nvtx" |
| 74 | + ], |
| 75 | +) |
0 commit comments