-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
python.extension_module()
linking with libpython when it should not
#11097
Comments
This diagnosis confuses me since we specifically check for link_libpython and remove the link arguments (keeping only the compile ones). However, on 3.7 you are supposed to link to libpython, except on Debian... |
Oh, I think I see it now. Edit: or not? This should already work? |
Apply the information gathered through distutils also to the case when the dependecy has not been expressed explicitly. The spurious linking has been observed on Python 3.7 on Linux where distutils does not instruct to link libpython but the Python's pkg-config contains linker flags to link to libpython. Fixes mesonbuild#11097.
I think the patch makes it clearer. I actually encountered the issue on the manylinux docker images, which are based on AlmaLinux. I suspect Debian may be patching the pkg-condig too. |
The thing is that the patch is exactly what I thought you meant, and I don't see how that's possible to be a problem. The internal dependency is |
I stepped through the thing with The pkg-config definition oh the system looks like this:
Let me know if there is anything else that may be useful to better understand the root cause. Edit: yes, I verified that this is the pkg-config picked up by Meson. |
I think the bug is most likely in the discrepancy between |
Also note that the distinction from |
I had a closer look at the Meson python module code and I understood better what you mean with the above sentence. When the dependency is looked up with |
Apply the information gathered through distutils also to the case when the dependecy has not been expressed explicitly. The spurious linking has been observed on Python 3.7 on Linux where distutils does not instruct to link libpython but the Python's pkg-config contains linker flags to link to libpython. Fixes mesonbuild#11097.
The `py.dependency(embed: false)` method is supposed to consistently provide a distutils-like `python.pc` / `python-embed.pc` interface regardless of Python version. It handles both pkg-config and sysconfig scraping. For the latter, we respect the value of self.link_libpython as determined by distutils, and construct a fully custom dependency. For the former, we blindly assume pkg-config is correct. It isn't correct, not until Python 3.8 when embed was added. Before then, we need to process the pkg-config dependency based on link_libpython. We did this, but only inside the extension_module method, which is obviously wrong. Delete the special casing from extension_module, and handle it inside the dependency. Fixes mesonbuild#11097
So for clarity, I looked at this last night, and I apologize, because what I said was incredibly bogus and clueless. I double and triple checked, and actually The correct fix is: eli-schwartz@889f913 ... When I added the implicit dependency I did probably assume that |
Thanks @eli-schwartz Your fix looks good to me, FWIW. |
The `py.dependency(embed: false)` method is supposed to consistently provide a distutils-like `python.pc` / `python-embed.pc` interface regardless of Python version. It handles both pkg-config and sysconfig scraping. For the latter, we respect the value of self.link_libpython as determined by distutils, and construct a fully custom dependency. For the former, we blindly assume pkg-config is correct. It isn't correct, not until Python 3.8 when embed was added. Before then, we need to process the pkg-config dependency based on link_libpython. We did this, but only inside the extension_module method, which is obviously wrong. Delete the special casing from extension_module, and handle it inside the dependency. Fixes mesonbuild#11097
The `py.dependency(embed: false)` method is supposed to consistently provide a distutils-like `python.pc` / `python-embed.pc` interface regardless of Python version. It handles both pkg-config and sysconfig scraping. For the latter, we respect the value of self.link_libpython as determined by distutils, and construct a fully custom dependency. For the former, we blindly assume pkg-config is correct. It isn't correct, not until Python 3.8 when embed was added. Before then, we need to process the pkg-config dependency based on link_libpython. We did this, but only inside the extension_module method, which is obviously wrong. Delete the special casing from extension_module, and handle it inside the dependency. Fixes mesonbuild#11097
Alright, PR'ed. |
Require unreleased version of Meson to fix Python 3.7 on macOS and Linux build with cibuildwheel, see mesonbuild/meson#11097. Require unreleased meson-python to enable cross compilation on macOS.
Require unreleased version of Meson to fix Python 3.7 on macOS and Linux build with cibuildwheel, see mesonbuild/meson#11097. Require unreleased meson-python to enable cross compilation on macOS.
Require unreleased version of Meson to fix Python 3.7 on macOS and Linux build with cibuildwheel, see mesonbuild/meson#11097. Require unreleased meson-python to enable cross compilation on macOS.
Require unreleased version of Meson to fix Python 3.7 on macOS and Linux build with cibuildwheel, see mesonbuild/meson#11097. Require unreleased meson-python to enable cross compilation on macOS.
Require unreleased version of Meson to fix Python 3.7 on macOS and Linux build with cibuildwheel, see mesonbuild/meson#11097. Require unreleased meson-python to enable cross compilation on macOS.
Since version 0.63.0 Meson automatically adds a dependency on libpython when needed compiling extension modules. To determine whether to link to libpython Meson consults
distutils
. On Python 3.7 on Linux,distutils
says that libpython should not be linked:However, the
pkg-config
file for python contains these linker argumentsThis code
meson/mesonbuild/modules/python.py
Lines 524 to 543 in fd43842
deals with adding the libpython dependency as need. In the case the libpython dependency is explicitly requested, only the compile arguments are used, however, in the case when it is not explicitly requested, all the arguments are added, including the link arguments found via
pkg-config
. I think that only the compile arguments should be included in this case too when the extension module should not be linked with libpython.I'll prepare a PR, but I would like to check with @eli-schwartz if he agrees on the diagnosis.
The text was updated successfully, but these errors were encountered: