From a600d4527021ad6db84a3271647801cfcbc7c69b Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Fri, 1 Sep 2023 23:44:46 -0400 Subject: [PATCH 1/2] link libwallycore into Python extension rather than recompiling code libwallycore.la is linked into the Python native extension library. Previously this wasn't really being done at all; rather, all of the libwally-core code was being recompiled into some "combined" objects that would then be linked into the Python extension. This was a needless duplication of work since the compiled objects already exist in libwallycore.a and libsecp256k1.a. Simply link those libraries into the extension. Since Windows does not use libtool, continue to compile the "combined" objects on Windows until a cleaner solution can be implemented. --- setup.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index fd073ef8e..34d66f1be 100644 --- a/setup.py +++ b/setup.py @@ -67,12 +67,11 @@ def call(args): include_dirs=[ './', './src', - './src/ccan', './src/secp256k1/include', ] if is_windows: shutil.copyfile('./src/amalgamation/windows_config/libsecp256k1-config.h', 'src/secp256k1/src/libsecp256k1-config.h') - include_dirs = ['./src/amalgamation/windows_config'] + include_dirs + include_dirs = ['./src/amalgamation/windows_config'] + include_dirs + ['./src/ccan'] extra_compile_args = ['-flax-vector-conversions'] @@ -80,12 +79,16 @@ def call(args): '_wallycore', define_macros=define_macros, include_dirs=include_dirs, + library_dirs=[] if is_windows else ['src/.libs', 'src/secp256k1/.libs'], + libraries=[] if is_windows else ['wallycore', 'secp256k1'], extra_compile_args=extra_compile_args, sources=[ - 'src/swig_python/swig_wrap.c' if is_windows else 'src/swig_python/swig_python_wrap.c', + 'src/swig_python/swig_wrap.c', 'src/amalgamation/combined.c', 'src/amalgamation/combined_ccan.c', 'src/amalgamation/combined_ccan2.c', + ] if is_windows else [ + 'src/swig_python/swig_python_wrap.c', ], ) From c35acde6bc394c1dfcdbd9c427e28027f381bee8 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 2 Sep 2023 00:04:00 -0400 Subject: [PATCH 2/2] setup.py: support optionally building libwally-core as a shared library Iff the environment contains WALLY_ABI_PY_WHEEL_USE_DSO=1, then: * setup.py will configure and build libwally-core as a shared library; * the Python native extension library will not contain any libwally-core or libsecp256k1 code; and * the dynamic linker will need to find and load libwallycore.so.1 whenever the Python native extension is loaded. --- setup.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 34d66f1be..7dd21bbec 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,13 @@ import copy, os, platform, shutil import distutils.sysconfig -CONFIGURE_ARGS = ['--disable-shared', '--enable-static', '--with-pic', +build_shared = os.environ.get('WALLY_ABI_PY_WHEEL_USE_DSO', '').lower() not in ['', '0', 'false', 'no', 'n', 'off'] +if build_shared: + CONFIGURE_ARGS = ['--enable-shared', '--disable-static'] +else: + CONFIGURE_ARGS = ['--disable-shared', '--enable-static', '--with-pic'] + +CONFIGURE_ARGS += [ '--enable-swig-python', '--enable-python-manylinux', '--disable-swig-java', '--disable-tests', '--disable-dependency-tracking'] @@ -79,8 +85,10 @@ def call(args): '_wallycore', define_macros=define_macros, include_dirs=include_dirs, - library_dirs=[] if is_windows else ['src/.libs', 'src/secp256k1/.libs'], - libraries=[] if is_windows else ['wallycore', 'secp256k1'], + library_dirs=[] if is_windows else + ['src/.libs'] + ([] if build_shared else ['src/secp256k1/.libs']), + libraries=[] if is_windows else + ['wallycore'] + ([] if build_shared else ['secp256k1']), extra_compile_args=extra_compile_args, sources=[ 'src/swig_python/swig_wrap.c',