-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
gh-111225: Link extension modules against libpython on Android #115780
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good; thanks a lot for making this bug-fix in a separate PR.
This comment was marked as resolved.
This comment was marked as resolved.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the back and forth; I had forgotten to clean the build folder. I redid my tests and I now can confirm that this breaks --enable-shared
builds on macOS (main
works fine).
This comment was marked as outdated.
This comment was marked as outdated.
Aha, this PR does not include 074bbec; rebasing onto |
…ython#115780) Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
Follow on to python#115780 . Without this change numpy's build is broken.
Follow on to python#115780 . Without this change numpy's build is broken.
…ython#115780) Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
Renaming it breaks the de-facto API that the sysconfig module has provided for 5 years, and which downstream projects rely on.
That check was originally written to configure the python-config script -- I later updated it to also configure the python.pc file. distutils had its own, second copy of the configure.ac logic which was probably dropped during the migration away from internally using distutils. Not really the fault of the variable itself but what can you do. :) |
It's unfortunate that sysconfig exposes all the Makefile variables in this way, because most of them were created with no intention of becoming a stable API. Can you give some examples of projects that rely on this variable? Setuptools, at least, does not rely on it. It has its own logic for deciding which platforms need to link against libpython, and it already knows about Windows, Cygwin and Android. |
Lacking any formalization of the information which might come via #107956, it is necessary to poke at raw Makefile variables -- in this case, the raw Makefile variable that corresponds to whether the "C-API extension modules" pkg-config file is configured to link to libpython. The setuptools logic is actually a copy-paste of the stdlib distutils logic, which was manually kept in sync with Makefile.pre.in up until it got deleted from the stdlib. |
This looks like it's going to break the build for NumPy on Android - the flag to link to
I couldn't agree more, but unfortunately that's the situation we're in. It's best not to rename variables unless the actual content/semantics of the variable changes. In this case, reverting the rename looks like the right thing to do. |
Thanks for the explanation.
Actually as @eli-schwartz says in #116745 (comment), it looks like it will break the build on every platform except Android, because the Meson code defaults to linking against libpython when the variable is missing from sysconfig. So I agree the rename must be reverted. I've done that in #122764. |
Thanks for looking into this! :) Fingers crossed that PEP 739 can be rolled out in the near future (hopefully as a beautiful gift included in 3.14). |
mhsmith:android-link-modules |
For the reasons explained in PEP 738, extension modules must be linked against libpython on Android.
Cygwin has the same requirement, and it looks like there were two existing attempts to implement this:
I've removed the first attempt in favor of the second one, and fixed it as follows:
-fPIC
on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error likerelocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC
.Before:
After: