comparison contrib/python-zstandard/setup_zstd.py @ 37495:b1fb341d8a61

zstandard: vendor python-zstandard 0.9.0 This was just released. It features a number of goodies. More info at https://gregoryszorc.com/blog/2018/04/09/release-of-python-zstandard-0.9/. The clang-format ignore list was updated to reflect the new source of files. The project contains a vendored copy of zstandard 1.3.4. The old version was 1.1.3. One of the changes between those versions is that zstandard is now dual licensed BSD + GPLv2 and the patent rights grant has been removed. Good riddance. The API should be backwards compatible. So no changes in core should be needed. However, there were a number of changes in the library that we'll want to adapt to. Those will be addressed in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D3198
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 09 Apr 2018 10:13:29 -0700
parents e0dc40530c5a
children c0081d3e1598
comparison
equal deleted inserted replaced
37494:1ce7a55b09d1 37495:b1fb341d8a61
2 # All rights reserved. 2 # All rights reserved.
3 # 3 #
4 # This software may be modified and distributed under the terms 4 # This software may be modified and distributed under the terms
5 # of the BSD license. See the LICENSE file for details. 5 # of the BSD license. See the LICENSE file for details.
6 6
7 import distutils.ccompiler
7 import os 8 import os
9 import sys
10
8 from distutils.extension import Extension 11 from distutils.extension import Extension
9 12
10 13
11 zstd_sources = ['zstd/%s' % p for p in ( 14 zstd_sources = ['zstd/%s' % p for p in (
12 'common/entropy_common.c', 15 'common/entropy_common.c',
17 'common/xxhash.c', 20 'common/xxhash.c',
18 'common/zstd_common.c', 21 'common/zstd_common.c',
19 'compress/fse_compress.c', 22 'compress/fse_compress.c',
20 'compress/huf_compress.c', 23 'compress/huf_compress.c',
21 'compress/zstd_compress.c', 24 'compress/zstd_compress.c',
25 'compress/zstd_double_fast.c',
26 'compress/zstd_fast.c',
27 'compress/zstd_lazy.c',
28 'compress/zstd_ldm.c',
29 'compress/zstd_opt.c',
22 'compress/zstdmt_compress.c', 30 'compress/zstdmt_compress.c',
23 'decompress/huf_decompress.c', 31 'decompress/huf_decompress.c',
24 'decompress/zstd_decompress.c', 32 'decompress/zstd_decompress.c',
25 'dictBuilder/cover.c', 33 'dictBuilder/cover.c',
26 'dictBuilder/divsufsort.c', 34 'dictBuilder/divsufsort.c',
39 'legacy/zstd_v06.c', 47 'legacy/zstd_v06.c',
40 'legacy/zstd_v07.c' 48 'legacy/zstd_v07.c'
41 )] 49 )]
42 50
43 zstd_includes = [ 51 zstd_includes = [
44 'c-ext',
45 'zstd', 52 'zstd',
46 'zstd/common', 53 'zstd/common',
47 'zstd/compress', 54 'zstd/compress',
48 'zstd/decompress', 55 'zstd/decompress',
49 'zstd/dictBuilder', 56 'zstd/dictBuilder',
52 zstd_includes_legacy = [ 59 zstd_includes_legacy = [
53 'zstd/deprecated', 60 'zstd/deprecated',
54 'zstd/legacy', 61 'zstd/legacy',
55 ] 62 ]
56 63
64 ext_includes = [
65 'c-ext',
66 'zstd/common',
67 ]
68
57 ext_sources = [ 69 ext_sources = [
70 'zstd/common/pool.c',
71 'zstd/common/threading.c',
58 'zstd.c', 72 'zstd.c',
59 'c-ext/bufferutil.c', 73 'c-ext/bufferutil.c',
60 'c-ext/compressiondict.c', 74 'c-ext/compressiondict.c',
61 'c-ext/compressobj.c', 75 'c-ext/compressobj.c',
62 'c-ext/compressor.c', 76 'c-ext/compressor.c',
63 'c-ext/compressoriterator.c', 77 'c-ext/compressoriterator.c',
64 'c-ext/compressionparams.c', 78 'c-ext/compressionparams.c',
79 'c-ext/compressionreader.c',
65 'c-ext/compressionwriter.c', 80 'c-ext/compressionwriter.c',
66 'c-ext/constants.c', 81 'c-ext/constants.c',
67 'c-ext/decompressobj.c', 82 'c-ext/decompressobj.c',
68 'c-ext/decompressor.c', 83 'c-ext/decompressor.c',
69 'c-ext/decompressoriterator.c', 84 'c-ext/decompressoriterator.c',
85 'c-ext/decompressionreader.c',
70 'c-ext/decompressionwriter.c', 86 'c-ext/decompressionwriter.c',
71 'c-ext/frameparams.c', 87 'c-ext/frameparams.c',
72 ] 88 ]
73 89
74 zstd_depends = [ 90 zstd_depends = [
75 'c-ext/python-zstandard.h', 91 'c-ext/python-zstandard.h',
76 ] 92 ]
77 93
78 94
79 def get_c_extension(support_legacy=False, name='zstd'): 95 def get_c_extension(support_legacy=False, system_zstd=False, name='zstd',
96 warnings_as_errors=False):
80 """Obtain a distutils.extension.Extension for the C extension.""" 97 """Obtain a distutils.extension.Extension for the C extension."""
81 root = os.path.abspath(os.path.dirname(__file__)) 98 root = os.path.abspath(os.path.dirname(__file__))
82 99
83 sources = [os.path.join(root, p) for p in zstd_sources + ext_sources] 100 sources = set([os.path.join(root, p) for p in ext_sources])
84 if support_legacy: 101 if not system_zstd:
85 sources.extend([os.path.join(root, p) for p in zstd_sources_legacy]) 102 sources.update([os.path.join(root, p) for p in zstd_sources])
103 if support_legacy:
104 sources.update([os.path.join(root, p) for p in zstd_sources_legacy])
105 sources = list(sources)
86 106
87 include_dirs = [os.path.join(root, d) for d in zstd_includes] 107 include_dirs = set([os.path.join(root, d) for d in ext_includes])
88 if support_legacy: 108 if not system_zstd:
89 include_dirs.extend([os.path.join(root, d) for d in zstd_includes_legacy]) 109 include_dirs.update([os.path.join(root, d) for d in zstd_includes])
110 if support_legacy:
111 include_dirs.update([os.path.join(root, d) for d in zstd_includes_legacy])
112 include_dirs = list(include_dirs)
90 113
91 depends = [os.path.join(root, p) for p in zstd_depends] 114 depends = [os.path.join(root, p) for p in zstd_depends]
92 115
116 compiler = distutils.ccompiler.new_compiler()
117
118 # Needed for MSVC.
119 if hasattr(compiler, 'initialize'):
120 compiler.initialize()
121
122 if compiler.compiler_type == 'unix':
123 compiler_type = 'unix'
124 elif compiler.compiler_type == 'msvc':
125 compiler_type = 'msvc'
126 else:
127 raise Exception('unhandled compiler type: %s' %
128 compiler.compiler_type)
129
93 extra_args = ['-DZSTD_MULTITHREAD'] 130 extra_args = ['-DZSTD_MULTITHREAD']
94 131
95 if support_legacy: 132 if not system_zstd:
133 extra_args.append('-DZSTDLIB_VISIBILITY=')
134 extra_args.append('-DZDICTLIB_VISIBILITY=')
135 extra_args.append('-DZSTDERRORLIB_VISIBILITY=')
136
137 if compiler_type == 'unix':
138 extra_args.append('-fvisibility=hidden')
139
140 if not system_zstd and support_legacy:
96 extra_args.append('-DZSTD_LEGACY_SUPPORT=1') 141 extra_args.append('-DZSTD_LEGACY_SUPPORT=1')
142
143 if warnings_as_errors:
144 if compiler_type == 'unix':
145 extra_args.append('-Werror')
146 elif compiler_type == 'msvc':
147 extra_args.append('/WX')
148 else:
149 assert False
150
151 libraries = ['zstd'] if system_zstd else []
97 152
98 # TODO compile with optimizations. 153 # TODO compile with optimizations.
99 return Extension(name, sources, 154 return Extension(name, sources,
100 include_dirs=include_dirs, 155 include_dirs=include_dirs,
101 depends=depends, 156 depends=depends,
102 extra_compile_args=extra_args) 157 extra_compile_args=extra_args,
158 libraries=libraries)