-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-21536: On Cygwin, C extensions must be linked with libpython #13549
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -714,20 +714,32 @@ def get_libraries(self, ext): | |
# don't extend ext.libraries, it may be shared with other | ||
# extensions, it is a reference to the original list | ||
return ext.libraries + [pythonlib] | ||
# On Android only the main executable and LD_PRELOADs are considered | ||
# to be RTLD_GLOBAL, all the dependencies of the main executable | ||
# remain RTLD_LOCAL and so the shared libraries must be linked with | ||
# libpython when python is built with a shared python library (issue | ||
# bpo-21536). | ||
else: | ||
# On Android only the main executable and LD_PRELOADs are considered | ||
# to be RTLD_GLOBAL, all the dependencies of the main executable | ||
# remain RTLD_LOCAL and so the shared libraries must be linked with | ||
# libpython when python is built with a shared python library (issue | ||
# bpo-21536). | ||
# On Cygwin (and if required, other POSIX-like platforms based on | ||
# Windows like MinGW) it is simply necessary that all symbols in | ||
# shared libraries are resolved at link time. | ||
from distutils.sysconfig import get_config_var | ||
link_libpython = False | ||
if get_config_var('Py_ENABLE_SHARED'): | ||
# Either a native build on an Android device or the | ||
# cross-compilation of Python. | ||
if (hasattr(sys, 'getandroidapilevel') or | ||
('_PYTHON_HOST_PLATFORM' in os.environ and | ||
get_config_var('ANDROID_API_LEVEL') != 0)): | ||
ldversion = get_config_var('LDVERSION') | ||
return ext.libraries + ['python' + ldversion] | ||
# A native build on an Android device or on Cygwin | ||
if hasattr(sys, 'getandroidapilevel'): | ||
link_libpython = True | ||
elif sys.platform == 'cygwin': | ||
link_libpython = True | ||
elif '_PYTHON_HOST_PLATFORM' in os.environ: | ||
# We are cross-compiling for one of the relevant platforms | ||
if get_config_var('ANDROID_API_LEVEL') != 0: | ||
link_libpython = True | ||
elif get_config_var('MACHDEP') == 'cygwin': | ||
link_libpython = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I just mostly "unwrapped" the single |
||
|
||
if link_libpython: | ||
ldversion = get_config_var('LDVERSION') | ||
return ext.libraries + ['python' + ldversion] | ||
|
||
return ext.libraries |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15129,9 +15129,9 @@ LDVERSION='$(VERSION)$(ABIFLAGS)' | |
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDVERSION" >&5 | ||
$as_echo "$LDVERSION" >&6; } | ||
|
||
# On Android the shared libraries must be linked with libpython. | ||
# On Android and Cygwin the shared libraries must be linked with libpython. | ||
|
||
if test -z "$ANDROID_API_LEVEL"; then | ||
if test -z "$ANDROID_API_LEVEL" -o "$MACHDEP" != "cygwin"; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "even clearer if the test weren't negated" yeah, please invert the test conditions to avoid double negation ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad we're on the same page. It's the double-negation that tripped me up in the first place, and probably you too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes |
||
LIBPYTHON='' | ||
else | ||
LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" | ||
|
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.
@embray trying to better understand this change...
On Android, before this PR, it is technically possible to refrain from linking to libpython if and only if python itself is configured as a static build.
This Cygwin change applies here also within
if get_config_var('Py_ENABLE_SHARED'):
-- does Cygwin only need libpython in shared builds, like Cygwin, or all the time, like MSVC?The commit message glosses over it by pointing out that static Cygwin builds are broken anyway. I am simply curious what the most correct approach is (when implementing similar logic outside of distutils).