Skip to content

Conversation

@ryanking13
Copy link
Contributor

@ryanking13 ryanking13 commented Sep 5, 2025

This PR adds ctypes.util.find_library support in Emscripten environment. I am resubmitting the patch that was closed around 3 years ago (#99950).

The previous pull request was closed at that time, as CPython did not have an official Emscripten build. But now it is back to tier-3 with buildbot support, so I think it makes sense to support this in CPython Emscripten builds.

Pyodide is applying this patch to support packages that rely on ctypes.util.find_library to locate packages.

@ryanking13
Copy link
Contributor Author

!buildbot emscripten

@bedevere-bot
Copy link

You don't have write permissions to trigger a build

@hoodmane
Copy link
Contributor

hoodmane commented Sep 5, 2025

!buildbot emscripten

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @hoodmane for commit 857b0fa 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138519%2Fmerge

The command will test the builders whose names match following regular expression: emscripten

The builders matched are:

  • WASM Emscripten PR

Copy link
Contributor

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments/suggestions about the implementation and testing strategy.

I'd also like @hoodmane to confirm the emscripten details on this; this all makes sense assuming LD_LIBRARY_PATH exits in the environment - but my understanding was the there were very limited opportunities to actually manipulate environment variables in a runtime environment.

It's entirely possible I'm missing something here - and the fact this patch comes from Pyodide suggests I might be - I just want to make sure I understand the full context here, and this isn't encoding as Pyodide-ism that won't necessarily apply elsewhere.

@bedevere-app
Copy link

bedevere-app bot commented Sep 8, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ryanking13
Copy link
Contributor Author

I'd also like @hoodmane to confirm the emscripten details on this; this all makes sense assuming LD_LIBRARY_PATH exits in the environment - but my understanding was the there were very limited opportunities to actually manipulate environment variables in a runtime environment.

The runtime environment might not have LD_LIBRARY_PATH. If it doesn't, it will simply fail to locate the library, but if it does, it can be used to locate the library from a specific location. Emscripten utilizes LD_LIBRARY_PATH in their dlopen implementation, so I think it makes sense to use the same approach.

I think this is a general approach that can be used in other non-Pyodide environments. We've noticed that a few packages use ctypes.util.find_library (example1) to locate and load shared libraries. Any Emscripten-targetting Python runtimes that want to support those packages should provide a way to support this function.

@hoodmane
Copy link
Contributor

LD_LIBRARY_PATH exists and works as expected.

@freakboy3742
Copy link
Contributor

!buildbot Emscripten

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @freakboy3742 for commit ff6a669 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138519%2Fmerge

The command will test the builders whose names match following regular expression: Emscripten

The builders matched are:

  • WASM Emscripten PR

@freakboy3742
Copy link
Contributor

!buildbot emscripten

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @freakboy3742 for commit 8157604 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138519%2Fmerge

The command will test the builders whose names match following regular expression: emscripten

The builders matched are:

  • WASM Emscripten PR

@freakboy3742 freakboy3742 added the needs backport to 3.14 bugs and security fixes label Sep 17, 2025
Copy link
Contributor

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One very cosmetic suggestion, but otherwise this looks good to me - thanks for the patch!

@freakboy3742 freakboy3742 enabled auto-merge (squash) September 17, 2025 09:53
@freakboy3742 freakboy3742 merged commit 218b8db into python:main Sep 17, 2025
45 checks passed
@miss-islington-app
Copy link

Thanks @ryanking13 for the PR, and @freakboy3742 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2025
…nment (pythonGH-138519)

Adds support for ctypes loading .so files directly.

---------
(cherry picked from commit 218b8db)

Co-authored-by: Gyeongjae Choi <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Russell Keith-Magee <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 17, 2025

GH-139022 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Sep 17, 2025
@ryanking13
Copy link
Contributor Author

Thanks!

hugovk pushed a commit that referenced this pull request Sep 17, 2025
…onment (GH-138519) (#139022)

Co-authored-by: Gyeongjae Choi <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Russell Keith-Magee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants