13
13
PY2 = sys .version_info [0 ] == 2
14
14
15
15
16
+ # determine CPU support for SSE2 and AVX2
17
+ cpu_info = cpuinfo .get_cpu_info ()
18
+ have_sse2 = 'sse2' in cpu_info ['flags' ]
19
+ have_avx2 = 'avx2' in cpu_info ['flags' ]
20
+ disable_sse2 = 'DISABLE_NUMCODECS_SSE2' in os .environ
21
+ disable_avx2 = 'DISABLE_NUMCODECS_AVX2' in os .environ
22
+
23
+
24
+ # setup common compile arguments
25
+ have_cflags = 'CFLAGS' in os .environ
26
+ base_compile_args = list ()
27
+ if have_cflags :
28
+ # respect compiler options set by user
29
+ pass
30
+ elif os .name == 'posix' :
31
+ if disable_sse2 :
32
+ base_compile_args .append ('-mno-sse2' )
33
+ elif have_sse2 :
34
+ base_compile_args .append ('-msse2' )
35
+ if disable_avx2 :
36
+ base_compile_args .append ('-mno-avx2' )
37
+ elif have_avx2 :
38
+ base_compile_args .append ('-mavx2' )
39
+ # workaround lack of support for "inline" in MSVC when building for Python 2.7 64-bit
40
+ if PY2 and os .name == 'nt' :
41
+ base_compile_args .append ('-Dinline=__inline' )
42
+
43
+
16
44
try :
17
45
from Cython .Build import cythonize
18
46
except ImportError :
@@ -34,23 +62,22 @@ def error(*msg):
34
62
def blosc_extension ():
35
63
info ('setting up Blosc extension' )
36
64
37
- # setup blosc extension
38
- blosc_sources = []
39
- extra_compile_args = []
40
- include_dirs = []
65
+ extra_compile_args = list (base_compile_args )
41
66
define_macros = []
42
67
43
- # generic setup
44
- blosc_sources += [f for f in glob ('c-blosc/blosc/*.c' )
45
- if 'avx2' not in f and 'sse2' not in f ]
68
+ # setup blosc sources
69
+ blosc_sources = [f for f in glob ('c-blosc/blosc/*.c' )
70
+ if 'avx2' not in f and 'sse2' not in f ]
71
+ include_dirs = [os .path .join ('c-blosc' , 'blosc' )]
72
+
73
+ # add internal complibs
46
74
blosc_sources += glob ('c-blosc/internal-complibs/lz4*/*.c' )
47
75
blosc_sources += glob ('c-blosc/internal-complibs/snappy*/*.cc' )
48
76
blosc_sources += glob ('c-blosc/internal-complibs/zlib*/*.c' )
49
77
blosc_sources += glob ('c-blosc/internal-complibs/zstd*/common/*.c' )
50
78
blosc_sources += glob ('c-blosc/internal-complibs/zstd*/compress/*.c' )
51
79
blosc_sources += glob ('c-blosc/internal-complibs/zstd*/decompress/*.c' )
52
80
blosc_sources += glob ('c-blosc/internal-complibs/zstd*/dictBuilder/*.c' )
53
- include_dirs += [os .path .join ('c-blosc' , 'blosc' )]
54
81
include_dirs += [d for d in glob ('c-blosc/internal-complibs/*' )
55
82
if os .path .isdir (d )]
56
83
include_dirs += [d for d in glob ('c-blosc/internal-complibs/*/*' )
@@ -61,33 +88,25 @@ def blosc_extension():
61
88
('HAVE_ZSTD' , 1 )]
62
89
# define_macros += [('CYTHON_TRACE', '1')]
63
90
64
- # determine CPU support for SSE2 and AVX2
65
- cpu_info = cpuinfo .get_cpu_info ()
66
-
67
91
# SSE2
68
- if 'sse2' in cpu_info [ 'flags' ] and 'DISABLE_NUMCODECS_SSE2' not in os . environ :
69
- info ('building with SSE2 support' )
92
+ if have_sse2 and not disable_sse2 :
93
+ info ('compiling Blosc extension with SSE2 support' )
70
94
extra_compile_args .append ('-DSHUFFLE_SSE2_ENABLED' )
71
95
blosc_sources += [f for f in glob ('c-blosc/blosc/*.c' ) if 'sse2' in f ]
72
- if os .name == 'posix' :
73
- extra_compile_args .append ('-msse2' )
74
- elif os .name == 'nt' :
96
+ if os .name == 'nt' :
75
97
define_macros += [('__SSE2__' , 1 )]
98
+ else :
99
+ info ('compiling Blosc extension without SSE2 support' )
76
100
77
101
# AVX2
78
- if 'avx2' in cpu_info [ 'flags' ] and 'DISABLE_NUMCODECS_AVX2' not in os . environ :
79
- info ('building with AVX2 support' )
102
+ if have_avx2 and not disable_avx2 :
103
+ info ('compiling Blosc extension with AVX2 support' )
80
104
extra_compile_args .append ('-DSHUFFLE_AVX2_ENABLED' )
81
105
blosc_sources += [f for f in glob ('c-blosc/blosc/*.c' ) if 'avx2' in f ]
82
- if os .name == 'posix' :
83
- extra_compile_args .append ('-mavx2' )
84
- elif os .name == 'nt' :
106
+ if os .name == 'nt' :
85
107
define_macros += [('__AVX2__' , 1 )]
86
-
87
- # workaround lack of support for "inline" in MSVC when building for Python
88
- # 2.7 64-bit
89
- if PY2 and os .name == 'nt' :
90
- extra_compile_args .append ('-Dinline=__inline' )
108
+ else :
109
+ info ('compiling Blosc extension without AVX2 support' )
91
110
92
111
if have_cython :
93
112
sources = ['numcodecs/blosc.pyx' ]
@@ -114,7 +133,7 @@ def zstd_extension():
114
133
info ('setting up Zstandard extension' )
115
134
116
135
zstd_sources = []
117
- extra_compile_args = []
136
+ extra_compile_args = list ( base_compile_args )
118
137
include_dirs = []
119
138
define_macros = []
120
139
@@ -123,18 +142,12 @@ def zstd_extension():
123
142
zstd_sources += glob ('c-blosc/internal-complibs/zstd*/compress/*.c' )
124
143
zstd_sources += glob ('c-blosc/internal-complibs/zstd*/decompress/*.c' )
125
144
zstd_sources += glob ('c-blosc/internal-complibs/zstd*/dictBuilder/*.c' )
126
-
127
145
include_dirs += [d for d in glob ('c-blosc/internal-complibs/zstd*' )
128
146
if os .path .isdir (d )]
129
147
include_dirs += [d for d in glob ('c-blosc/internal-complibs/zstd*/*' )
130
148
if os .path .isdir (d )]
131
149
# define_macros += [('CYTHON_TRACE', '1')]
132
150
133
- # workaround lack of support for "inline" in MSVC when building for Python
134
- # 2.7 64-bit
135
- if PY2 and os .name == 'nt' :
136
- extra_compile_args .append ('-Dinline=__inline' )
137
-
138
151
if have_cython :
139
152
sources = ['numcodecs/zstd.pyx' ]
140
153
else :
@@ -159,7 +172,7 @@ def zstd_extension():
159
172
def lz4_extension ():
160
173
info ('setting up LZ4 extension' )
161
174
162
- extra_compile_args = []
175
+ extra_compile_args = list ( base_compile_args )
163
176
define_macros = []
164
177
165
178
# setup sources - use LZ4 bundled in blosc
@@ -168,11 +181,6 @@ def lz4_extension():
168
181
include_dirs += ['numcodecs' ]
169
182
# define_macros += [('CYTHON_TRACE', '1')]
170
183
171
- # workaround lack of support for "inline" in MSVC when building for Python
172
- # 2.7 64-bit
173
- if PY2 and os .name == 'nt' :
174
- extra_compile_args .append ('-Dinline=__inline' )
175
-
176
184
if have_cython :
177
185
sources = ['numcodecs/lz4.pyx' ]
178
186
else :
@@ -197,14 +205,18 @@ def lz4_extension():
197
205
def compat_extension ():
198
206
info ('setting up compat extension' )
199
207
208
+ extra_compile_args = list (base_compile_args )
209
+
200
210
if have_cython :
201
211
sources = ['numcodecs/compat_ext.pyx' ]
202
212
else :
203
213
sources = ['numcodecs/compat_ext.c' ]
204
214
205
215
# define extension module
206
216
extensions = [
207
- Extension ('numcodecs.compat_ext' , sources = sources ),
217
+ Extension ('numcodecs.compat_ext' ,
218
+ sources = sources ,
219
+ extra_compile_args = extra_compile_args ),
208
220
]
209
221
210
222
if have_cython :
0 commit comments