From e377be183febe8466295987738d53c5e207f6590 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 2 Sep 2023 00:04:00 -0400 Subject: [PATCH] setup.py: support optionally building libwally-core as a shared library Iff the environment contains WALLY_BUILD_SHARED=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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index fdccfb8ce..2f3d03682 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_BUILD_SHARED', '').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'] @@ -81,8 +87,8 @@ def call(args): '_wallycore', define_macros=define_macros, include_dirs=include_dirs, - library_dirs=['src/.libs', 'src/secp256k1/.libs'], - libraries=['wallycore', 'secp256k1'], + library_dirs=['src/.libs'] + ([] if build_shared else ['src/secp256k1/.libs']), + libraries=['wallycore'] + ([] if build_shared else ['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',