|
@@ -1,11 +1,17 @@
|
|
|
-# Support code for building a C extension with zstd
|
|
|
+# Support code for building a C extension with compression code
|
|
|
|
|
|
import os
|
|
|
|
|
|
+
|
|
|
+def multi_join(paths, *path_segments):
|
|
|
+ """apply os.path.join on a list of paths"""
|
|
|
+ return [os.path.join(*(path_segments + (path,))) for path in paths]
|
|
|
+
|
|
|
+
|
|
|
# zstd files, structure as seen in zstd project repository:
|
|
|
|
|
|
-# bundled_path: relative (to this file) path to the bundled library source code files
|
|
|
-bundled_path = 'src/borg/algorithms/zstd'
|
|
|
+# path relative (to this file) to the bundled library source code files
|
|
|
+zstd_bundled_path = 'src/borg/algorithms/zstd'
|
|
|
|
|
|
zstd_sources = [
|
|
|
'lib/common/debug.c',
|
|
@@ -63,11 +69,6 @@ zstd_includes_legacy = [
|
|
|
]
|
|
|
|
|
|
|
|
|
-def multi_join(paths, *path_segments):
|
|
|
- """apply os.path.join on a list of paths"""
|
|
|
- return [os.path.join(*(path_segments + (path,))) for path in paths]
|
|
|
-
|
|
|
-
|
|
|
def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
|
|
|
if prefer_system:
|
|
|
system_prefix = os.environ.get('BORG_LIBZSTD_PREFIX')
|
|
@@ -82,12 +83,12 @@ def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
|
|
|
return pc.parse('libzstd')
|
|
|
|
|
|
print('Using bundled ZSTD')
|
|
|
- sources = multi_join(zstd_sources, bundled_path)
|
|
|
+ sources = multi_join(zstd_sources, zstd_bundled_path)
|
|
|
if legacy:
|
|
|
- sources += multi_join(zstd_sources_legacy, bundled_path)
|
|
|
- include_dirs = multi_join(zstd_includes, bundled_path)
|
|
|
+ sources += multi_join(zstd_sources_legacy, zstd_bundled_path)
|
|
|
+ include_dirs = multi_join(zstd_includes, zstd_bundled_path)
|
|
|
if legacy:
|
|
|
- include_dirs += multi_join(zstd_includes_legacy, bundled_path)
|
|
|
+ include_dirs += multi_join(zstd_includes_legacy, zstd_bundled_path)
|
|
|
extra_compile_args = ['-DZSTDLIB_VISIBILITY=', '-DZDICTLIB_VISIBILITY=', '-DZSTDERRORLIB_VISIBILITY=', ]
|
|
|
# '-fvisibility=hidden' does not work, doesn't find PyInit_compress then
|
|
|
if legacy:
|
|
@@ -97,3 +98,37 @@ def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
|
|
|
define_macros = [('BORG_USE_BUNDLED_ZSTD', 'YES')]
|
|
|
return dict(sources=sources, include_dirs=include_dirs,
|
|
|
extra_compile_args=extra_compile_args, define_macros=define_macros)
|
|
|
+
|
|
|
+
|
|
|
+# lz4 files, structure as seen in lz4 project repository:
|
|
|
+
|
|
|
+# path relative (to this file) to the bundled library source code files
|
|
|
+lz4_bundled_path = 'src/borg/algorithms/lz4'
|
|
|
+
|
|
|
+lz4_sources = [
|
|
|
+ 'lib/lz4.c',
|
|
|
+]
|
|
|
+
|
|
|
+lz4_includes = [
|
|
|
+ 'lib',
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+def lz4_ext_kwargs(pc, prefer_system):
|
|
|
+ if prefer_system:
|
|
|
+ system_prefix = os.environ.get('BORG_LIBLZ4_PREFIX')
|
|
|
+ if system_prefix:
|
|
|
+ print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]')
|
|
|
+ return dict(include_dirs=[os.path.join(system_prefix, 'include')],
|
|
|
+ library_dirs=[os.path.join(system_prefix, 'lib')],
|
|
|
+ libraries=['lz4'])
|
|
|
+
|
|
|
+ if pc and pc.installed('liblz4', '>= 1.7.0'):
|
|
|
+ print('Detected and preferring liblz4 [via pkg-config]')
|
|
|
+ return pc.parse('liblz4')
|
|
|
+
|
|
|
+ print('Using bundled LZ4')
|
|
|
+ sources = multi_join(lz4_sources, lz4_bundled_path)
|
|
|
+ include_dirs = multi_join(lz4_includes, lz4_bundled_path)
|
|
|
+ define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')]
|
|
|
+ return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)
|