25 'common/xxhash.c', |
25 'common/xxhash.c', |
26 'common/zstd_common.c', |
26 'common/zstd_common.c', |
27 'compress/fse_compress.c', |
27 'compress/fse_compress.c', |
28 'compress/huf_compress.c', |
28 'compress/huf_compress.c', |
29 'compress/zstd_compress.c', |
29 'compress/zstd_compress.c', |
|
30 'compress/zstd_double_fast.c', |
|
31 'compress/zstd_fast.c', |
|
32 'compress/zstd_lazy.c', |
|
33 'compress/zstd_ldm.c', |
|
34 'compress/zstd_opt.c', |
30 'compress/zstdmt_compress.c', |
35 'compress/zstdmt_compress.c', |
31 'decompress/huf_decompress.c', |
36 'decompress/huf_decompress.c', |
32 'decompress/zstd_decompress.c', |
37 'decompress/zstd_decompress.c', |
33 'dictBuilder/cover.c', |
38 'dictBuilder/cover.c', |
34 'dictBuilder/divsufsort.c', |
39 'dictBuilder/divsufsort.c', |
36 )] |
41 )] |
37 |
42 |
38 # Headers whose preprocessed output will be fed into cdef(). |
43 # Headers whose preprocessed output will be fed into cdef(). |
39 HEADERS = [os.path.join(HERE, 'zstd', *p) for p in ( |
44 HEADERS = [os.path.join(HERE, 'zstd', *p) for p in ( |
40 ('zstd.h',), |
45 ('zstd.h',), |
41 ('compress', 'zstdmt_compress.h'), |
|
42 ('dictBuilder', 'zdict.h'), |
46 ('dictBuilder', 'zdict.h'), |
43 )] |
47 )] |
44 |
48 |
45 INCLUDE_DIRS = [os.path.join(HERE, d) for d in ( |
49 INCLUDE_DIRS = [os.path.join(HERE, d) for d in ( |
46 'zstd', |
50 'zstd', |
78 raise Exception('unsupported compiler type: %s' % compiler.compiler_type) |
82 raise Exception('unsupported compiler type: %s' % compiler.compiler_type) |
79 |
83 |
80 def preprocess(path): |
84 def preprocess(path): |
81 with open(path, 'rb') as fh: |
85 with open(path, 'rb') as fh: |
82 lines = [] |
86 lines = [] |
83 for l in fh: |
87 it = iter(fh) |
|
88 |
|
89 for l in it: |
84 # zstd.h includes <stddef.h>, which is also included by cffi's |
90 # zstd.h includes <stddef.h>, which is also included by cffi's |
85 # boilerplate. This can lead to duplicate declarations. So we strip |
91 # boilerplate. This can lead to duplicate declarations. So we strip |
86 # this include from the preprocessor invocation. |
92 # this include from the preprocessor invocation. |
87 # |
93 # |
88 # The same things happens for including zstd.h, so give it the same |
94 # The same things happens for including zstd.h, so give it the same |
135 |
141 |
136 return b'\n'.join(lines) |
142 return b'\n'.join(lines) |
137 |
143 |
138 |
144 |
139 ffi = cffi.FFI() |
145 ffi = cffi.FFI() |
|
146 # zstd.h uses a possible undefined MIN(). Define it until |
|
147 # https://github.com/facebook/zstd/issues/976 is fixed. |
140 # *_DISABLE_DEPRECATE_WARNINGS prevents the compiler from emitting a warning |
148 # *_DISABLE_DEPRECATE_WARNINGS prevents the compiler from emitting a warning |
141 # when cffi uses the function. Since we statically link against zstd, even |
149 # when cffi uses the function. Since we statically link against zstd, even |
142 # if we use the deprecated functions it shouldn't be a huge problem. |
150 # if we use the deprecated functions it shouldn't be a huge problem. |
143 ffi.set_source('_zstd_cffi', ''' |
151 ffi.set_source('_zstd_cffi', ''' |
144 #include "mem.h" |
152 #define MIN(a,b) ((a)<(b) ? (a) : (b)) |
145 #define ZSTD_STATIC_LINKING_ONLY |
153 #define ZSTD_STATIC_LINKING_ONLY |
146 #include "zstd.h" |
154 #include <zstd.h> |
147 #define ZDICT_STATIC_LINKING_ONLY |
155 #define ZDICT_STATIC_LINKING_ONLY |
148 #define ZDICT_DISABLE_DEPRECATE_WARNINGS |
156 #define ZDICT_DISABLE_DEPRECATE_WARNINGS |
149 #include "zdict.h" |
157 #include <zdict.h> |
150 #include "zstdmt_compress.h" |
158 ''', sources=SOURCES, |
151 ''', sources=SOURCES, include_dirs=INCLUDE_DIRS) |
159 include_dirs=INCLUDE_DIRS, |
|
160 extra_compile_args=['-DZSTD_MULTITHREAD']) |
152 |
161 |
153 DEFINE = re.compile(b'^\\#define ([a-zA-Z0-9_]+) ') |
162 DEFINE = re.compile(b'^\\#define ([a-zA-Z0-9_]+) ') |
154 |
163 |
155 sources = [] |
164 sources = [] |
156 |
165 |