|
3 | 3 | import os |
4 | 4 |
|
5 | 5 |
|
6 | | -def multi_join(paths, *path_segments): |
7 | | - """apply os.path.join on a list of paths""" |
8 | | - return [os.path.join(*(path_segments + (path,))) for path in paths] |
| 6 | +def zstd_ext_kwargs(pc, system_prefix): |
| 7 | + if system_prefix: |
| 8 | + print('Detected and preferring libzstd [via BORG_LIBZSTD_PREFIX]') |
| 9 | + return dict(include_dirs=[os.path.join(system_prefix, 'include')], |
| 10 | + library_dirs=[os.path.join(system_prefix, 'lib')], |
| 11 | + libraries=['zstd']) |
9 | 12 |
|
| 13 | + if pc and pc.installed('libzstd', '>= 1.3.0'): |
| 14 | + print('Detected and preferring libzstd [via pkg-config]') |
| 15 | + return pc.parse('libzstd') |
10 | 16 |
|
11 | | -# zstd files, structure as seen in zstd project repository: |
| 17 | + raise Exception('Could not find zstd lib/headers, please set BORG_LIBZSTD_PREFIX') |
12 | 18 |
|
13 | | -# path relative (to this file) to the bundled library source code files |
14 | | -zstd_bundled_path = 'src/borg/algorithms/zstd' |
15 | 19 |
|
16 | | -zstd_sources = [ |
17 | | - 'lib/common/debug.c', |
18 | | - 'lib/common/entropy_common.c', |
19 | | - 'lib/common/error_private.c', |
20 | | - 'lib/common/fse_decompress.c', |
21 | | - 'lib/common/pool.c', |
22 | | - 'lib/common/threading.c', |
23 | | - 'lib/common/xxhash.c', |
24 | | - 'lib/common/zstd_common.c', |
25 | | - 'lib/compress/fse_compress.c', |
26 | | - 'lib/compress/hist.c', |
27 | | - 'lib/compress/huf_compress.c', |
28 | | - 'lib/compress/zstd_compress.c', |
29 | | - 'lib/compress/zstd_compress_literals.c', |
30 | | - 'lib/compress/zstd_compress_sequences.c', |
31 | | - 'lib/compress/zstd_compress_superblock.c', |
32 | | - 'lib/compress/zstd_double_fast.c', |
33 | | - 'lib/compress/zstd_fast.c', |
34 | | - 'lib/compress/zstd_lazy.c', |
35 | | - 'lib/compress/zstd_ldm.c', |
36 | | - 'lib/compress/zstd_opt.c', |
37 | | - 'lib/compress/zstdmt_compress.c', |
38 | | - 'lib/decompress/huf_decompress.c', |
39 | | - 'lib/decompress/zstd_ddict.c', |
40 | | - 'lib/decompress/zstd_decompress.c', |
41 | | - 'lib/decompress/zstd_decompress_block.c', |
42 | | - 'lib/dictBuilder/cover.c', |
43 | | - 'lib/dictBuilder/divsufsort.c', |
44 | | - 'lib/dictBuilder/fastcover.c', |
45 | | - 'lib/dictBuilder/zdict.c', |
46 | | -] |
| 20 | +def lz4_ext_kwargs(pc, system_prefix): |
| 21 | + if system_prefix: |
| 22 | + print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]') |
| 23 | + return dict(include_dirs=[os.path.join(system_prefix, 'include')], |
| 24 | + library_dirs=[os.path.join(system_prefix, 'lib')], |
| 25 | + libraries=['lz4']) |
47 | 26 |
|
48 | | -zstd_sources_legacy = [ |
49 | | - 'lib/deprecated/zbuff_common.c', |
50 | | - 'lib/deprecated/zbuff_compress.c', |
51 | | - 'lib/deprecated/zbuff_decompress.c', |
52 | | - 'lib/legacy/zstd_v01.c', |
53 | | - 'lib/legacy/zstd_v02.c', |
54 | | - 'lib/legacy/zstd_v03.c', |
55 | | - 'lib/legacy/zstd_v04.c', |
56 | | - 'lib/legacy/zstd_v05.c', |
57 | | - 'lib/legacy/zstd_v06.c', |
58 | | - 'lib/legacy/zstd_v07.c', |
59 | | -] |
| 27 | + if pc and pc.installed('liblz4', '>= 1.7.0'): |
| 28 | + print('Detected and preferring liblz4 [via pkg-config]') |
| 29 | + return pc.parse('liblz4') |
60 | 30 |
|
61 | | -zstd_includes = [ |
62 | | - 'lib', |
63 | | - 'lib/common', |
64 | | - 'lib/compress', |
65 | | - 'lib/decompress', |
66 | | - 'lib/dictBuilder', |
67 | | -] |
68 | | - |
69 | | -zstd_includes_legacy = [ |
70 | | - 'lib/deprecated', |
71 | | - 'lib/legacy', |
72 | | -] |
73 | | - |
74 | | - |
75 | | -def zstd_ext_kwargs(pc, prefer_system, system_prefix, multithreaded=False, legacy=False): |
76 | | - if prefer_system: |
77 | | - if system_prefix: |
78 | | - print('Detected and preferring libzstd [via BORG_LIBZSTD_PREFIX]') |
79 | | - return dict(include_dirs=[os.path.join(system_prefix, 'include')], |
80 | | - library_dirs=[os.path.join(system_prefix, 'lib')], |
81 | | - libraries=['zstd']) |
82 | | - |
83 | | - if pc and pc.installed('libzstd', '>= 1.3.0'): |
84 | | - print('Detected and preferring libzstd [via pkg-config]') |
85 | | - return pc.parse('libzstd') |
86 | | - |
87 | | - print('Using bundled ZSTD') |
88 | | - sources = multi_join(zstd_sources, zstd_bundled_path) |
89 | | - if legacy: |
90 | | - sources += multi_join(zstd_sources_legacy, zstd_bundled_path) |
91 | | - include_dirs = multi_join(zstd_includes, zstd_bundled_path) |
92 | | - if legacy: |
93 | | - include_dirs += multi_join(zstd_includes_legacy, zstd_bundled_path) |
94 | | - extra_compile_args = ['-DZSTDLIB_VISIBILITY=', '-DZDICTLIB_VISIBILITY=', '-DZSTDERRORLIB_VISIBILITY=', ] |
95 | | - # '-fvisibility=hidden' does not work, doesn't find PyInit_compress then |
96 | | - if legacy: |
97 | | - extra_compile_args += ['-DZSTD_LEGACY_SUPPORT=1', ] |
98 | | - if multithreaded: |
99 | | - extra_compile_args += ['-DZSTD_MULTITHREAD', ] |
100 | | - define_macros = [('BORG_USE_BUNDLED_ZSTD', 'YES')] |
101 | | - return dict(sources=sources, include_dirs=include_dirs, |
102 | | - extra_compile_args=extra_compile_args, define_macros=define_macros) |
103 | | - |
104 | | - |
105 | | -# lz4 files, structure as seen in lz4 project repository: |
106 | | - |
107 | | -# path relative (to this file) to the bundled library source code files |
108 | | -lz4_bundled_path = 'src/borg/algorithms/lz4' |
109 | | - |
110 | | -lz4_sources = [ |
111 | | - 'lib/lz4.c', |
112 | | -] |
113 | | - |
114 | | -lz4_includes = [ |
115 | | - 'lib', |
116 | | -] |
117 | | - |
118 | | - |
119 | | -def lz4_ext_kwargs(pc, prefer_system, system_prefix): |
120 | | - if prefer_system: |
121 | | - if system_prefix: |
122 | | - print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]') |
123 | | - return dict(include_dirs=[os.path.join(system_prefix, 'include')], |
124 | | - library_dirs=[os.path.join(system_prefix, 'lib')], |
125 | | - libraries=['lz4']) |
126 | | - |
127 | | - if pc and pc.installed('liblz4', '>= 1.7.0'): |
128 | | - print('Detected and preferring liblz4 [via pkg-config]') |
129 | | - return pc.parse('liblz4') |
130 | | - |
131 | | - print('Using bundled LZ4') |
132 | | - sources = multi_join(lz4_sources, lz4_bundled_path) |
133 | | - include_dirs = multi_join(lz4_includes, lz4_bundled_path) |
134 | | - define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')] |
135 | | - return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros) |
| 31 | + raise Exception('Could not find lz4 lib/headers, please set BORG_LIBLZ4_PREFIX') |
0 commit comments