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

Emscripten support: Use es6 modules #126898

Open
hoodmane opened this issue Nov 16, 2024 · 0 comments
Open

Emscripten support: Use es6 modules #126898

hoodmane opened this issue Nov 16, 2024 · 0 comments
Labels
OS-emscripten type-feature A feature request or enhancement

Comments

@hoodmane
Copy link
Contributor

hoodmane commented Nov 16, 2024

We are in the future and ES6 module support is finally universal in mainstream JavaScript runtimes (Firefox was the straggler but finally added Module WebWorker support in v114 released on June 6 2023). They have many benefits, such as fewer global variables and more sanity. We should switch to using them.

cc @freakboy3742

Linked PRs

hoodmane added a commit to hoodmane/cpython that referenced this issue Nov 16, 2024
@picnixz picnixz added the type-feature A feature request or enhancement label Nov 16, 2024
hoodmane added a commit to hoodmane/cpython that referenced this issue Nov 16, 2024
hoodmane added a commit to hoodmane/cpython that referenced this issue Nov 16, 2024
…try script

We delete `node_pre.js` and `--pre-js`. Instead that logic moves to
`node_entry.mjs`. In order to access `FS` from outside of `python.mjs`, we need
to add `-sEXPORTED_RUNTIME_METHODS=FS`. Instead of invoking `python.js`
directly, we will invoke `node_entry.mjs`.

Special care has to be taken to ensure that we get `sys.executable` correct. It
should point to the original path that was invoked, without symlinks resolved. I
updated the generated `python.sh` to calculate it's own absolute path with
`realpath -s $0` and pass that in. Then `node_entry.mjs` sets `thisProgram` to
the path passed in. I manually validated this by creating a symlink to
`python.sh` and invoking it. `sys.executable` and `sys._base_exectable`
indeed point to the symlink, not to the build directory `python.sh` and not to
`node_entry.mjs`.
hoodmane added a commit to hoodmane/cpython that referenced this issue Nov 16, 2024
We delete `node_pre.js` and `--pre-js`. Instead that logic moves to
`node_entry.mjs`. In order to access `FS` from outside of `python.mjs`, we need
to add `-sEXPORTED_RUNTIME_METHODS=FS`. Instead of invoking `python.js`
directly, we will invoke `node_entry.mjs`.

Special care has to be taken to ensure that we get `sys.executable` correct. It
should point to the original path that was invoked, without symlinks resolved. I
updated the generated `python.sh` to calculate it's own absolute path with
`realpath -s $0` and pass that in. Then `node_entry.mjs` sets `thisProgram` to
the path passed in. I manually validated this by creating a symlink to
`python.sh` and invoking it. `sys.executable` and `sys._base_exectable`
indeed point to the symlink, not to the build directory `python.sh` and not to
`node_entry.mjs`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-emscripten type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants