-
Notifications
You must be signed in to change notification settings - Fork 341
[lldb] Fix deps loading for lldb-python on Windows and Python3.8+ #9370
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
[lldb] Fix deps loading for lldb-python on Windows and Python3.8+ #9370
Conversation
At this point, I patched the module load code for both cases here, swig and static. However, upstream LLDB doesn't have the static binding case. Would it be better to submit the majority of this patch upstream and only patch the static binding code here in swiftlang LLDB? Not sure. Any thoughts? |
If you ask me, this solution feels too generic. I don't know how swift build is set up (let alone swift-on-windows), so it's hard to provide more specific feedback. Maybe you could give an example of the layouts (build and install) that you want to support. Also, how is this situation handled on non-windows operating systems? Do we use rpath to let liblldb find the dependent binaries? |
Good question. In Apple Swift 5.10, liblldb has an rpath for the Swift dylibs in Homebrew does a llvm-shared-lib build and it doesn't ship LLDB.framework, so this might be closer to the Linux distribution. It doesn't have the Swift dependencies, because it ships upstream LLDB, but it has others. Looking at 17.0.6, it depends on Installing the official LLDB 19 for Windows, I only see Python as a dynamic dependency. The DLL is 180MB on my system, so I guess everything else is linked statically.
Python seems special in this case: It's not resolved when running For Swift, however, we don't want to link the DLLs statically. |
I did a few more attempts to patch the module load code. For example, trying to hardcode a set of relative paths into the My interim status is: Attempting to patch module load code with |
On Windows there is no concept similar to rpaths. Instead the best practice is to copy DLLs into the directory of their depending binaries. We attempted it before in the build script, but asking devs to keep the list of files up-to-date didn't seem feasible: Instead of the build-script, we could also do that in CMake and it turns out that there even is a dedicated generator expression for it: That avoids the explicit file list and fixes the |
|
That was the gist. What do you think @labath? Or otherwise @hjyamauchi and @hyp? |
If that's the state of the art on windows then I guess that's fine with me. My question about was more along the lines of: if we know what rpath to set (are we setting that explicitly somewhere), then maybe it would be reasonable to take the same path and give it to python as the dll directory path (I'm not sure which mechanism to use, though if it would be known to cmake, then it could probably be somehow embedded in the bindings). |
We have to copy it over in build.ps1 since it doesn't exist yet during the initial build.
Since Python3.8 the Windows Python runtime now longer loads dependent DLLs for module imports from Path or CWD. Instead, candidate locations must be set explicit via
os.add_dll_directory()
. This is a known issue and reported a long time ago. It's an issue for swiftlang LLDB in particular, because it depends on a number of DLLs from the Swift toolchain, likeSwiftSyntax.dll
andSwiftParser.dll
.Previously, the implicit assumption was that these DLLs will always be somewhere in Path and so Python would find them. Now we have to remember where to look and it might not always be the same places. We want to refer to the build-tree when testing and the install-tree after packaging. A list of candidate locations seems to be a flexible solution.
The list should be easy to write from CMake as well as easy to review and extend. A text file inside the Python package seems handy and it keeps the Python bindings code somehow generic. A post-build step for the
lldb-python
target creates the text file and sets LLVM's shared library output dir (i.e. the build-tree'sbin
) as the default location.