forked from flier/pyfasthash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
240 lines (213 loc) · 6.96 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import math
import codecs
import platform
from glob import glob
from setuptools import setup, Extension
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md')) as f:
long_description = f.read()
machine = platform.machine()
is_x86 = machine in ['i386', 'i686', 'x86_64']
is_arm = machine in ['aarch64', 'aarch64_be', 'armv8b', 'armv8l']
is_ppc = machine in ['ppc', 'ppc64', 'ppc64le', 'ppc64le']
is_posix = os.name == "posix"
is_64bits = sys.maxsize > 2**32
def cpu_features():
from collections import namedtuple
CpuFeatures = namedtuple(
"CpuFeatures", ['sse41', 'sse42', 'aes', 'avx', 'avx2'])
sse41 = sse42 = aes = avx = avx2 = False
if is_x86:
try:
from cpuid import _is_set
sse41 = is_x86 and _is_set(1, 2, 19),
sse42 = is_x86 and _is_set(1, 2, 20),
aes = is_x86 and _is_set(1, 2, 25),
avx = is_x86 and _is_set(1, 2, 28),
avx2 = is_x86 and _is_set(7, 1, 5),
except ImportError:
if is_64bits:
sse41 = sse42 = aes = avx = avx2 = True
return CpuFeatures(sse41, sse42, aes, avx, avx2)
cpu = cpu_features()
macros = []
include_dirs = [
"src/pybind11/include",
"src/highwayhash",
]
library_dirs = []
libraries = []
extra_macros = []
extra_compile_args = []
extra_link_args = []
if os.name == "nt":
macros += [
("WIN32", None),
]
python_home = os.environ.get('PYTHON_HOME')
if python_home:
include_dirs += [
os.path.join(python_home, 'include'),
]
library_dirs += [
os.path.join(python_home, 'libs'),
]
extra_macros += [("WIN32", 1)]
extra_compile_args += ["/O2", "/GL", "/MT", "/EHsc", "/Gy", "/Zi"]
extra_link_args += ["/DLL", "/OPT:REF", "/OPT:ICF",
"/MACHINE:X64" if is_64bits else "/MACHINE:X86"]
else:
macros += [
('SUPPORT_INT128', 1),
]
if is_posix:
if sys.platform == "darwin":
include_dirs += [
'/opt/local/include',
'/usr/local/include'
]
extra_compile_args += ["-Wdeprecated-register"]
else:
libraries += ["rt", "gcc"]
if is_x86 and is_posix:
extra_compile_args += list(filter(None, [
"-msse4.2" if cpu.sse42 else None,
"-maes" if cpu.aes else None,
"-mavx" if cpu.avx else None,
"-mavx2" if cpu.avx2 else None,
]))
if is_arm:
extra_compile_args += [
'-mfloat-abi=hard',
'-march=armv7-a',
'-mfpu=neon',
]
c_libraries = [(
'fnv', {
"sources": [
'src/fnv/hash_32.c',
'src/fnv/hash_32a.c',
'src/fnv/hash_64.c',
'src/fnv/hash_64a.c'
],
"macros": extra_macros,
}
), (
'smhasher', {
"sources": [
'src/smhasher/MurmurHash1.cpp',
'src/smhasher/MurmurHash2.cpp',
'src/smhasher/MurmurHash3.cpp',
'src/smhasher/City.cpp',
'src/smhasher/Spooky.cpp',
'src/smhasher/metrohash64.cpp',
'src/smhasher/metrohash64crc.cpp',
'src/smhasher/metrohash128.cpp',
'src/smhasher/metrohash128crc.cpp',
],
"cflags": extra_compile_args,
}
), (
't1ha', {
"sources": list(filter(None, [
'src/t1ha/src/t1ha0.c',
'src/t1ha/src/t1ha0_ia32aes_avx.c' if cpu.avx else None,
'src/t1ha/src/t1ha0_ia32aes_avx2.c' if cpu.avx2 else None,
'src/t1ha/src/t1ha0_ia32aes_noavx.c',
'src/t1ha/src/t1ha1.c',
'src/t1ha/src/t1ha2.c',
])),
"macros": [
("T1HA0_AESNI_AVAILABLE", 1 if cpu.aes else 0),
("T1HA0_RUNTIME_SELECT", 1),
],
"cflags": extra_compile_args,
}
), (
'farm', {
"sources": ['src/smhasher/farmhash-c.c'],
"macros": extra_macros,
}
), (
'lookup3', {
"sources": ['src/lookup3/lookup3.c'],
"macros": extra_macros,
}
), (
'SuperFastHash', {
"sources": ['src/SuperFastHash/SuperFastHash.c'],
"macros": extra_macros,
}
), (
"highwayhash", {
"sources": list(filter(None, [
"src/highwayhash/highwayhash/arch_specific.cc",
"src/highwayhash/highwayhash/instruction_sets.cc",
"src/highwayhash/highwayhash/os_specific.cc",
"src/highwayhash/highwayhash/hh_portable.cc",
"src/highwayhash/highwayhash/hh_sse41.cc" if cpu.sse41 else None,
"src/highwayhash/highwayhash/hh_avx2.cc" if cpu.avx2 else None,
"src/highwayhash/highwayhash/hh_neon.cc" if is_arm else None,
"src/highwayhash/highwayhash/hh_vsx.cc" if is_ppc else None,
])),
"cflags": extra_compile_args + [
"-Isrc/highwayhash",
"-std=c++11"
],
}
), (
"xxhash", {
"sources": ["src/xxHash/xxhash.c"],
}
)]
libraries += [libname for (libname, _) in c_libraries]
pyhash = Extension(name="_pyhash",
sources=['src/Hash.cpp'],
depends=glob('src/*.h'),
define_macros=macros,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args + ["-std=c++11"],
extra_link_args=extra_link_args,
)
setup(name='pyhash',
version='0.9.4',
description='Python Non-cryptographic Hash Library',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/flier/pyfasthash',
download_url='https://github.com/flier/pyfasthash/releases',
platforms=["x86", "x64"],
author='Flier Lu',
author_email='[email protected]',
license="Apache Software License",
packages=['pyhash'],
libraries=c_libraries,
ext_modules=[pyhash],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Utilities'
],
keywords='hash hashing fasthash',
setup_requires=['pytest-runner', 'pytest-benchmark'],
tests_require=['pytest'],
use_2to3=True)