Repository navigation
gh-100956: Update directions for how to run python + wasm #101003
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,12 @@ Users and developers are encouraged to use the script | |||||||||||||||||||||||
| `Tools/wasm/wasm_build.py`. The tool automates the build process and provides | ||||||||||||||||||||||||
| assistance with installation of SDKs. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## wasm32-emscripten build | ||||||||||||||||||||||||
| * [Build emscripten](https://github.com/python/cpython/tree/main/Tools/wasm#wasm32-emscripten-build) | ||||||||||||||||||||||||
| * [Serve Python WASM](https://github.com/python/cpython/tree/main/Tools/wasm#hosting-python-wasm-builds) | ||||||||||||||||||||||||
| * [Build WASI-SDK](https://github.com/python/cpython/tree/main/Tools/wasm#wasi-wasm32-wasi) | ||||||||||||||||||||||||
| * [Running Python in WASI]((https://github.com/python/cpython/tree/main/Tools/wasm#running-python-wasi) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # wasm32-emscripten build | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| For now the build system has two target flavors. The ``Emscripten/browser`` | ||||||||||||||||||||||||
| target (``--with-emscripten-target=browser``) is optimized for browsers. | ||||||||||||||||||||||||
|
|
@@ -281,6 +286,50 @@ make -j$(nproc) | |||||||||||||||||||||||
| popd | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Running Python in WASI | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Here is a simple script that can run a python script, it expects that the Python installation | ||||||||||||||||||||||||
| is at the root of the filesystem (and it appears that currently that is [required](https://github.com/python/cpython/issues/100307). | ||||||||||||||||||||||||
|
Comment on lines
+291
to
+292
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue #100307 is not about where you run the WASI binary from, but how you have to mount the
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```shell | ||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if [ $# -eq 0 ]; then | ||||||||||||||||||||||||
| FILE="" | ||||||||||||||||||||||||
| HOST_DIR=$PWD | ||||||||||||||||||||||||
| GUEST_DIR=$PWD | ||||||||||||||||||||||||
| elif [[ "$1" = /* ]]; then | ||||||||||||||||||||||||
| REAL_PATH=$(realpath $1) | ||||||||||||||||||||||||
| HOST_DIR=$(dirname $REAL_PATH) | ||||||||||||||||||||||||
| GUEST_DIR=$HOST_DIR | ||||||||||||||||||||||||
| FILE=${REAL_PATH} | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe to help make things clearer around the difference between host and guest directories it's worth mapping to a |
||||||||||||||||||||||||
| else | ||||||||||||||||||||||||
| HOST_DIR=$PWD | ||||||||||||||||||||||||
| GUEST_DIR=$PWD | ||||||||||||||||||||||||
| FILE="/$PWD/${@#}" | ||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| PYTHON_WASI_ROOT=/Python-3.11.0-wasm32-wasi-16 | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably move this to the top and leave a comment about updating it. |
||||||||||||||||||||||||
| wasmtime run --dir ${PYTHON_WASI_ROOT} \ | ||||||||||||||||||||||||
| --mapdir /::${PYTHON_WASI_ROOT} \ | ||||||||||||||||||||||||
| --dir ${HOST_DIR} \ | ||||||||||||||||||||||||
| --mapdir ${GUEST_DIR}::${HOST_DIR} \ | ||||||||||||||||||||||||
| -- ${PYTHON_WASI_ROOT}/python.wasm $FILE | ||||||||||||||||||||||||
|
Comment on lines
+313
to
+317
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Once you have that script installed somewhere and executable (e.g. `/usr/bin/python3-wasm`) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| # Launch a REPL | ||||||||||||||||||||||||
| python3-wasm | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Launch a python file | ||||||||||||||||||||||||
| python3-wasm some-python.py | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Launch a directory | ||||||||||||||||||||||||
| python3-wasm some/directory/ | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| ## WASI limitations and issues (WASI SDK 15.0) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| A lot of Emscripten limitations also apply to WASI. Noticeable restrictions | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either use relative anchor links so this works offline or rely on GitHub's automatic table of contents for all Markdown files.