Commit Graph

336 Commits

Author SHA1 Message Date
Hood Chatham 2294ad03ec
Stack Switching: Save the Python state when suspending and restore it when done (#3992)
This allows bidirectional stack switching and other arbitrary control flow, whereas
without this patch arbitrary control flow terribly messes up the Python interpreter
state.

By far the most subtle thing here is the manipulation of the cframe state. This
required careful reading of the greenlet source code and a large amount of trial
and error to get right.

Unfortunately the file pystate.c is tightly coupled to the Python version. There are
apparently plans to try to upstream some of this code from greenlet into Python itself.
In the meantime, it should be possible to continue updating it by imitating greenlet.
2023-11-02 12:48:41 -07:00
Hood Chatham 31c1345afd Move stack switching logic into a new stack switching folder. (#3987)
This is a minor rearrangment.

I renamed "continuations" stuff to "stack_switching" and made a new folder
for stack switching logic. I also added logic in esbuild.config.mjs to calculate
which functions exported from stack_switching.mjs and automatically copy them to
Module and into the Emscripten namespace. This makes unit testing a little neater
since there is no modification of the Module object.
2023-10-21 09:20:09 -07:00
Hood Chatham 3085cb9d5e Use Wasm Exceptions for invoke stubs if they exist (#3957)
If wasm exception handling is available, use dynamically generated modules
with wasm exception handling for the invoke stubs instead of a JS trampoline.
This is useful because JS trampolines interact poorly with JS Promise Integration.

In the future, we should switch exception handling ABIs to the compiler-provided
wasm exception handling ABI and we can remove this code. Currently we are
blocked on using compiler-provided wasm eh by Rust support.
2023-10-21 09:20:09 -07:00
Hood Chatham 90fb414e41
Fix dts bundle generation (#4227)
v8.1.0 (just released) has a regression related to a self referential export in @types/node:
https://github.com/timocov/dts-bundle-generator/issues/264
2023-10-16 17:31:25 -07:00
Hood Chatham 98b4bf567c
Use externrefs for some ffi code (#4218)
This begins migrating some of the ffi code towards using externrefs, which
should make it faster and shorter.

I'm planning on migrating from the existing hiwire.h functions to new `jslib.h` 
functions which will operate on externrefs, but I think it will be easiest to 
do this in several PRs since it's going to be a fair amount of code that
changes (in mostly boilerplate ways though).
2023-10-16 11:47:38 -07:00
Hood Chatham cbb008da59
Improve handling of generated typescript files (#4212)
This makes IDEs, documentation generation tools, and linters handle our
generated files better. I set the project root to be `src` instead of `src/js`  
so that it is allowed to import files directly from `src/core`. This way we 
don't have to copy `error_handling.ts` we can just import
`../core/error_handling`.

I made a new folder called `src/js/generated` to place generated files into and
added typescript resolution rules so that when we import a file called
"generated/blah" we first look for `blah` in `src/js/generated` and then fall
back to a file called `blah` in `src/core`.

This also allows us to move around fewer files when building the docs 
and in the makefile.
2023-10-11 08:14:42 -07:00
Hood Chatham aaab6a86d5
NFC Changes to make it easier to build with dead code elimination (#4198)
This forces a bunch of things to be exported. Hopefully we can eventually build with -sMAIN_MODULE=2
or make no dynamic linking builds.
2023-10-03 17:18:23 -07:00
Hood Chatham f28d8c9efc Revert JSPI Changes
This reverts commits:
9ed5e839ff
8861b317a6
b2c47ae766
ab8dc2eac6
3bcc527c92
2505d4d6a3
2023-09-14 07:26:46 -07:00
Hood Chatham b2c47ae766 Move stack switching logic into a new stack switching folder. (#3987)
This is a minor rearrangment.

I renamed "continuations" stuff to "stack_switching" and made a new folder
for stack switching logic. I also added logic in esbuild.config.mjs to calculate
which functions exported from stack_switching.mjs and automatically copy them to
Module and into the Emscripten namespace. This makes unit testing a little neater
since there is no modification of the Module object.
2023-09-13 16:25:24 -07:00
Hood Chatham 9ed5e839ff Use Wasm Exceptions for invoke stubs if they exist (#3957)
If wasm exception handling is available, use dynamically generated modules
with wasm exception handling for the invoke stubs instead of a JS trampoline.
This is useful because JS trampolines interact poorly with JS Promise Integration.

In the future, we should switch exception handling ABIs to the compiler-provided
wasm exception handling ABI and we can remove this code. Currently we are
blocked on using compiler-provided wasm eh by Rust support.
2023-09-13 16:22:07 -07:00
Hood Chatham 9042e6cb1b
ENH Print helpful error if ccache was linked against too new glibc (#4127)
Resolves pyodide#4126.
If someone builds emsdk outside of the docker image and then attempts to use it
inside, there will be an error. This detects it and tells people to clean emsdk.
2023-09-10 21:08:02 -07:00
Hood Chatham 5db49494dd
Emscripten 3.1.43 (#4056) 2023-08-17 15:30:32 +02:00
Hood Chatham 983f83ba1d
Remove assemble_wat (#3952)
This is dead code.
2023-06-23 16:09:43 -07:00
Hood Chatham 5fe0d2e302
Change the name of repodata.json to pyodide-lock.json (#3824) 2023-06-18 22:57:43 -07:00
Hood Chatham 3e05af6963
Using esbuild instead of rollup (take 2) (#3720)
Co-authored-by: webreflection <andrea.giammarchi@gmail.com>
2023-03-31 09:30:04 +02:00
Gyeongjae Choi 2046310460
ENH Support SDL-based packages and add pyxel (#3508)
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
2023-03-30 08:18:31 +00:00
Roman Yurchak bce105bd69 Revert "Using esbuild instead of rollup (#3679)"
This reverts commit be12f07ed9.
2023-03-29 22:08:03 +02:00
Andrea Giammarchi be12f07ed9
Using esbuild instead of rollup (#3679)
This PR removes *rollup* in favor of *esbuild*, ensuring `DEBUG` flag, when used, 
is available to the produced JS and the *umd* dance has been simplified, ditching 
the *amd* part from it as I think *amd* is kinda dead as module system.
2023-03-27 12:48:19 -07:00
Roman Yurchak 601d939fdd
Fix wheel compression with the JsDelivr CDN (#3667)
Set the MIME type for wheels and zip files to application/wasm to enable CDN compression. Also optionally disable compression in zip files and wheels to make the brotli compression by the CDN more efficient.

Co-authored-by: Gyeongjae Choi <def6488@gmail.com>
2023-03-21 09:11:47 +01:00
Gyeongjae Choi a9182030cd
Merge pyodide_py into python_stdlib.zip (#3621)
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2023-03-04 11:05:12 +01:00
Gyeongjae Choi ba5545cbf1
Add private APIs to get Python version before bootstrapping Python (#3625)
Use them in Module.preRun to initialize the filesystem.
2023-03-03 10:19:43 +01:00
Gyeongjae Choi ed3ae1ba49
Download standard libraries in a zipfile (#3582) 2023-03-01 23:11:30 +01:00
Gyeongjae Choi c55bd2a823
Move webbrowser.py into pyodide-py (#3583) 2023-02-14 16:08:28 +09:00
Hood Chatham 861a758c3b
Add new `pyodide.ffi` JavaScript submodule with PyProxy subtypes (#3523)
This creates a new `pyodide.ffi` submodule and adds a bunch of new subclasses of
`PyProxy` to it.

There are three stages in which we are concerned with the behavior of the
objects we define:
1. at time of static typechecks
2. at execution time
3. when generating docs

Prior to this PR, the subtypes of PyProxy only work well for static type checks,
they work acceptably at runtime (just don't let the user access them), and the
docs don't look that great. This PR is primarily intended to improve the docs
for PyProxy, but they also make execution time checks work better: you can now
say `obj instanceof pyodide.ffi.PyCallable` instead of `obj.isCallable()` which
I is easier to understand and to cross reference against the documentation. I am
marking `isCallable` as deprecated.

I also made a bunch of edits and improvements to the docs.

I have deprecated `PyProxyCallable` in favor of `pyodide.ffi.PyCallable` and
`PyProxy.isCallable` in favor of `obj instanceof pyodide.ffi.PyCallable`.
`PyBuffer` has been renamed to `pyodide.ffi.PyBufferView` and a new `PyBuffer`
has been created which is a subtype of `PyProxy`.
2023-02-05 19:35:08 -08:00
Hood Chatham 5e26d9f1ae
Build libpyodide.a (#3335)
This is work towards unvendoring the Pyodide foreign function interface. 

Prior to this point, we included a large amount of critical functionality with `--pre-js`.
So we could create an archive called `libpyodide.a` with the object files but to use it
you would have to pass `--pre-js _pyodide.out.js` at link time. This embeds all of this
stuff in an object file called `pyodide_pre.o` which goes in our archive so you get all
the needed js runtime by linking it. 

Of course someone trying to use this still has to get the Python code onto the import
path, either using `--preload-file`, using Python to unpack it as a zip archive as we now
do, with zipimporter, or otherwise. They also will have to link `libpython.a` (is CPython
going to start distributing an Emscripten libpython?) and probably various other things.

We have to use a hack to inject the JavaScript code into the object files. The normal
`EM_JS` macro cannot handle arbitrary JavaScript code -- for example it fails with many
regex. Instead we manually generate write a C source file that does what we need using
`xxd`. The generated C code is similar to what `EM_JS` generates, but it uses an array
initializer rather than a string initializer for the characters avoiding the C preprocessor /
compiler's strange opinions about strings.
2023-01-26 17:22:05 -08:00
Hood Chatham c06f4d5dfb
DOCS Fix console.html deploy (#3510)
Put `console.html` in `app.outdir`.

This was needed because readthedocs/readthedocs.org PR 9888 moved the outdir
2023-01-25 09:31:06 -08:00
Hood Chatham 3b2952fc92
Python3.11 (#3252) 2023-01-23 19:45:59 -08:00
Gyeongjae Choi ef112108c9
Add rust toolchain to the pyodide-env docker image (#3441)
This adds rust toolchain into our docker image so we don't have to install it every time.

make rust command still exists, but I removed it from the docs. So now a user (who wants to build a package that requires rust) is responsible for installing rust toolchain in their build setup, which is reasonable I think.

Co-authored-by: josephrocca <1167575+josephrocca@users.noreply.github.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2023-01-10 13:28:04 +09:00
Gyeongjae Choi 2f1716b575
Relocate files inside tools directory (#3358)
This PR relocates files inside `tools` directory so that `tools` directory doesn't
have to be vendored when creating xbuildenv.

- cmake, pyo3 config ==> moved to `pyodide-build`.
- venv python script ==> moved to templates, then copied to dist during build.
2022-12-26 20:00:24 -08:00
Hood Chatham 653310a37d
NFC Use initialization function to load _pyodide_core (#3333)
This adds `_pyodide_core` to the init tab and initializes it using that. This is a small step toward unvendoring the Pyodide ffi.
2022-12-10 09:51:17 -08:00
Hood Chatham 68842baa16
NFC Move rollup.config.js to rollup.config.mjs (#3296)
My local build fails with:
```
RollupError: Node tried to load your configuration file as CommonJS
even though it is likely an ES module. To resolve this, change the
extension of your configuration to ".mjs", set "type": "module" in 
your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
```
This fixes it.
2022-11-26 15:05:42 -08:00
Hood Chatham 8523da0f36
Add a tool to allow us to embed wasm modules with hand coded wat (#3230)
This allows us to embed extra wasm modules into the output. This is split off of #3210.
We need this for #3210 since
1. We don't want to assume that externref is supported but we need to use it as part of
the JS Promise integration proposal. To handle this we segment off the externrefs into
separate wasm modules. If externref is not supported, we load most everything
successfully but these small modules fail to load

2. Even supposing that we know that externref is supported, there is no way to write C
code such that the compiled code uses externref. It's possible using the emscripten
assembly format, but that is less well documented and harder to use for our purposes
than wat.

This PR doesn't actually change anything by itself.
2022-11-10 14:22:59 -08:00
Gyeongjae Choi 69b2d3f157
Add debug build option for js package (#3129) 2022-09-21 14:20:08 +09:00
Gyeongjae Choi 968f2c6f36
Keep webpackIgnore comments when building js package (#3132)
It adds terser config to not strip `/* webpackIgnore */` comments instead of
using sed after build.
2022-09-19 09:28:54 -07:00
Hood Chatham c53e229175
Fix webpack warnings and reenable webpack test (#3094)
This uses sed to insert /* webpackIgnore: true */ comments into pyodide.js. 
This resolves #3087. I also enabled a check that a simple webpack config
builds without warnings. In the future it would be good to add a test that it
also runs without error.
2022-09-12 15:00:54 -07:00
Hood Chatham e6e7d56752
MAINT Remove custom setuptools_rust commit (#3045) 2022-08-30 17:29:25 -07:00
Hood Chatham 325291ab87
Use upstream C++ error formatting support (#2828)
The logic that we are using to format C++ exceptions has been upstreamed. 
This will also work correctly with wasm exceptions.
2022-08-25 14:41:39 -07:00
Gyeongjae Choi e7a7bad1a9
MAINT Prevent `make rust` command from generating a temp file (#2984) 2022-08-18 09:26:31 +02:00
Gyeongjae Choi 26e45657a7
MAINT Build test and distutils stdlib modules with pyodide-build (#2979) 2022-08-18 13:55:16 +09:00
Hood Chatham 5fd96f9b27
Try again with deploying debug version (#2801)
I guess there has to be some trial and error with these. Since we
can't link `pyodide.asm.js` in the deploy docker image, we do it in
a separate step after `build-packages`. Because we have hard
coded `dist` everywhere, it's a little bit awkward building into
`dist-debug`. I do some rearrangements with `cp` and `mv` to hack
around this.
2022-06-28 10:16:23 -07:00
Hood Chatham deb344cd37
Update Rust nightly version (#2792)
Yesterday's nightly includes rust-lang/rust#98149 which allows us to remove the
PIC setting. This also means we won't ever have to put -Zbuild-std back in.
2022-06-26 21:21:34 -07:00
Roman Yurchak 8de2a04ab0
API Rename packages.json to repodata.json (#2749)
Closes #2747

 * renames packages.json to repodata.json
 * renames the corresponding JS and Python variables to be a bit more explicit.

Tangentially related to #795
2022-06-20 14:46:11 -07:00
Hood Chatham 060f1f4ba6
MAINT Use the patched version of setuptools-rust (#2735) 2022-06-20 09:28:19 +09:00
Hood Chatham b427d36e58
Use nightly rust and simplify rust_emcc_wrapper (#2724) 2022-06-15 20:54:56 -07:00
Hood Chatham c834085995
Use emscripten 3.1.13 (#2679) 2022-06-10 22:26:10 +02:00
Hood Chatham dbbbbb67b2
Cryptography v36.0.2 w/ Rust (#2378) 2022-06-09 10:57:34 -07:00
Gyeongjae Choi 0c63457b37
Remove tzdata from the build step (#2658) 2022-06-03 08:51:41 +09:00
Hood Chatham 951681cfba
MAINT Improve debug settings in Makefile.envs (#2648) 2022-05-30 17:16:55 -07:00
Gyeongjae Choi 829023c9af
MAINT Remove outdated commands in Makefile (#2576) 2022-05-19 15:09:24 +09:00
Hood Chatham 7fc1c2da8e
FIX Fix feature detection when `obj.constructor` is undefined (#2520)
Currently the following code fails:
```py
from js import eval
eval("Object.create(null)")
```
with:
```py
Traceback (most recent call last):
  File "<console>", line 1, in <module>
JsException: TypeError: Cannot read properties of undefined (reading 'name')
```
This fixes it.
2022-05-18 22:19:37 -07:00