-
Notifications
You must be signed in to change notification settings - Fork 257
stubgen: add LIB_PATH option to locate dependent shared libraries
#1045
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
base: master
Are you sure you want to change the base?
Conversation
|
I am generally open to this feature, but what bothers me is the windows-specific nature. The two other supported platforms (Linux, macOS) have analogous ways of adding dynamic library search paths. |
|
Thanks for raising that point! I updated the code to handle dependent shared libraries on Linux and macOS as well. The option has been renamed from |
DLL_PATH option to locate dependent DLLs on WindowsLIB_PATH option to locate dependent shared libraries
|
What is the status of this PR? This feature is very much appreciated and valuable. |
1778524 to
b7f6b40
Compare
|
Would you be kind enough to add documentation (the source for which is found in the |
1f13784 to
6c26b68
Compare
|
Thanks for the reminder |
a69b64c to
95db088
Compare
4d71d9a to
238b695
Compare
|
@Doekin -- did you test this feature on all platforms? (Linux/Windows/macOS). It does not ship with tests, so it's a bit hard to say if it works as expected. Also, could I ask you to rebase on top of |
|
Tested on Windows so far. Linux/macOS typically have Will rebase on master. |
95db088 to
28c2bfb
Compare
…onfiguration" This reverts commit 28c2bfb.
|
It looks like on Linux/macOS, we're good to go without On Windows, the situation is different: stub generation fails when the dependent DLL isn't in the same directory as the module. The penultimate CI run demonstrates this issue. |
This PR addresses issues such as
ModuleNotFoundErrorthat could occur during stub generation when extension modules depend on external shared libraries (e.g.,.dllon Windows,.soon Linux) located outside of the standard search paths.Background
On Windows, when stubgen attempts to import an extension module to generate stubs,
importlib.import_module()may fail if the Python interpreter cannot locate the required dependent DLLs—for example, if they are not in the same directory as the.pydfile.Example error:
In contrast, on Linux, the dynamic linker can use the extension module's embedded RPATH to find dependencies.
Proposed Change
A new
LIB_PATHargument has been introduced tonanobind_add_stub. This option allows you to specify a list of directories containing dependent shared libraries. During stub generation:os.add_dll_directory().LD_LIBRARY_PATHenvironment variable (on macOS, toDYLD_LIBRARY_PATH).Example Usage