You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 wasmtime run --dir . --." Maybe something similar for iwasm, but that's just a bonus.
The only thing that may need checking is whether any specific directory mapping is necessary for e.g. /tmp in case some code somewhere in pytest or something is making some bad assumption about that directory always existing.
Mostly for me to not forget, wasmtime run --mapdir .::Python-3.11.0-wasm32-wasi-16 Python-3.11.0-wasm32-wasi-16/python.wasm gets the REPL up and running, as does wasmtime run --dir . python.wasm when in the same directory as lib/ (at least when grabbed from https://github.com/tiran/cpython-wasm-test/releases).
Note that the one weirdness is that the working directory is the working directory of python.wasm not the directory of the script. That's a little unfortunate, but doesn't seem to be settable in wasmtime right now. I would wish for a flag that I could use in wasmtime to set the working directory, but I can't seem to find one.
Note that the one weirdness is that the working directory is the working directory of python.wasm not the directory of the script. That's a little unfortunate, but doesn't seem to be settable in wasmtime right now. I would wish for a flag that I could use in wasmtime to set the working directory, but I can't seem to find one.
Yeah, it's a bit annoying. We can actually compile in the bytecode for the .py files in the stdlib into the binary (it's called freezing), but it does make the tracebacks less useful since the actual source code won't be shown (the line numbers and file paths are still there, though). I think we have a mechanism right now that lets us manually specify the paths back to the source for frozen code; @ericsnowcurrently , is that right?
I think we have a mechanism right now that lets us manually specify the paths back to the source for frozen code; @ericsnowcurrently , is that right?
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 sys._stdlib_dir) and use the result for __file__. I'm not sure how that works with WASM though.
Activity
brendandburns commentedon Jan 12, 2023
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.
brettcannon commentedon Jan 12, 2023
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
wasmtime run --dir . --." Maybe something similar for iwasm, but that's just a bonus.The only thing that may need checking is whether any specific directory mapping is necessary for e.g.
/tmpin case some code somewhere in pytest or something is making some bad assumption about that directory always existing.brendandburns commentedon Jan 12, 2023
Ok, I will send a PR.
brettcannon commentedon Jan 13, 2023
Mostly for me to not forget,
wasmtime run --mapdir .::Python-3.11.0-wasm32-wasi-16 Python-3.11.0-wasm32-wasi-16/python.wasmgets the REPL up and running, as doeswasmtime run --dir . python.wasmwhen in the same directory aslib/(at least when grabbed from https://github.com/tiran/cpython-wasm-test/releases).brendandburns commentedon Jan 13, 2023
Here's the script I use (and which I put in the docs)
Note that the one weirdness is that the working directory is the working directory of
python.wasmnot the directory of the script. That's a little unfortunate, but doesn't seem to be settable in wasmtime right now. I would wish for a flag that I could use inwasmtimeto set the working directory, but I can't seem to find one.brettcannon commentedon Jan 13, 2023
Yeah, it's a bit annoying. We can actually compile in the bytecode for the
.pyfiles in the stdlib into the binary (it's called freezing), but it does make the tracebacks less useful since the actual source code won't be shown (the line numbers and file paths are still there, though). I think we have a mechanism right now that lets us manually specify the paths back to the source for frozen code; @ericsnowcurrently , is that right?ericsnowcurrently commentedon Jan 17, 2023
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
sys._stdlib_dir) and use the result for__file__. I'm not sure how that works with WASM though.GH-102404, GH-100956: Document how to do a WASI build (GH-105251)
brettcannon commentedon Jun 2, 2023
70dc2fb