-
Notifications
You must be signed in to change notification settings - Fork 233
/
setup.py
87 lines (71 loc) · 2.32 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
import platform
from Cython.Build import cythonize
from setuptools import Extension, setup
from setuptools.command.bdist_rpm import bdist_rpm as _bdist_rpm
from setuptools.command.build_ext import build_ext
from setuptools.errors import CCompilerError, ExecError, PlatformError
# Those are needed to build _hton for windows
CFLAGS = ["-O2"]
LDFLAGS = []
LIBRARIES = []
if platform.uname().system == "Windows":
LDFLAGS.append("ws2_32.lib")
else:
CFLAGS.extend(["-Wall", "-Wsign-compare", "-Wconversion"])
LIBRARIES.append("z")
extensions = [
Extension(
"aiokafka.record._crecords.legacy_records",
["aiokafka/record/_crecords/legacy_records.pyx"],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
Extension(
"aiokafka.record._crecords.default_records",
[
"aiokafka/record/_crecords/crc32c.c",
"aiokafka/record/_crecords/default_records.pyx",
],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
Extension(
"aiokafka.record._crecords.memory_records",
["aiokafka/record/_crecords/memory_records.pyx"],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
Extension(
"aiokafka.record._crecords.cutil",
["aiokafka/record/_crecords/crc32c.c", "aiokafka/record/_crecords/cutil.pyx"],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
]
class bdist_rpm(_bdist_rpm):
def _make_spec_file(self):
orig = super()._make_spec_file()
orig.insert(0, "%define debug_package %{nil}")
return orig
class BuildFailed(Exception):
pass
class ve_build_ext(build_ext):
# This class allows C extension building to fail.
def run(self):
try:
build_ext.run(self)
except (PlatformError, FileNotFoundError) as exc:
raise BuildFailed() from exc
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, ExecError, PlatformError, ValueError) as exc:
raise BuildFailed() from exc
setup(
ext_modules=cythonize(extensions),
cmdclass={"build_ext": ve_build_ext, "bdist_rpm": bdist_rpm},
)