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

Support jupyter-lite / pyodide #11

Open
keller-mark opened this issue Apr 15, 2024 · 3 comments
Open

Support jupyter-lite / pyodide #11

keller-mark opened this issue Apr 15, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@keller-mark keller-mark added the enhancement New feature or request label Apr 15, 2024
@keller-mark
Copy link
Owner Author

keller-mark commented Apr 15, 2024

See https://go.dev/blog/wasi - try building with GOOS=wasip1 GOARCH=wasm - use go 1.21 or higher

Update: this works up to the usage of the .so file in the Pyodide python REPL:

Following the steps at https://pyodide.org/en/stable/development/building-and-testing-packages.html#building-and-testing-packages-out-of-tree

pip install pyodide-build

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk

PYODIDE_EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
./emsdk install ${PYODIDE_EMSCRIPTEN_VERSION}
./emsdk activate ${PYODIDE_EMSCRIPTEN_VERSION}
source emsdk_env.sh

cd ..
pyodide build

pyodide venv .venv-pyodide
source .venv-pyodide/bin/activate

pip install "./dist/esbuild_py-0.1.5-cp311-cp311-emscripten_3_1_46_wasm32.whl"

python
>>> import ctypes
>>> from pathlib import Path
>>> import os
>>> lib_path = Path('build/lib.emscripten_3_1_46_wasm32-cpython-311/_esbuild.cpython-311-wasm32-emscripten.so').absolute()
>>> so = ctypes.CDLL(lib_path)
>>> so.transform
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python311.zip/ctypes/__init__.py", line 389, in __getattr__
  File "/lib/python311.zip/ctypes/__init__.py", line 394, in __getitem__
AttributeError: Tried to lookup unknown symbol "transform" in dynamic lib: /path/to/esbuild-py/build/lib.emscripten_3_1_46_wasm32-cpython-311/_esbuild.cpython-311-wasm32-emscripten.so
>>> so.__dict__
{'_name': PosixPath('/path/to/esbuild-py/build/lib.emscripten_3_1_46_wasm32-cpython-311/_esbuild.cpython-311-wasm32-emscripten.so'), '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>, '_handle': 23285320}

@keller-mark
Copy link
Owner Author

May not work without go:wasmexport - see golang/go#65199 although there is discussion of using main with stdin/out

@keller-mark
Copy link
Owner Author

keller-mark commented Apr 16, 2024

Alternative solution: use JS FFI to run the esbuild WASM when in pyodide contexts https://pyodide.org/en/stable/usage/api/python-api/code.html#pyodide.code.run_js - see discussion at pyodide/pyodide#4696 (comment)

Can detect pyodide at runtime with https://pyodide.org/en/0.16.1/faq.html#how-to-detect-that-code-is-run-with-pyodide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant