diff --git a/kittens/transfer/rsync.c b/kittens/transfer/rsync.c index 550f1baff..9cfd9bd47 100644 --- a/kittens/transfer/rsync.c +++ b/kittens/transfer/rsync.c @@ -24,11 +24,13 @@ begin_create_signature(PyObject *self UNUSED, PyObject *args) { if (!PyArg_ParseTuple(args, "|Ll", &file_size, &sl)) return NULL; rs_magic_number magic_number = 0; 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); if (res != RS_DONE) { PyErr_SetString(PyExc_ValueError, rs_strerror(res)); return NULL; } +#endif rs_job_t *job = rs_sig_begin(block_len, strong_len, magic_number); if (!job) return PyErr_NoMemory(); PyObject *ans = PyCapsule_New(job, JOB_CAPSULE, free_job_capsule); diff --git a/setup.py b/setup.py index 31db67069..df6f64a1a 100755 --- a/setup.py +++ b/setup.py @@ -228,11 +228,11 @@ def get_sanitize_args(cc: str, ccver: Tuple[int, int]) -> List[str]: 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; }' p = subprocess.Popen( - [cc] + list(cflags) + ['-x', lang, '-o', os.devnull, '-'], - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE, + [cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', os.devnull, '-'], + stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=None if show_stderr else subprocess.DEVNULL ) stdin = p.stdin 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)) +def detect_librsync(cc: str, cflags: List[str]) -> None: + if not test_compile(cc, '-lrsync', show_stderr=True, src='#include \nint main(void) { rs_strerror(0); return 0; }'): + raise SystemExit('The librsync library is required') + if test_compile(cc, link_also=False, src=''' +#include +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( debug: bool = False, sanitize: bool = False, @@ -316,6 +330,7 @@ def init_env( cflags = shlex.split(cflags_) + shlex.split( sysconfig.get_config_var('CCSHARED') or '' ) + detect_librsync(cc, cflags) ldflags_ = os.environ.get( 'OVERRIDE_LDFLAGS', '-Wall ' + ' '.join(sanitize_args) + ('' if debug else ' -O3')