-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
130 lines (112 loc) · 4.5 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
from build import *
from setuptools import setup
import os
import pathlib
from typing import Dict, Any
import sys
from setuptools import setup
from setuptools import Extension
from setuptools.command.build_ext import build_ext
import re
import subprocess
PLAT_TO_CMAKE = {
"win32": "Win32",
"win-amd64": "x64",
"win-arm32": "ARM",
"win-arm64": "ARM64",
}
class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: str = ""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext: CMakeExtension):
ext_dir = pathlib.Path(self.get_ext_fullpath(
ext.name)).parent.absolute()
debug = int(os.environ.get("DEBUG", 0)
) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"
cmake_args = [
f"-DBUILD_SHARED_LIBS=OFF",
f"-DBUILD_PYBIND11=ON",
f"-DPRINT_BENCHMARK=OFF",
f"-DBUILD_TESTS=OFF",
f"-DBUILD_BENCHMARKS=OFF",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={ext_dir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}",
]
build_args = []
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
if sys.platform.startswith("win"):
# Single config generators are handled "normally"
single_config = any(
x in cmake_generator for x in {"NMake", "Ninja"})
# CMake allows an arch-in-generator style for backward compatibility
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
# Specify the arch if using MSVC generator, but only if it doesn't
# contain a backward-compatibility arch spec already in the
# generator name.
if not single_config and not contains_arch:
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
# Multi-config generators have a different way to specify configs
if not single_config:
cmake_args += [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={ext_dir}"
]
build_args += ["--config", cfg]
if sys.platform.startswith("darwin"):
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += [
"-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
subprocess.run(
["cmake", ext.sourcedir] + cmake_args,
cwd=build_temp,
check=True,
)
subprocess.run(
["cmake", "--build", "."] + build_args,
cwd=build_temp,
check=True,
)
setup(
name='libstreamvbyte',
version='0.3.8',
description='A C++ implementation of StreamVByte, with Python bindings.',
long_description=open('README.md').read(),
author='HSING-HAN WU (Xyphuz)',
author_email='[email protected]',
maintainer='HSING-HAN WU (Xyphuz)',
maintainer_email='[email protected]',
url='https://github.com/wst24365888/libstreamvbyte',
python_requires='>=3.8,<4.0',
ext_modules=[CMakeExtension("libstreamvbyte")],
cmdclass=dict(build_ext=CMakeBuild),
long_description_content_type='text/markdown',
license='MIT',
classifiers=[
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: System :: Archiving :: Compression',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords='streamvbyte, libstreamvbyte, vbyte, integer, compression, SIMD, vectorization, SSSE3, NEON, SSE2NEON, Python, C++, CMake, pybind11',
)