Skip to content

Commit 187d602

Browse files
committed
don't embed Python code into libwallycore.so
Embedding SWIG Python code into libwallycore.so ties the library to a specific version of Python, thereby precluding concurrent installation of the wallycore Python module for multiple implementations of Python on the same system if the Python modules are linked with a system-wide libwallycore.so. On Gentoo at least, linking libwallycore.so with libpython3.14.so and then attempting to use the wallycore Python module from Python 3.11, 3.12, or 3.13 causes an immediate segfault. Rather than injecting Python-specific glue into libwallycore.so, we can and should keep it contained within the Python native extension library that we build for each Python implementation. The Python wheel actually already compiles swig_python_wrap.c and links it into the native extension library, so linking it into libwallycore.so as well is redundant and harmful. * Remove libswig_python.la from libwallycore_la_LIBADD, and expunge its existence from Makefile.am entirely since it's now unused. * The Python wheel build for each Python implementation compiles swig_python_wrap.c against the headers for that particular Python implementation, ensuring that the resulting native extension library matches the ABI of the Python implementation for which it is installed. This may be a different Python implementation than the one found by Autoconf, the only relevance of which now is in finding the interpreter with which to run the tests. * Since we no longer link libwallycore.so with libpython*.so, there should no longer be any manylinux compatibility issues, so drop the --enable-python-manylinux Autoconf option and the PYTHON_MANYLINUX Automake conditional. This also means that the test programs no longer need to link with $(PYTHON_LIBS) since libwallycore.la now never has any dependence on Python (implicit or explicit). * Note that the Python native extension libraries do not explicitly link with libpython*.so either. This is correct, as the dynamic linker resolves their undefined Py* symbols when it loads them into the Python interpreter. * Remove check-libwallycore and check-swig-java prerequisites from the check-swig-python target, as these are three orthogonal test suites with no interdependencies. After applying these changes, the Gentoo ebuild for libwally-core 1.5.4 now successfully runs the SWIG Python tests on all currently supported versions of Python (3.12 through 3.14), all using the same libwallycore.so.6.
1 parent c559183 commit 187d602

4 files changed

Lines changed: 19 additions & 61 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ $ brew install swig
7373
- `--enable-swig-python`. Enable the [SWIG](http://www.swig.org/) Python
7474
interface. The resulting shared library can be imported from Python using
7575
the generated interface file `src/swig_python/wallycore/__init__.py`. (default: no).
76-
- `--enable-python-manylinux`. Enable [manylinux](https://github.com/pypa/manylinux)
77-
support for building [PyPI](https://pypi.org/) compatible python wheels. Using
78-
the resulting library in non-python programs requires linking with `libpython.so`.
7976
- `--enable-swig-java`. Enable the [SWIG](http://www.swig.org/) Java (JNI)
8077
interface. After building, see `src/swig_java/src/com/blockstream/libwally/Wally.java`
8178
for the Java interface definition (default: no).

configure.ac

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,10 @@ AC_SUBST([libsecp256k1_LIBS])
338338
#
339339
# Python facilities
340340
#
341-
AC_ARG_ENABLE(python-manylinux,
342-
AS_HELP_STRING([--enable-python-manylinux],[enable manylinux Python compatibility (default: no)]),
343-
[python_manylinux=$enableval], [python_manylinux=no])
344-
AM_CONDITIONAL([PYTHON_MANYLINUX], [test "x$python_manylinux" = "xyes"])
345-
341+
dnl We set the 'optional' flag here because manylinux cibuildwheel containers
342+
dnl don't include libpython*.so, and thus AX_PYTHON_DEVEL fails its final sanity
343+
dnl check. We actually don't link against libpython*.so anyway, so all we care
344+
dnl about is that we get a good value of $PYTHON_CPPFLAGS to pass to SWIG.
346345
AX_PYTHON_DEVEL([>= '3.9.0'], [true])
347346
AM_CONDITIONAL([HAVE_PYTHON], [test "x$ax_python_devel_found" = "xyes"])
348347

@@ -365,10 +364,10 @@ AC_ARG_ENABLE(swig-python,
365364
[swig_python=$enableval], [swig_python=no])
366365
AM_CONDITIONAL([USE_SWIG_PYTHON], [test "x$swig_python" = "xyes"])
367366

368-
AM_CONDITIONAL([RUN_PYTHON_TESTS], [test "$PYTHON" != "" -a "x$pythonexists" = "xyes"])
367+
AM_CONDITIONAL([RUN_PYTHON_TESTS], [test -n "$PYTHON"])
369368

370369
if test "x$swig_python" = "xyes"; then
371-
if test "x$pythonexists" != "xyes"; then
370+
if test -z "$PYTHON_CPPFLAGS"; then
372371
AC_MSG_FAILURE([ERROR: No usable Python was found for swig-python])
373372
fi
374373
if test "x$elements_abi" = "xno"; then

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _call(args, cwd=ABS_PATH):
6262
_call(['git', 'submodule', 'update', '--init', '--recursive'])
6363

6464
CONFIGURE_ARGS = [
65-
'--with-pic', '--enable-swig-python', '--enable-python-manylinux',
65+
'--with-pic', '--enable-swig-python',
6666
'--disable-swig-java', '--disable-tests', '--disable-dependency-tracking'
6767
]
6868

src/Makefile.am

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@ TOOLS_EXTRA_ARGS :=
3838
endif
3939

4040
if USE_SWIG_PYTHON
41-
noinst_LTLIBRARIES += libswig_python.la
42-
libswig_python_la_SOURCES = swig_python/swig_python_wrap.c
43-
44-
libswig_python_la_CFLAGS = -I$(top_srcdir) $(libsecp256k1_CFLAGS) $(AM_CFLAGS) $(SWIG_PYTHON_CPPFLAGS) $(SWIG_WARN_CFLAGS) $(NOALIAS_CFLAGS)
45-
if PYTHON_MANYLINUX
46-
else
47-
libswig_python_la_LIBADD = $(PYTHON_LIBS)
48-
endif # PYTHON_MANYLINUX
49-
41+
BUILT_SOURCES = swig_python/swig_python_wrap.c
5042
# Append our extra wrapper code to the package
5143
swig_python/swig_python_wrap.c : swig_python/swig.i swig_python/python_extra.py_in
5244
$(AM_V_at)$(SWIG) $(SWIG_PYTHON_OPT) $(SWIG_GEN_FLAGS) -outdir swig_python -o $@ $< && \
@@ -60,20 +52,6 @@ clean-local: clean-swig-python
6052
endif # USE_SWIG_PYTHON
6153

6254
if RUN_PYTHON_TESTS
63-
# Python requires the shared library to be named _wallycore.so
64-
# for 'import' to work.
65-
if IS_OSX
66-
platform_dso_ext = dylib
67-
else
68-
if IS_MINGW
69-
platform_dso_ext = dll
70-
else
71-
platform_dso_ext = so
72-
endif # IS_MINGW
73-
endif # IS_OSX
74-
.libs/_wallycore.so: .libs/libwallycore.$(platform_dso_ext)
75-
$(AM_V_at)ln -sfn libwallycore.$(platform_dso_ext) $@
76-
PYTHON_TEST_DEPS = .libs/_wallycore.so
7755
PYTHON_TEST = PYTHONDONTWRITEBYTECODE=1 $(PYTHON)
7856
endif
7957

@@ -225,82 +203,66 @@ endif
225203

226204
TESTS =
227205
noinst_PROGRAMS =
206+
228207
if RUN_TESTS
229208
TESTS += test_bech32
230209
noinst_PROGRAMS += test_bech32
231210
test_bech32_SOURCES = ctest/test_bech32.c
232211
test_bech32_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS)
233212
test_bech32_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
234-
if PYTHON_MANYLINUX
235-
test_bech32_LDADD += $(PYTHON_LIBS)
236-
endif
213+
237214
TESTS += test_psbt
238215
noinst_PROGRAMS += test_psbt
239216
test_psbt_SOURCES = ctest/test_psbt.c ccan/ccan/str/hex/hex.c
240217
test_psbt_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS) -I$(srcdir)/ccan
241218
test_psbt_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
242-
if PYTHON_MANYLINUX
243-
test_psbt_LDADD += $(PYTHON_LIBS)
244-
endif
219+
245220
TESTS += test_psbt_limits
246221
noinst_PROGRAMS += test_psbt_limits
247222
test_psbt_limits_SOURCES = ctest/test_psbt_limits.c ccan/ccan/str/hex/hex.c
248223
test_psbt_limits_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS) -I$(srcdir)/ccan
249224
test_psbt_limits_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
250-
if PYTHON_MANYLINUX
251-
test_psbt_limits_LDADD += $(PYTHON_LIBS)
252-
endif
225+
253226
if USE_PTHREAD
254227
TESTS += test_clear
255228
noinst_PROGRAMS += test_clear
256229
test_clear_SOURCES = ctest/test_clear.c
257230
test_clear_CFLAGS = -I$(top_srcdir)/include $(PTHREAD_CFLAGS) $(AM_CFLAGS) $(NOOPT_CFLAGS) $(NOBUILTIN_CFLAGS)
258231
test_clear_LIBS = $(PTHREAD_LIBS)
259232
test_clear_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
260-
if PYTHON_MANYLINUX
261-
test_clear_LDADD += $(PYTHON_LIBS)
262-
endif
263233
endif
234+
264235
TESTS += test_coinselection
265236
noinst_PROGRAMS += test_coinselection
266237
test_coinselection_SOURCES = ctest/test_coinselection.c
267238
test_coinselection_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS)
268239
test_coinselection_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
269-
if PYTHON_MANYLINUX
270-
test_coinselection_LDADD += $(PYTHON_LIBS)
271-
endif
240+
272241
TESTS += test_tx
273242
noinst_PROGRAMS += test_tx
274243
test_tx_SOURCES = ctest/test_tx.c
275244
test_tx_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS)
276245
test_tx_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
277-
if PYTHON_MANYLINUX
278-
test_tx_LDADD += $(PYTHON_LIBS)
279-
endif
246+
280247
TESTS += test_descriptor
281248
noinst_PROGRAMS += test_descriptor
282249
test_descriptor_SOURCES = ctest/test_descriptor.c
283250
test_descriptor_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS)
284251
test_descriptor_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
285-
if PYTHON_MANYLINUX
286-
test_descriptor_LDADD += $(PYTHON_LIBS)
287-
endif
252+
288253
if BUILD_ELEMENTS
289254
TESTS += test_elements_tx
290255
noinst_PROGRAMS += test_elements_tx
291256
test_elements_tx_SOURCES = ctest/test_elements_tx.c
292257
test_elements_tx_CFLAGS = -I$(top_srcdir)/include $(AM_CFLAGS)
293258
test_elements_tx_LDADD = $(lib_LTLIBRARIES) @CTEST_EXTRA_STATIC@
294-
if PYTHON_MANYLINUX
295-
test_elements_tx_LDADD += $(PYTHON_LIBS)
296-
endif
297259
endif
298260

299261
check-local: check-libwallycore check-swig-java check-swig-python
300262
$(AM_V_at)! grep '^int ' $(top_srcdir)/include/*.h # Missing WALLY_CORE_API
301263

302264
if RUN_JAVA_TESTS
303-
check-swig-java: $(SWIG_JAVA_TEST_DEPS) .libs/libwallycore.$(platform_dso_ext)
265+
check-swig-java: $(SWIG_JAVA_TEST_DEPS) libwallycore.la
304266
$(AM_V_at)! grep 'native int wally_' $(sjs)/$(cblw)/Wally.java # Unwrapped Java calls
305267
$(AM_V_at)! grep 'native Object wally_' $(sjs)/$(cblw)/Wally.java # Unwrapped Java calls
306268
if BUILD_ELEMENTS
@@ -319,7 +281,7 @@ endif # RUN_JAVA_TESTS
319281

320282
if SHARED_BUILD_ENABLED
321283
if RUN_PYTHON_TESTS
322-
check-libwallycore: $(PYTHON_TEST_DEPS)
284+
check-libwallycore:
323285
$(AM_V_at)$(PYTHON_TEST) test/test_address.py
324286
$(AM_V_at)$(PYTHON_TEST) test/test_aes.py
325287
$(AM_V_at)$(PYTHON_TEST) test/test_anti_exfil.py
@@ -356,7 +318,7 @@ if BUILD_ELEMENTS
356318
endif
357319

358320
if USE_SWIG_PYTHON
359-
check-swig-python: check-libwallycore check-swig-java
321+
check-swig-python:
360322
$(AM_V_at)rm -rf $(top_builddir)/venv
361323
$(AM_V_at)$(PYTHON) -m virtualenv $(top_builddir)/venv
362324
$(AM_V_at)$(top_builddir)/venv/bin/python -m pip install $(top_srcdir)

0 commit comments

Comments
 (0)