Skip to content

Commit 96d93dc

Browse files
do not support bundled 3rd party code any more, fixes borgbackup#6316
1 parent 159bd06 commit 96d93dc

File tree

9 files changed

+53
-210
lines changed

9 files changed

+53
-210
lines changed

docs/installation.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,18 @@ Dependencies
159159
To install Borg from a source package (including pip), you have to install the
160160
following dependencies first:
161161

162-
* `Python 3`_ >= 3.8.0, plus development headers.
163-
* OpenSSL_ >= 1.1.1, plus development headers.
164-
* libacl_ (which depends on libattr_), both plus development headers.
165-
* We have bundled code of the following packages, but borg by default (see
166-
setup.py if you want to change that) prefers a shared library if it can
167-
be found on the system (lib + dev headers) at build time:
162+
* `Python 3`_ >= 3.8.0 (interpreter plus development headers)
163+
* Libraries (library plus development headers):
168164

165+
- OpenSSL_ >= 1.1.1
166+
- libacl_ (which depends on libattr_)
169167
- liblz4_ >= 1.7.0 (r129)
170168
- libzstd_ >= 1.3.0
171169
- libxxhash >= 0.8.1 (0.8.0 might work also)
172170
* pkg-config (cli tool) and pkgconfig python package (borg uses these to
173171
discover header and library location - if it can't import pkgconfig and
174172
is not pointed to header/library locations via env vars [see setup.py],
175-
it will fall back to using the bundled code, see above).
173+
it will raise a fatal error).
176174
**These must be present before invoking setup.py!**
177175
* some other Python dependencies, pip will automatically install them for you.
178176
* optionally, if you wish to mount an archive as a FUSE filesystem, you need

setup.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,25 @@
2626

2727
is_win32 = sys.platform.startswith('win32')
2828

29-
# How the build process finds the system libs / uses the bundled code:
29+
# How the build process finds the system libs:
3030
#
31-
# 1. it will try to use (system) libs (see 1.1. and 1.2.),
32-
# except if you use these env vars to force using the bundled code:
33-
# BORG_USE_BUNDLED_XXX undefined --> try using system lib
34-
# BORG_USE_BUNDLED_XXX=YES --> use the bundled code
35-
# Note: do not use =NO, that is not supported!
36-
# 1.1. if BORG_LIBXXX_PREFIX is set, it will use headers and libs from there.
37-
# 1.2. if not and pkg-config can locate the lib, the lib located by
38-
# pkg-config will be used. We use the pkg-config tool via the pkgconfig
39-
# python package, which must be installed before invoking setup.py.
40-
# if pkgconfig is not installed, this step is skipped.
41-
# 2. if no system lib could be located via 1.1. or 1.2., it will fall back
42-
# to using the bundled code.
43-
44-
# OpenSSL is required as a (system) lib in any case as we do not bundle it.
45-
# Thus, only step 1.1. and 1.2. apply to openssl (but not 1. and 2.).
46-
# needed: openssl >=1.0.2 or >=1.1.0 (or compatible)
31+
# 1. if BORG_LIBXXX_PREFIX is set, it will use headers and libs from there.
32+
# 2. if not and pkg-config can locate the lib, the lib located by
33+
# pkg-config will be used. We use the pkg-config tool via the pkgconfig
34+
# python package, which must be installed before invoking setup.py.
35+
# if pkgconfig is not installed, this step is skipped.
36+
# 3. otherwise raise a fatal error.
37+
38+
# needed: >=1.1.1 (or compatible)
4739
system_prefix_openssl = os.environ.get('BORG_OPENSSL_PREFIX')
4840

4941
# needed: lz4 (>= 1.7.0 / r129)
50-
prefer_system_liblz4 = not bool(os.environ.get('BORG_USE_BUNDLED_LZ4'))
5142
system_prefix_liblz4 = os.environ.get('BORG_LIBLZ4_PREFIX')
5243

5344
# needed: zstd (>= 1.3.0)
54-
prefer_system_libzstd = not bool(os.environ.get('BORG_USE_BUNDLED_ZSTD'))
5545
system_prefix_libzstd = os.environ.get('BORG_LIBZSTD_PREFIX')
5646

57-
prefer_system_libxxhash = not bool(os.environ.get('BORG_USE_BUNDLED_XXHASH'))
47+
# needed: xxhash (>= 0.8.1)
5848
system_prefix_libxxhash = os.environ.get('BORG_LIBXXHASH_PREFIX')
5949

6050
# Number of threads to use for cythonize, not used on windows
@@ -187,14 +177,13 @@ def members_appended(*ds):
187177

