Skip to content
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

PEP 776: Emscripten support #4307

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

Conversation

hoodmane
Copy link

@hoodmane hoodmane commented Mar 18, 2025

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Rationale
    • Specification
    • Backwards Compatibility
    • Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

📚 Documentation preview 📚: https://pep-previews--4307.org.readthedocs.build/pep-0776/

@hoodmane hoodmane requested a review from a team as a code owner March 18, 2025 10:46
@hugovk hugovk added the new-pep A new draft PEP submitted for initial review label Mar 18, 2025
@hugovk
Copy link
Member

hugovk commented Mar 18, 2025

Thanks for the PEP and work on Emscripten!

I've edited the top post with the new PEP checklist, please could you work through it and check things off?

You can use PEP number 776.

@hoodmane hoodmane changed the title Add Emscripten support pep Add PEP 776: Emscripten support Mar 18, 2025
@hugovk hugovk changed the title Add PEP 776: Emscripten support PEP 776: Emscripten support Mar 18, 2025
@hoodmane
Copy link
Author

formally confirmed their approval

What form does this formal confirmation take? Comment here? cc @ambv @freakboy3742.

@hoodmane
Copy link
Author

content displays as intended in the rendered HTML

The preview link shows pep-0776 as a 404 for me: https://pep-previews--4307.org.readthedocs.build/pep-0776/
Am I doing something wrong?

@hoodmane
Copy link
Author

Lowercase name seemed to be the problem.

@hugovk
Copy link
Member

hugovk commented Mar 18, 2025

Revert 871a223 but keep the newline before the bullet list:

WebAssembly does not have native support for signals. Furthermore, on a
non-pthreads build, the address space of the WebAssembly module is not shared,
so it is impossible for any thread capable of seeing an interrupt to write to
the eval breaker while the Python interpreter is running code. To work around
this, there are two possible solutions:

* If Emscripten is run in a webworker and served with the shared memory headers,
  it is possible to use shared memory outside of the WebAssembly address space
  as a signal buffer. A signal handling UI thread can write the desired signal
  into the signal buffer. The interpreter can periodically check the state of
  this signal buffer in the eval breaker code. Checking the signal buffer is
  slow compared to checking the eval breaker in native platforms, so we do only
  do it once every 50 times through the eval breaker. See
  `Python/emscripten_signal.c <https://github.com/python/cpython/blob/2bef8ea8ea045d20394f0daec7a5c5b1046a4e22/Python/emscripten_signal.c>`__
* Using stack switching, we can occasionally switch the stack and allow the
  JavaScript event loop to go around, then check the state of a signal buffer.
  This requires the experimental JavaScript Promise Integration API, and would
  be best used with the techniques for optimizing long tasks described
  `in this article <https://web.dev/articles/optimize-long-tasks>`__

Emscripten Python has already implemented the solution based on shared memory,
and it is in use in Pyodide.

@hoodmane
Copy link
Author

Thanks for the copy edits @hugovk and @encukou!

@ambv
Copy link
Contributor

ambv commented Mar 18, 2025

I formally confirm sponsorship.

Copy link

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks a lot @hoodmane !

I'm not sure about PEP review process, and if you would rather not get comments here, sorry about that.

Still a few comment below :)

``pyodide_<abi>`` and ``emscripten_<version>`` is intended to be the same as the
relationship between ``manylinux<version>`` and ``linux``.

The specification of the ``pyodide_<abi>`` ABI includes:
Copy link

Choose a reason for hiding this comment

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

It would be good if there was a link to some page where these ABI versions are going to be tracked maybe?

Copy link
Author

Choose a reason for hiding this comment

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

I've been meaning to add to Pyodide a policies page, which would be a good place to refer to for this. I think the most contentious part of this PEP is likely to be who/what organization chooses the ABI and what it is called...

@hugovk
Copy link
Member

hugovk commented Mar 18, 2025

I'm not sure about PEP review process, and if you would rather not get comments here, sorry about that.

These wording comments are generally fine here, thanks.

This first review is mainly for structure and formatting. Once merged, the PEP will be discussed in depth with the community on discuss.python.org (should we do this, how should we do it, etc).

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

@hoodmane Ping when you're ready to merge.

Co-authored-by: Hugo van Kemenade <[email protected]>
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

I left some editorial comments.


as well as any functionality that requires these.

The following are present but cannot be imported due to a dependency on the
Copy link
Member

Choose a reason for hiding this comment

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

So why aren't they removed too?

Copy link
Author

Choose a reason for hiding this comment

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

Uh... that is a good question. This language was added to the Pyodide docs in this PR:
pyodide/pyodide#4078

I just confirmed is true of both Pyodide and Emscripten Cpython. I think the removals are mainly targeted at large modules whereas pty and tty are only a few kilobytes so nobody ever bothered to remove them. If we think they should be removed, I can add language to that effect.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I don't feel strongly, this just stood out as an oddity while reading

Co-authored-by: Jelle Zijlstra <[email protected]>
@hoodmane
Copy link
Author

Thanks for the copy edit @JelleZijlstra!

@hoodmane
Copy link
Author

@hugovk I think this can be merged now. I will address the remaining feedback in followup PRs. Thanks everyone!

@AA-Turner AA-Turner self-requested a review March 18, 2025 23:22
Co-authored-by: Brett Cannon <[email protected]>
@JelleZijlstra
Copy link
Member

@AA-Turner I saw you are intending to review, but I'd rather merge this now since Hugo and I already approved and I prefer for PEPs not to get stuck in the ready-but-not-yet-merged state. If you have feedback, we can always update the PEP text later.

@AA-Turner
Copy link
Member

AA-Turner commented Mar 18, 2025

I'm about halfway through (mainly editorial points, but nothing major so far). Happy for you to merge now though.

I agree we should avoid PEPs being "ready but not merged" (several have been as drafts in PRs for days/weeks(!)), but this PR was only opened this morning -- I had an unexpectedly busy day, so was late on a full read-through.

A

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @hoodmane. Very well written and happy to see this continue to move forward. I remember the early days of pyodide and iodide at Mozilla.

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Sorry again for the delay, almost entirely editorial points.

run in JavaScript runtimes including browsers and Node.js.

This PEP formalizes the addition of Tier 3 for Emscripten support in Python 3.14
which `was approved by the steering council on October 25, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
which `was approved by the steering council on October 25, 2024
which `was approved by the Steering Council on October 25, 2024

This PEP formalizes the addition of Tier 3 for Emscripten support in Python 3.14
which `was approved by the steering council on October 25, 2024
<https://github.com/python/steering-council/issues/256>`__. The goal is to allow
Pyodide wheels to be uploaded to PyPI.
Copy link
Member

Choose a reason for hiding this comment

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

Pyodide (or the relationship to Emscripten) isn't defined here, perhaps a link?

Comment on lines +16 to +18
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler
toolchain which compiles C/C++ code into WebAssembly/JavaScript executables that
run in JavaScript runtimes including browsers and Node.js.
Copy link
Member

Choose a reason for hiding this comment

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

This sentence read a little breathlessly. I also would suggest removing the paragraph break afterwards.

Also, later on the PEP mentions the "Rust emscripten target" -- is this part of the emscripten project? Should the support for Rust/non-C native languages be mentioned here?

Suggested change
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler
toolchain which compiles C/C++ code into WebAssembly/JavaScript executables that
run in JavaScript runtimes including browsers and Node.js.
`Emscripten <https://emscripten.org/>`__ is a complete open source compiler
toolchain. It compiles C/C++ code into WebAssembly/JavaScript executables,
for use in JavaScript runtimes, including browsers and Node.js.

Comment on lines +77 to +78
`Emscripten
<https://emscripten.org/docs/introducing_emscripten/about_emscripten.html>`__
Copy link
Member

Choose a reason for hiding this comment

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

Optional, throughout: To use intersphinx (would need corresponding definition in conf.py)

Suggested change
`Emscripten
<https://emscripten.org/docs/introducing_emscripten/about_emscripten.html>`__
:ref:`Emscripten <emscripten:about-emscripten>`

Linux, and every smartphone.

`The Pyodide project <https://pyodide.org/>`__ has for years supported
Emscripten Python. Hundreds of thousands of students have learned Python through
Copy link
Member

Choose a reason for hiding this comment

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

I've read a couple of times and I'm unclear on the distinction between "Emscripten Python" and "Pyodide". Is there a reference for a disambiguation? The only mention of Python on the emscripten intro page references Pyodide.

1. To describe Pyodide's packaging tooling
2. To describe Pyodide's wheel abi to a similar level of detail as the manylinux
PEPs
3. To request that Pyodide wheels be allowed for upload to PyPI
Copy link
Member

Choose a reason for hiding this comment

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

A PEP specifies, rather than requesting -- if this PEP is accepted and implemented, Pyodide wheels will be permitted:

Suggested change
3. To request that Pyodide wheels be allowed for upload to PyPI
3. For Pyodide wheels to be allowed for upload to PyPI

Comment on lines +82 to +86
Emscripten is a POSIX-based platform. It uses the WebAssembly binary format,
specified here:

* https://webassembly.github.io/spec/core/binary/index.html
* https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md
Copy link
Member

Choose a reason for hiding this comment

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

Is this an accurate rephrasing?

Suggested change
Emscripten is a POSIX-based platform. It uses the WebAssembly binary format,
specified here:
* https://webassembly.github.io/spec/core/binary/index.html
* https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md
Emscripten is a POSIX-based platform. It uses the `WebAssembly binary format`_,
including the `dynamic linking extension`_.
.. _WebAssembly binary format: https://webassembly.github.io/spec/core/binary/index.html
.. _dynamic linking extension: https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md

Comment on lines +118 to +120
Because of these limitations, Pyodide standardizes a no-pthreads build of
Python. We will start with support for no-pthreads builds. If there is
sufficient demand, a pthreads build with no dynamic loader could be added later.
Copy link
Member

Choose a reason for hiding this comment

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

The second sentence seems to repeat the first

Suggested change
Because of these limitations, Pyodide standardizes a no-pthreads build of
Python. We will start with support for no-pthreads builds. If there is
sufficient demand, a pthreads build with no dynamic loader could be added later.
Because of these limitations, Pyodide standardizes a no-pthreads build of
Python. If there is sufficient demand, a pthreads build with no dynamic loader
could be added later.

Comment on lines +266 to +267
Packages
~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Packages
~~~~~~~~
Third-party packages
~~~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pep A new draft PEP submitted for initial review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants