-
Notifications
You must be signed in to change notification settings - Fork 69
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
ENH: Don't add system library directories to rpath #160
base: main
Are you sure you want to change the base?
Conversation
You are assuming that LIBDIR is in the dynamic linker's default search directories which is not true for some python distributions. |
So this should stay a distribution patch? Should there be a note for packagers in the setuptools release notes that any patches on the CPython |
I’d say no. The goal of Setuptools adoption of distutils is to remove the need for distribution patches. If a distribution wishes to customize the behavior, Setuptools would like to devise a hook such that a distribution can configure that behavior and not have to patch it… although one supported way of customizing behavior is through a patch to |
Is there a way to access the dynamic linker's default search directories from python? |
I don't understand this concern well enough to comment. I'm hoping @isuruf or someone else can comment. |
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.
Would it be possible to add a test or tests that capture the missed expectation? That way, even if this solution ends up not being the right one, a subsequent change would still honor the concerns this change is attempting to address?
I don't think there is any. I guess there are couple of ways to allow this to work for your use-case.
|
I think so; the rough outline would be to create a C Extension module linked against some shared library in LIBDIR, check its
That second one looks like a good starting point. |
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.
Changes suggested by black in CI
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.
More suggestions from black
I like idea 1 best, because it gives the end user more control, but the second idea may be suitable too if it captures the essential concern. |
2c90ac8
to
6852b20
Compare
12769e5
to
d23e28a
Compare
What's the status of this PR? @DWesl are you still working on it? It looks like there was maybe just one lingering concern. |
Could you remind me what that concern is? It's been a bit since I worked on this. One concern would be all the new tests failing. I should figure out how to compile extensions on Linux, and whether renaming an |
After scanning through the messages, I guess I was mistaken. I see you addressed adding a test and of the two options suggested by isuruf, you elected the second. So now it's just a matter of making sure the tests pass. I'll work on it. |
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.
The tests don't appear to be passing. I see four failures in build_ext
:
FAILED distutils/tests/test_build_ext.py::TestBuildExt::test_build_ext[False] - AssertionError: assert ('RPATH' not in '\nDynamic s... 0x0\n'
FAILED distutils/tests/test_build_ext.py::TestBuildExt::test_build_ext[True] - distutils.errors.LinkError: command '/usr/bin/gcc' failed with exit code 1
FAILED distutils/tests/test_build_ext.py::TestParallelBuildExt::test_build_ext[False] - AssertionError: assert ('RPATH' not in '\nDynamic s... 0x0\n'
FAILED distutils/tests/test_build_ext.py::TestParallelBuildExt::test_build_ext[True] - distutils.errors.LinkError: command '/usr/bin/gcc' failed with exit code 1
Can you investigate?
Last of the patches from pypa#73 Might close pypa/setuptools#3257 Dual purposes here: - On platforms like Cygwin that don't have `rpath`, try to avoid adding things to `rpath` - Some distribution binary package makers require that no shared library list a system library directory (`/lib`, `/lib64`, `/usr/lib`, `/usr/lib64`) in its `rpath`; this patch simplifies the code to ensure the shared library can find its dependencies at runtime.
Avoids problems with odd LIBDIR Package managers will be putting things in LIBDIR anyway, so this should catch all use-cases I know of.
The check reference caused docutils problems with no ldesc. The cygwinccompiler change produced a DeprecationWarning.
Cygwin separates import libraries from dynamic libraries (needed link time vs run time).
Let's see if I got the syntax right. Next step will be hooking the temporary /tmp/libxx_z.so file handling into pytest's tempfile handling.
The old test seemed to pick up the 32-bit library, not the 64-bit one. The new test should pick up the 64-bit one consistently when relevant.
Still need to get the test compiling in the alternate location. Did I add -L/tmp?
I think /usr/lib/libz.so links to /usr/lib/libz.so.10, which in turn links to /usr/lib/libz.so.10.5.1 (numbers may differ), with the last being the actual library. Ensure that is the one I copy for linking.
Maybe this will work better? I should look into whether ELF `so`s store their basename.
@DWesl Let me know if you want to continue working on this, or if we should abandon it. |
I don't understand why copying /usr/lib/libz.so to /tmp/libxx_z.so and trying to link with If you know a library installed outside /usr/lib*/ on the Linux GHA runners, I can use that get a working test, otherwise it might be simplest to drop the test of rpath for non-system library directories. EDIT: If you've already got a test of RPATH that this behavior won't break, then this PR is done barring removal of that part of the test. |
Alternately, you could declare this PR tests the new behavior, and tests of old behavior are out of scope, at which point I delete the part of the test that checks the old behavior |
Not the best solution, but I don't know how to check rpath in a manner that doesn't crash.
I dropped the test of old behavior, so that test passes, but now ruff fails with the extremely informative message "file would be changed". As I can't run ruff on my machine, I'm leaving that for someone else. |
I don't have much experience with rpath (and why one would set it via setuptools), but I wonder if setup.py explicitly requests rpath to be set why remove some of them again? And what is so special about LIBDIR, and Regarding the cygwin part here, I was trying to fix it back then in #150 but missed that cygwincompiler is not actually used outside of tests (see #185) so I think we should move the cygwin check to ignore runtime_library_dirs to unixcompiler as was initially intended. |
I think the main reason is that some distributions fail when creating a RPM/DEB package when there is a rpath for the system library dir. See the issues that OP posted. Usually, packages in setup.py add this rpath so that when building packages locally, the package works without having to set LD_LIBRARY_PATH which is a bad thing to do. Ideally packages should only add RPATH if the path is not a package in the dynamic linker's path.
I'm not sure if removing these directories is the correct thing to do, but I don't think it would break anything. |
Specifically, it looks like it is distrubution policy not to release a package with the system library paths in the rpath of any shared library, because the system library paths are always searched outside certain specific situations. I suspect they don't like the redundancy, as the space gains would be minor.
I think the Since my motivation (crashes on Cygwin) seems to have been alleviated in other ways, the main alternatives would be leaving it to distributions that have such policies to patch setuptools on their own. |
Last of the patches from #73
Might close pypa/setuptools#3257
Might also close pypa/setuptools#3450, depending on what the actual problem looks like
Dual purposes here:
rpath
, try to avoid adding things torpath
(Support Cygwin patches #73, maybe [BUG] Recent release introduced a breaking change on MingW setuptools#3450)/lib
,/lib64
,/usr/lib
,/usr/lib64
) in itsrpath
because these directories are always in the runtime linker search path; this patch simplifies the code to ensure the shared library can find its dependencies at runtime ([BUG] 62.0.0:setuptools._distutils.unixccompiler
hardcodes on linking rpath setuptools#3257)