|
1 | | -import sys |
2 | 1 | import os |
3 | | -from setuptools import Extension, setup |
| 2 | +import sys |
4 | 3 | from Cython.Build import cythonize |
| 4 | +from setuptools import Extension, setup |
| 5 | +from setuptools.command.build_ext import build_ext |
5 | 6 |
|
6 | 7 | vi = sys.version_info |
7 | 8 | if vi < (3, 9): |
8 | 9 | raise RuntimeError('picows requires Python 3.9 or greater') |
9 | 10 |
|
| 11 | + |
| 12 | +class CustomBuildExt(build_ext): |
| 13 | + def build_extensions(self): |
| 14 | + for ext in self.extensions: |
| 15 | + if ext.extra_compile_args: |
| 16 | + ext.extra_compile_args = [ |
| 17 | + flag for flag in ext.extra_compile_args if flag != '-g' |
| 18 | + ] |
| 19 | + if ext.extra_link_args: |
| 20 | + ext.extra_link_args = [ |
| 21 | + flag for flag in ext.extra_link_args if flag != '-g' |
| 22 | + ] |
| 23 | + |
| 24 | + if os.name != 'nt': |
| 25 | + self.compiler.compiler_so = [ |
| 26 | + flag for flag in self.compiler.compiler_so if flag != '-g' |
| 27 | + ] |
| 28 | + self.compiler.linker_so = [ |
| 29 | + flag for flag in self.compiler.linker_so if flag != '-g' |
| 30 | + ] |
| 31 | + super().build_extensions() |
| 32 | + |
| 33 | + |
10 | 34 | if os.name == 'nt': |
| 35 | + compile_args = ["/O2", "/DNDEBUG"] |
| 36 | + link_args = [] |
11 | 37 | libraries = ["Ws2_32"] |
12 | 38 | else: |
| 39 | + compile_args = ["-O2", "-Wall", "-DNDEBUG", "-fno-strict-overflow", "-Wsign-compare", "-fPIC"] |
| 40 | + link_args = ["-Wl,-s"] |
13 | 41 | libraries = None |
14 | 42 |
|
15 | 43 | cython_modules = [ |
16 | | - Extension("picows.picows", ["picows/picows.pyx"], libraries=libraries) |
17 | | - ] |
| 44 | + Extension( |
| 45 | + "picows.picows", |
| 46 | + ["picows/picows.pyx"], |
| 47 | + libraries=libraries, |
| 48 | + extra_compile_args=compile_args, |
| 49 | + extra_link_args=link_args, |
| 50 | + ) |
| 51 | +] |
18 | 52 |
|
19 | 53 | if os.getenv("PICOWS_BUILD_EXAMPLES") is not None: |
20 | | - cython_modules.append(Extension("examples.echo_client_cython", ["examples/echo_client_cython.pyx"])) |
| 54 | + cython_modules.append( |
| 55 | + Extension( |
| 56 | + "examples.echo_client_cython", |
| 57 | + ["examples/echo_client_cython.pyx"], |
| 58 | + extra_compile_args=compile_args, |
| 59 | + extra_link_args=link_args, |
| 60 | + ) |
| 61 | + ) |
21 | 62 |
|
22 | 63 | setup( |
| 64 | + cmdclass={'build_ext': CustomBuildExt}, |
23 | 65 | ext_modules=cythonize( |
24 | 66 | cython_modules, |
25 | 67 | compiler_directives={ |
26 | | - 'language_level': sys.version_info[0], |
| 68 | + 'language_level': vi[0], |
27 | 69 | 'profile': False, |
28 | 70 | 'nonecheck': False, |
29 | 71 | 'boundscheck': False, |
|
32 | 74 | 'optimize.use_switch': False, |
33 | 75 | 'cdivision': True |
34 | 76 | }, |
35 | | - annotate=True, |
| 77 | + annotate=False, |
36 | 78 | gdb_debug=False |
37 | 79 | ), |
38 | 80 | ) |
0 commit comments