Skip to content

Commit

Permalink
setup.py: support optionally building libwally-core as a shared library
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitslack committed Sep 2, 2023
1 parent aeef3af commit 5dc21e0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
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']
'--disable-swig-java', '--disable-tests', '--disable-dependency-tracking',
]

distutils_env = distutils.sysconfig.get_config_vars()
configure_env = copy.deepcopy(os.environ)
Expand Down Expand Up @@ -82,8 +89,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',
Expand Down

0 comments on commit 5dc21e0

Please sign in to comment.