Open daniel-larraz opened 2 months ago
We are seeing the same problem with building Matplotlib wheels, though not directly. It's actually failing on kiwisolver
, but this is a bit annoying to work around, since the setuptools
install is under cibuildwheel
's test command + build isolation.
A bisect points to 0ab156c3e12054503a0dac0ce172e241262881f4, which is not too surprising, I think. Bisecting distutils
itself points to pypa/distutils@2c937116cc0dcd9b26b6070e89a3dc5dcbedc2ae
It looks like PyPy only just added LDCXXSHARED
(and there's been no releases with it) but the fetch from sysconfig
to distutils
's linker_so_cxx
does not have any handling of that. Something simple like this might work:
diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py
index fbdd5d73..19ea6aa0 100644
--- a/distutils/sysconfig.py
+++ b/distutils/sysconfig.py
@@ -321,6 +321,9 @@ def customize_compiler(compiler):
)
cxxflags = cflags
+ if ldcxxshared is None:
+ # Older versions of PyPy do not set LDCXXSHARED.
+ ldcxxshared = ldshared
if 'CC' in os.environ:
newcc = os.environ['CC']
Actually, looking at the commit again, it appears that CygwinCCompiler
and UnixCCompiler
both have a default for linker_so_cxx
, but it's customize_compiler
that overwrites it. So instead of trying to set the default in customize_compiler
, it should just not set it, perhaps:
diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py
index fbdd5d73..29a2ba36 100644
--- a/distutils/sysconfig.py
+++ b/distutils/sysconfig.py
@@ -362,11 +362,13 @@ def customize_compiler(compiler):
compiler_cxx=cxx_cmd,
compiler_so_cxx=cxx_cmd + ' ' + ccshared,
linker_so=ldshared,
- linker_so_cxx=ldcxxshared,
linker_exe=cc,
linker_exe_cxx=cxx,
archiver=archiver,
)
+ if ldcxxshared is not None:
+ # Older versions of PyPy do not set LDCXXSHARED.
+ compile.set_executable('linker_so_cxx', ldcxxshared)
if 'RANLIB' in os.environ and compiler.executables.get('ranlib', None):
compiler.set_executables(ranlib=os.environ['RANLIB'])
Thank you @QuLogic for the investigation.
@jaraco , @lazka do you think this patch is viable in the pypa/distutils
repository? Should we move this issue there?
The patches above need a few more None checks for CXXFLAGS and LDCXXSHARED cases, but yeah, moving to distutils sounds good to me.
I wonder why CI didn't catch this.
See #228 where this behavior was added. That PR and the one that preceded it were tricky to get right, especially due to the nuances of manipulating the sysconfig variables and the different locations where those variables are defined.
I see now how that PR caused a regression. Prior to this change, distutils and setuptools would treat C++ like C, only honoring the C configs and environment and disregarding the C++ settings. With the change, it now honors the C++ settings for C++ extensions, but there are some environments that don't yet have C++ settings configured. In that case, we want distutils to fall back to the old behavior (C settings).
I wonder why CI didn't catch this.
We should definitely determine the answer. If the current tests don't cover the condition (and it seems they don't), we'll want to manifest a test that does capture the missed expectation.
Looking at the original PR, test_customize_compiler
does not set LDCXXSHARED
, but it only checks compiler_cxx
, and none of the new compiler_so_cxx
, linker_so_cxx
, linker_exe_cxx
, so it neither confirms that the environment variable works, nor confirms that the fallback works.
It looks like PyPy only just added
LDCXXSHARED
(and there's been no releases with it)
This has now been released in last week's PyPy3.10 v7.3.17:
GitHub Actions is still on 7.3.16:
Reported: https://github.com/actions/setup-python/issues/936
Could you add check-latest: true
to the setup-python action options? I don't know how expensive it is, in any case you can comment it out once the image updates.
Thanks, that does force 7.3.17 to be installed and now it passes for Ubuntu but fails for macOS with a different error:
ld: unknown options: -Bsymbolic-function
https://github.com/hugovk/ultrajson/actions/runs/10676841128
I wonder where that is coming from. As far as I can tell, it is not here (distutils) nor in PyPy. Is it an xcode default?
setuptools version
setuptools==72.2.0
Python version
Python 3.8.16 (PyPy 7.3.11)
OS
Ubuntu 20.04
Additional environment information
This issue occurs only when I run setuptools with PyPy; it works fine with CPython. Downgrading to setuptools version 72.1.0 resolves the issue for both PyPy and CPython.
Description
When building a Cython extension that depends on a shared library, setuptools triggers a
TypeError
during the linking process.Expected behavior
setuptools doesn't fail.
How to Reproduce
Create a file named
hello_world.cpp
:Create a file named
hello_world.h
:On Linux, compile this into a shared library using:
Create a file named
hello.pyx
:Create a
setup.py
file to build the Cython extension:Run the following command in the terminal:
Output