Fix building on the usual ancient Linux distro suspects
Detect if librsync is new enough to have rs_sig_args
This commit is contained in:
parent
067502bd66
commit
348e632dd6
@ -24,11 +24,13 @@ begin_create_signature(PyObject *self UNUSED, PyObject *args) {
|
|||||||
if (!PyArg_ParseTuple(args, "|Ll", &file_size, &sl)) return NULL;
|
if (!PyArg_ParseTuple(args, "|Ll", &file_size, &sl)) return NULL;
|
||||||
rs_magic_number magic_number = 0;
|
rs_magic_number magic_number = 0;
|
||||||
size_t block_len = 0, strong_len = sl;
|
size_t block_len = 0, strong_len = sl;
|
||||||
|
#ifdef KITTY_HAS_RS_SIG_ARGS
|
||||||
rs_result res = rs_sig_args(file_size, &magic_number, &block_len, &strong_len);
|
rs_result res = rs_sig_args(file_size, &magic_number, &block_len, &strong_len);
|
||||||
if (res != RS_DONE) {
|
if (res != RS_DONE) {
|
||||||
PyErr_SetString(PyExc_ValueError, rs_strerror(res));
|
PyErr_SetString(PyExc_ValueError, rs_strerror(res));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
rs_job_t *job = rs_sig_begin(block_len, strong_len, magic_number);
|
rs_job_t *job = rs_sig_begin(block_len, strong_len, magic_number);
|
||||||
if (!job) return PyErr_NoMemory();
|
if (!job) return PyErr_NoMemory();
|
||||||
PyObject *ans = PyCapsule_New(job, JOB_CAPSULE, free_job_capsule);
|
PyObject *ans = PyCapsule_New(job, JOB_CAPSULE, free_job_capsule);
|
||||||
|
|||||||
21
setup.py
21
setup.py
@ -228,11 +228,11 @@ def get_sanitize_args(cc: str, ccver: Tuple[int, int]) -> List[str]:
|
|||||||
return sanitize_args
|
return sanitize_args
|
||||||
|
|
||||||
|
|
||||||
def test_compile(cc: str, *cflags: str, src: Optional[str] = None, lang: str = 'c') -> bool:
|
def test_compile(cc: str, *cflags: str, src: Optional[str] = None, lang: str = 'c', link_also: bool = True, show_stderr: bool = False) -> bool:
|
||||||
src = src or 'int main(void) { return 0; }'
|
src = src or 'int main(void) { return 0; }'
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[cc] + list(cflags) + ['-x', lang, '-o', os.devnull, '-'],
|
[cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', os.devnull, '-'],
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE,
|
stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=None if show_stderr else subprocess.DEVNULL
|
||||||
)
|
)
|
||||||
stdin = p.stdin
|
stdin = p.stdin
|
||||||
assert stdin is not None
|
assert stdin is not None
|
||||||
@ -263,6 +263,20 @@ def set_arches(flags: List[str], arches: Iterable[str] = ('x86_64', 'arm64')) ->
|
|||||||
flags.extend(('-arch', arch))
|
flags.extend(('-arch', arch))
|
||||||
|
|
||||||
|
|
||||||
|
def detect_librsync(cc: str, cflags: List[str]) -> None:
|
||||||
|
if not test_compile(cc, '-lrsync', show_stderr=True, src='#include <librsync.h>\nint main(void) { rs_strerror(0); return 0; }'):
|
||||||
|
raise SystemExit('The librsync library is required')
|
||||||
|
if test_compile(cc, link_also=False, src='''
|
||||||
|
#include <librsync.h>
|
||||||
|
int main(void) {
|
||||||
|
rs_magic_number magic_number = 0;
|
||||||
|
size_t block_len = 0, strong_len = 0;
|
||||||
|
rs_sig_args(1024, &magic_number, &block_len, &strong_len);
|
||||||
|
return 0;
|
||||||
|
}'''):
|
||||||
|
cflags.append('-DKITTY_HAS_RS_SIG_ARGS')
|
||||||
|
|
||||||
|
|
||||||
def init_env(
|
def init_env(
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
sanitize: bool = False,
|
sanitize: bool = False,
|
||||||
@ -316,6 +330,7 @@ def init_env(
|
|||||||
cflags = shlex.split(cflags_) + shlex.split(
|
cflags = shlex.split(cflags_) + shlex.split(
|
||||||
sysconfig.get_config_var('CCSHARED') or ''
|
sysconfig.get_config_var('CCSHARED') or ''
|
||||||
)
|
)
|
||||||
|
detect_librsync(cc, cflags)
|
||||||
ldflags_ = os.environ.get(
|
ldflags_ = os.environ.get(
|
||||||
'OVERRIDE_LDFLAGS',
|
'OVERRIDE_LDFLAGS',
|
||||||
'-Wall ' + ' '.join(sanitize_args) + ('' if debug else ' -O3')
|
'-Wall ' + ' '.join(sanitize_args) + ('' if debug else ' -O3')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user