Scons: Add rpath for relocatable Python installations#3333
Conversation
Reviewer's Guide by SourceryThis pull request adds support for relocatable Python installations by introducing a mechanism to detect them and setting the rpath accordingly. It introduces a new Sequence diagram for relocatable Python detectionsequenceDiagram
participant Nuitka
participant PythonFlavors
participant sysconfig
Nuitka->>PythonFlavors: isRelocatable()
PythonFlavors->>sysconfig: get_config_var("PYTHON_BUILD_STANDALONE")
sysconfig-->>PythonFlavors: Returns 1 or None
alt PYTHON_BUILD_STANDALONE == 1
PythonFlavors-->>Nuitka: True
else isSelfCompiledPythonUninstalled()
PythonFlavors->>PythonFlavors: isSelfCompiledPythonUninstalled()
PythonFlavors-->>Nuitka: Result of isSelfCompiledPythonUninstalled()
else
PythonFlavors-->>Nuitka: False
end
Updated class diagram for Python flavorsclassDiagram
class PythonFlavors {
<<module>>
+isRyePython()
+isPythonBuildStandalonePython()
+isPyenvPython()
+isUninstalledPython()
+isRelocatable()
+getPythonFlavorName()
}
note for PythonFlavors.isRelocatable "New method to detect relocatable Python installations"
note for PythonFlavors.isPythonBuildStandalonePython "Replaces isUvPython"
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You didn't respond to my ideas about doing it always, and I tend to take that as agreement. I think we understand that for your Python flavor, it is needed for sure, and as such I am now going to rebase it, but making the rpath non-optional, and to only disable it where the toolchain doesn't support that feature at most. |
488e01b to
46e5da3
Compare
|
So, this rebased to 2.6.6 without any issues. |
|
And I implemented my idea, renaming the flavor, please let me know if you like it, and inviting you to test it, I didn't quite check it yet. Doing it always should not break UV-Python's use of Standalone Build Python. Adding it as a flavor will make uses outside of uv supported as well I think. |
There was a problem hiding this comment.
Hey @geofft - I've reviewed your changes - here's some feedback:
Overall Comments:
- The
isRelocatablefunction duplicates the logic ofisPythonBuildStandalonePythonandisSelfCompiledPythonUninstalled; consider consolidating. - The changes touch a lot of files; could you provide more context on why each change is necessary?
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
43b975d to
e9ff424
Compare
|
It seems, somehow the rpath added survives on Linux now, where of course it should be removed for standalone to be working properly, I need to check that out. |
e9ff424 to
fe63b53
Compare
|
So, it was only removing the rpath for the main executable on macOS, which may have been too little anyway, need to do it for all platforms now, as it now gets added always, that should repair general Linux standalone. Glad that Github Actions Python detected that with it not using static libpython, in my setups it didn't show. |
fe63b53 to
852e33e
Compare
|
Oh the joy of it, macOS (maybe Clang?) won't accept |
c4ab575 to
5a78e40
Compare
|
I rebased to current develop and fixed macOS, which has no rpath at all, me being ignorant there. |
5a78e40 to
056ffc4
Compare
|
Rebased it to the current develop branch after the other PRs merge. It's very disturbing that this still fails, despite it claiming to set the rpath properly on |
|
So, my suspect is that DT_RPATH is used by GitHub Actions Python, but no say my Debian Python, where i force it to use --static-libpython=no to reproduce it, so adding |
537b6a6 to
799e103
Compare
7331249 to
68e0085
Compare
|
I am at a complete loss there, it seems the ELF output is perfect: Yet, the runtime traces taking complains the GitHub Action Python libpython is being loaded, for which there wouldn't be a reason why. And esp. if this wasn't sufficient, I don't see why the old code didn't show that happen, if somehow it was forced through environment or something. In the old code, it just didn't have an rpath, how would that make it check the local directory first, maybe |
|
So, this comes down to |
|
So, I think, I am making the executive decision, to minimize the differences of this PR to develop, and skip this for the next hotfix, unless I figure out what's going on through that. Failing tests on Github Actions is not acceptable. Obviously unsetting LD_LIBRARY_PATH before any execution of a standalone binary is kind of a must, for the strace to hold any water, but I would really like to understand why I haven't noticed this issue previously, since it's absolutely presenct on current hotfix branch as well, but strace doesn't load it from there. I tried manually removing the RPATH, to see if that's what causes it, but on my Debian that didn't do anything particular, so I am at a loss what is bug hiding there, or how the strace analysis is not effective previously. |
68e0085 to
d510d5e
Compare
|
So, I rebased this to factory branch now, to which I picked the changes that are in here, but could be separate, flavor rename, lib_Hacl2_SHA2 issue, and the minor test improvement to display the resulting file. |
|
Now GitHub is just giving me a hard time for the merge of that other PR that now conflicts, I of course put that for the hotfix, so really, I think the best way ahead is to make the hotfix release now and rebase onto the then develop. The diff is really small now, but it seems centered around touching the linker rpath. I am contemplating to add to develop a change where for one standalone binary, it does the output of readelf anyway, so I can see what would be the change, maybe |
d510d5e to
ccf4e15
Compare
|
So, with this rebased and minimal, still fails. Maybe an explanation why I don't just fix the So, what I will probably add, is like a standalone compilation with artifacts like a report, and the readelf output, and the strace captured on execution, such that I have a reference point to easily compare the situation. We are down to just adding the rpath early, during compilation, and that causing the test to fail, and it being added later, to not do that. But also, it's being removed and replaced entirely, and yet there is a difference. I would like to get to the bottom of that, and Github Actions Python is obviously a relatively difficult environment for that. |
|
So, I was distracted privately with real life Nuitka being in hospital for close to 2 weeks, but I am finally getting to this, and have updated factory with the recording of reports. For a simple standalone this is what ldd gives without the PR code: And this is what readelf says: Both are good, but supposedly the PR breaks that, and I don't know how, but lets first confirm that by me rebasing to current factory branch. |
ccf4e15 to
8ab76cf
Compare
|
So, indeed the regression is this PR branch, and not an old issue, noticed only now, the readelf has a The ldd output then gives this: And while this affects libpython here, I guess it could affect practially all other DLLs contained. I thought I had made sure it's a RPATH vs. RUNPATH, but somehow unsuccessfully maybe. |
8ab76cf to
6454f86
Compare
|
Pretty sure I tried Of course, "Standalone Build Python" ought to not need a dynamic libpython, but rather libpython is not off the table, but I guess that's still a very good improvement to Nuitka. I wasn't aware of there being such a difference between |
* Relocatable installations are not installed to a system-wide path and therefore compiling against their libpython require using an rpath to find it in accelerated mode. * This might break platforms that don't have rpath and these need to be listed one by one. Please PR those as you encounter them. * For standalone only, we correct the rpath in the distribution to become "$ORIGIN" again as we need that there either way.
6454f86 to
5472ea7
Compare
|
Rebased it back to develop and adapted the commit message, a bunch of fixes has already been evacuated from this PR before, leaving only the always-rpath change in. |
|
I merged this but will put it into 2.6.8 hotfix directly if that works. |
|
The newly released Nuitka 2.6.8 fixed the issue for me! 🎉 See: #3325 (comment) |
|
Part of the 2.7 release |
Relocatable installations are not installed to a system-wide path and therefore compiling against their libpython requires using an rpath. At the moment the heuristic is whether the installation comes from python-build-standalone.
Fixes #3325.
Summary by Sourcery
Add support for relocatable Python installations. Detect
python-build-standaloneinstallations and userpathwhen linking againstlibpython. Improve error messages for statically linking relocatable Python installations.Bug Fixes:
Build:
rpathfor relocatable Python installations when linking againstlibpython.python-build-standaloneas relocatable installations.python-build-standalone.