188178
compress_ext_kwargs = members_appended(
189179
dict(sources=[compress_source]),
190-
setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4, system_prefix_liblz4),
191-
setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, system_prefix_libzstd,
192-
multithreaded=False, legacy=False),
180+
setup_compress.lz4_ext_kwargs(pc, system_prefix_liblz4),
181+
setup_compress.zstd_ext_kwargs(pc, system_prefix_libzstd),
193182
)
194183

195184
checksums_ext_kwargs = members_appended(
196185
dict(sources=[checksums_source]),
197-
setup_checksums.xxhash_ext_kwargs(pc, prefer_system_libxxhash, system_prefix_libxxhash),
186+
setup_checksums.xxhash_ext_kwargs(pc, system_prefix_libxxhash),
198187
)
199188

200189
ext_modules += [

setup_checksums.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,15 @@
33
import os
44

55

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]
9-
10-
11-
# xxhash files, structure as seen in xxhash project repository:
12-
13-
# path relative (to this file) to the bundled library source code files
14-
xxhash_bundled_path = 'src/borg/algorithms/xxh64'
15-
16-
xxhash_sources = [
17-
'xxhash.c',
18-
]
19-
20-
xxhash_includes = [
21-
'',
22-
]
23-
24-
25-
def xxhash_ext_kwargs(pc, prefer_system, system_prefix):
26-
if prefer_system:
27-
if system_prefix:
28-
print('Detected and preferring libxxhash [via BORG_LIBXXHASH_PREFIX]')
29-
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
30-
library_dirs=[os.path.join(system_prefix, 'lib')],
31-
libraries=['xxhash'])
32-
33-
if pc and pc.installed('libxxhash', '>= 0.7.3'):
34-
print('Detected and preferring libxxhash [via pkg-config]')
35-
return pc.parse('libxxhash')
36-
37-
print('Using bundled xxhash')
38-
sources = multi_join(xxhash_sources, xxhash_bundled_path)
39-
include_dirs = multi_join(xxhash_includes, xxhash_bundled_path)
40-
define_macros = [('BORG_USE_BUNDLED_XXHASH', 'YES')]
41-
return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)
42-
6+
def xxhash_ext_kwargs(pc, system_prefix):
7+
if system_prefix:
8+
print('Detected and preferring libxxhash [via BORG_LIBXXHASH_PREFIX]')
9+
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
10+
library_dirs=[os.path.join(system_prefix, 'lib')],
11+
libraries=['xxhash'])
12+
13+
if pc and pc.installed('libxxhash', '>= 0.7.3'):
14+
print('Detected and preferring libxxhash [via pkg-config]')
15+
return pc.parse('libxxhash')
16+
17+
raise Exception('Could not find xxhash lib/headers, please set BORG_LIBXXHASH_PREFIX')

setup_compress.py

Lines changed: 20 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3,133 +3,29 @@
33
import os
44

55

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'])
912

13+
if pc and pc.installed('libzstd', '>= 1.3.0'):
14+
print('Detected and preferring libzstd [via pkg-config]')
15+
return pc.parse('libzstd')
1016

11-
# zstd files, structure as seen in zstd project repository:
17+
raise Exception('Could not find zstd lib/headers, please set BORG_LIBZSTD_PREFIX')
1218

13-
# path relative (to this file) to the bundled library source code files
14-
zstd_bundled_path = 'src/borg/algorithms/zstd'
1519

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'])
4726

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')
6030

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')

src/borg/algorithms/checksums.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cdef extern from "crc32_dispatch.c":
1212
int _have_clmul "have_clmul"()
1313

1414

15-
cdef extern from "xxhash-libselect.h":
15+
cdef extern from "xxhash.h":
1616
ctypedef struct XXH64_canonical_t:
1717
char digest[8]
1818

src/borg/algorithms/lz4-libselect.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/borg/algorithms/xxhash-libselect.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/borg/algorithms/zstd-libselect.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/borg/compress.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ from .helpers import Buffer, DecompressionError
3030

3131
API_VERSION = '1.2_02'
3232

33-
cdef extern from "algorithms/lz4-libselect.h":
33+
cdef extern from "lz4.h":
3434
int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize) nogil
3535
int LZ4_decompress_safe(const char* source, char* dest, int inputSize, int maxOutputSize) nogil
3636
int LZ4_compressBound(int inputSize) nogil
3737

3838

39-
cdef extern from "algorithms/zstd-libselect.h":
39+
cdef extern from "zstd.h":
4040
size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel) nogil
4141
size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t compressedSize) nogil
4242
size_t ZSTD_compressBound(size_t srcSize) nogil

0 commit comments

Comments
 (0)