-
Notifications
You must be signed in to change notification settings - Fork 34
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
Get ctypes working #68
Comments
Maybe that fixture could be avoided with https://bugs.python.org/issue14527 + its pr python/cpython#20451 using pkg-config + setting PKG_CONFIG_PATH
|
just saw python/cpython#32253 and remind of problem i had with ctypes |
Of course you mean it refuses to synchronously load large wasm libraries.
I would encourage people to package their Python side modules as wheels and compile them themselves rather than using preload plugins. This requires more setup code, but it gives much better control and there are is much more mature tooling around wheels and zip files than around emscripten |
but emscripten_run_preload_plugins and FS.createPreloadedFile have serious limitations. I don't see how you would take out the .so from the wheel and dlopen it synchronously unless you stay in a worker or firefox ( which both bring other serious limitations ). i just tried with BrowserFS with ZipFS/OverlayFS/InMemoryFS and the only way i've found was to copy file into MEMFS and preload from there (required for image/audio/wasm ), the gap beetween Node and browser is to big there. |
so basically it would be preferable to hook fopen and rewrite the preloading logic instead of trying to rely on emscripten FS ? anyway i guess that would be required to make a wasi shim for the browser. |
I'm a bit confused about what the filesystem has to do with it? I'm not doing anything crazy like hooking |
the low level fonction for preloading audio/images/wasm ( The 3 of them not only 1 like in load-package.ts ) is FS.createPreloadedFile but it does not seem to support handling blob urls ( i tried with various in memory fs ). if you don't hook the filesytem how would a C extension be able to dlopen ( or load an image take SDL2_image port ) on the fly. "import" is just the tip of the iceberg. ref: https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.createPreloadedFile |
Don't use |
Right okay, so the point is that Emscripten's const module = await Module.loadWebAssemblyModule(wasmBuffer, {
loadAsync: true,
nodelete: true,
allowUndefined: true,
});
Module.preloadedWasm[dynamic_lib_path] = module; where |
thx @hoodmane edit/ it was made from C with one call to https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_run_preload_plugins + a python call to run_script ( eval for js ) to fix the table after the yield. possibly a job for |
Really you should be building with |
that seems a very good idea ! @tiran that would need to be set at the makefile stage of |
|
same js level there that sounds scary, i'm wary about worker since they have very choppy input and no audio, and worse i'm quite sure i have read somewhere they do not fit well with dynamic linking ( or was it threading? ) |
Workers are great, should always be used in production since otherwise Python will block the UI. The debugging experience is worse though. Workers work correctly with both dynamic linking and threading, but dynamic linking and threading can't be used at the same time. |
@hoodmane indeed but i fear your point of view is a bit too Pyodide centric which is a bit too "serious" for broad audience. i advocate "python for everyone, everywhere" so maybe there should be one UI with python as worker and one without :) |
I think they are even more important for games and reactive input because otherwise that input cannot be processed while Python code is running. We keep Pyodide's console in the main thread because it makes debugging easier. |
For a game, I think the correct design would look like: You could probably make it work on the main thread with function step(){
iteratePythonGameState();
window.requestAnimationFrame(step);
}
window.requestAnimationFrame(step); and then probably there is enough time between each Running the game in the main thread isn't considered to be "browser best practices", but using a worker is indeed a lot of extra trouble. I am hoping to improve the situation with https://github.com/hoodmane/synclink which admittedly still won't make it easy to understand but at least will limit how much code you have to write. |
If you are putting it into Python I would recommend not running it in a worker. Pyodide has decided that making a full UI that runs in a worker is out of scope for us, I think it's also a bit out of scope for CPython. Compare: CPython has a basic repl, IPython is a package. |
Actually the design you describe is close to the one on main thread, but worker sneak in more serialization overhead and some flaws. js call requestAnimationFrame }
} |
Yeah the goal of hoodmane/synclink is to allow synchronous calls to main thread from the worker. But it obviously introduces some complexity and limitations. |
Does anyone have an idea how this could be accomplished with WASI? since WASI doesn't support dynamic linking |
well as discussed on discord i may have one but it's as simple as it's horribly slow : move the dlfcn implementation (temporarily as wasi may gain dlfcn someday ) in cpython layer and use an asynchronous wasm vm from cpython ( pywasm (pure python) or pywasm3 (very portable C) ) to load extra modules |
cp /opt/libffi-emscripten/lib/libffi.a /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/
cp /opt/libffi-emscripten/include/ffi* /emsdk/upstream/emscripten/cache/sysroot/include/
./build-python-emscripten-node.sh --enable-wasm-dynamic-linking
*shared*\n_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -lffi
toModule/Setup.local
The text was updated successfully, but these errors were encountered: