-
Notifications
You must be signed in to change notification settings - Fork 146
don't embed Python code into libwallycore.so
#501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Hi @whitslack the CI does not like these changes, that will need to be fixed. The CI build results must be uploadable to PyPI as complete wheels, i.e. if a new venv is created then You may need to gate this change behind a configure flag. |
So, this breaks In #505 I've fixed python, but you will need to fix java to get this merged. I'm releasing 1.5.1 without it as I need python 13 wheels in pypi. |
I do see the issue you raised about I'll see if I can rebase this PR atop your virtualenv and get it working. At the end of the day, though, I might just give up and do things the Gentoo way on Gentoo and not worry about everyone else having a clean |
Running the SWIG Python tests requires that Python is able to find the wallycore native extension. To save users from needing to build it manually and add its location to `PYTHONPATH` themselves, we add a target dependency in `src/Makefile.am` to trigger the Python build before we'll need the native extension for running the SWIG Python tests. It's unfortunate that we can't merely call `setup.py build` and then ask setuptools where it stashed its staging copy of the module, as there seems to be no accessible query interface for that information. So instead we have to tell `setup.py` to install the module to a location that we do know, and then we can pass that location in `PYTHONPATH` when we run the SWIG Python tests. See: ElementsProject#501 (comment)
Okay, so this is working now as of 7e87b7a.
I haven't run any into issues with the Java tests, either before this latest commit or after. What problem are you observing? |
If you don't run make check when building your wheels you don't need to revert this surely? |
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. * manylinux intentionally omits libpython*.so libraries from its build containers to discourage/prevent wheels' native extension libraries from linking against the Python DSO. We don't do that (anymore), but the AX_PYTHON_DEVEL Autoconf macro expects to be able to find it and fails its final sanity check if it can't. Thankfully, more recent versions of the macro support an 'optional' flag that allows configure to proceed even if the check fails. So now we set that flag and just check that we have a value in $PYTHON_CPPFLAGS, which is all the SWIG_PYTHON macro cares about in the first place. After applying these changes, the Gentoo ebuild for libwally-core 1.5.0 now successfully runs the SWIG Python tests on all currently supported versions of Python (3.11 through 3.14), all using the same libwallycore.so.6.
7e87b7a
to
5e137d0
Compare
We do run The reversion turned out not to be a big deal. All I needed was this:
That changes all the (non-PIP) |
@whitslack I've got a couple of things to tend to but will look at this early next week. Assuming no issues I should be able to release it as v1.5.2 fairly soon and hopefully minimise the packaging burden for you going forward. |
Honestly, you might want to wait until 1.6.0, as this is not a trivial change. Technically, it's an ABI-breaking change, as |
Good to know, thanks. I'll have a look at the roadmap and make a call next week. |
Embedding SWIG Python code into
libwallycore.so
ties the library to a specific version of Python, thereby precluding concurrent installation of thewallycore
Python module for multiple implementations of Python on the same system if the Python modules are linked with a system-widelibwallycore.so
. On Gentoo at least, linkinglibwallycore.so
withlibpython3.14.so
and then attempting to use thewallycore
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 compilesswig_python_wrap.c
and links it into the native extension library, so linking it intolibwallycore.so
as well is redundant and harmful.Remove
libswig_python.la
fromlibwallycore_la_LIBADD
, and expunge its existence fromMakefile.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
withlibpython*.so
, there should no longer be any manylinux compatibility issues, so drop the--enable-python-manylinux
Autoconf option and thePYTHON_MANYLINUX
Automake conditional. This also means that the test programs no longer need to link with$(PYTHON_LIBS)
sincelibwallycore.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 undefinedPy*
symbols when it loads them into the Python interpreter.After applying these changes, the Gentoo ebuild for libwally-core 1.5.0 now successfully runs the SWIG Python tests on all currently supported versions of Python (3.11 through 3.14), all using the same
libwallycore.so.6
.For reference, this is a follow-up to a comment I made back in November 2023:
That bad feeling has indeed blossomed into an actual segfault as of Python 3.14.
At that same time, @jgriffiths noted: