diff --git a/setup.py b/setup.py index f8a73d032..c8c106851 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,7 @@ except ImportError: cythonize = None -import setup_lz4 -import setup_zstd -import setup_b2 +import setup_compress import setup_crypto import setup_docs @@ -161,13 +159,13 @@ def members_appended(*ds): crypto_ext_kwargs = members_appended( dict(sources=[crypto_ll_source, crypto_helpers]), setup_crypto.crypto_ext_kwargs(pc), - setup_b2.b2_ext_kwargs(pc, prefer_system_libb2), + setup_crypto.b2_ext_kwargs(pc, prefer_system_libb2), ) compress_ext_kwargs = members_appended( dict(sources=[compress_source]), - setup_lz4.lz4_ext_kwargs(pc, prefer_system_liblz4), - setup_zstd.zstd_ext_kwargs(pc, prefer_system_libzstd, multithreaded=False, legacy=False), + setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4), + setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, multithreaded=False, legacy=False), ) ext_modules += [ diff --git a/setup_b2.py b/setup_b2.py deleted file mode 100644 index 309cdb101..000000000 --- a/setup_b2.py +++ /dev/null @@ -1,41 +0,0 @@ -# Support code for building a C extension with blake2 - -import os - -# b2 files, structure as seen in BLAKE2 (reference implementation) project repository: - -# bundled_path: relative (to this file) path to the bundled library source code files -bundled_path = 'src/borg/algorithms/blake2' - -b2_sources = [ - 'ref/blake2b-ref.c', -] - -b2_includes = [ - 'ref', -] - - -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 b2_ext_kwargs(pc, prefer_system): - if prefer_system: - system_prefix = os.environ.get('BORG_LIBB2_PREFIX') - if system_prefix: - print('Detected and preferring libb2 [via BORG_LIBB2_PREFIX]') - return dict(include_dirs=[os.path.join(system_prefix, 'include')], - library_dirs=[os.path.join(system_prefix, 'lib')], - libraries=['b2']) - - if pc and pc.installed('libb2', '>= 0.98.1'): - print('Detected and preferring libb2 [via pkg-config]') - return pc.parse('libb2') - - print('Using bundled BLAKE2') - sources = multi_join(b2_sources, bundled_path) - include_dirs = multi_join(b2_includes, bundled_path) - define_macros = [('BORG_USE_BUNDLED_B2', 'YES')] - return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros) diff --git a/setup_zstd.py b/setup_compress.py similarity index 64% rename from setup_zstd.py rename to setup_compress.py index 050c72f79..b5c8195ce 100644 --- a/setup_zstd.py +++ b/setup_compress.py @@ -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 @@ ] -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) diff --git a/setup_crypto.py b/setup_crypto.py index b0971ff62..600310b18 100644 --- a/setup_crypto.py +++ b/setup_crypto.py @@ -1,8 +1,13 @@ -# Support code for building a C extension with crypto from OpenSSL / LibreSSL +# Support code for building a C extension with crypto 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] + + def crypto_ext_kwargs(pc): system_prefix = os.environ.get('BORG_OPENSSL_PREFIX') if system_prefix: @@ -16,3 +21,37 @@ def crypto_ext_kwargs(pc): return pc.parse('libcrypto') raise Exception('Could not find OpenSSL lib/headers, please set BORG_OPENSSL_PREFIX') + + +# b2 files, structure as seen in BLAKE2 (reference implementation) project repository: + +# path relative (to this file) to the bundled library source code files +b2_bundled_path = 'src/borg/algorithms/blake2' + +b2_sources = [ + 'ref/blake2b-ref.c', +] + +b2_includes = [ + 'ref', +] + + +def b2_ext_kwargs(pc, prefer_system): + if prefer_system: + system_prefix = os.environ.get('BORG_LIBB2_PREFIX') + if system_prefix: + print('Detected and preferring libb2 [via BORG_LIBB2_PREFIX]') + return dict(include_dirs=[os.path.join(system_prefix, 'include')], + library_dirs=[os.path.join(system_prefix, 'lib')], + libraries=['b2']) + + if pc and pc.installed('libb2', '>= 0.98.1'): + print('Detected and preferring libb2 [via pkg-config]') + return pc.parse('libb2') + + print('Using bundled BLAKE2') + sources = multi_join(b2_sources, b2_bundled_path) + include_dirs = multi_join(b2_includes, b2_bundled_path) + define_macros = [('BORG_USE_BUNDLED_B2', 'YES')] + return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros) diff --git a/setup_lz4.py b/setup_lz4.py deleted file mode 100644 index b8b5f7dfb..000000000 --- a/setup_lz4.py +++ /dev/null @@ -1,41 +0,0 @@ -# Support code for building a C extension with lz4 files - -import os - -# lz4 files, structure as seen in lz4 project repository: - -# bundled_path: relative (to this file) path to the bundled library source code files -bundled_path = 'src/borg/algorithms/lz4' - -lz4_sources = [ - 'lib/lz4.c', -] - -lz4_includes = [ - 'lib', -] - - -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 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, bundled_path) - include_dirs = multi_join(lz4_includes, bundled_path) - define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')] - return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)