-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Document how to run code under WASI #100956
Comments
fwiw, I have a devcontainer here: https://github.com/dev-wasm/dev-wasm-python that makes it easy to do this in GitHub codespaces or VS Code. I would be happy to expand that documentation via PR if there is an interest. |
I'm happy to take a PR! I'm honestly not looking at anything fancy, just something simple like, "To run code under wasmtime, you probably want to run the command The only thing that may need checking is whether any specific directory mapping is necessary for e.g. |
Ok, I will send a PR. |
Mostly for me to not forget, |
Here's the script I use (and which I put in the docs) #!/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}
else
HOST_DIR=$PWD
GUEST_DIR=$PWD
FILE="/$PWD/${@#}"
fi
PYTHON_WASI_ROOT=/Python-3.11.0-wasm32-wasi-16
wasmtime run --dir ${PYTHON_WASI_ROOT} \
--mapdir /::${PYTHON_WASI_ROOT} \
--dir ${HOST_DIR} \
--mapdir ${GUEST_DIR}::${HOST_DIR} \
-- ${PYTHON_WASI_ROOT}/python.wasm $FILE Note that the one weirdness is that the working directory is the working directory of |
Yeah, it's a bit annoying. We can actually compile in the bytecode for the |
There is no manual step. Currently when freezing the stdlib, the tools record the relative path for each frozen stdlib module as part of the frozen data. During import we then make that path absolute (using |
https://github.com/python/cpython/tree/main/Tools/wasm doesn't cover how to take a WASI build and actually use it. We can probably just snag the instructions from https://github.com/tiran/cpython-wasm-test for wasmtime, maybe something for https://github.com/bytecodealliance/wasm-micro-runtime . Key thing is to probably show how to run something like pytest with a WASI build.
Linked PRs
The text was updated successfully, but these errors were encountered: