WASI distribution PoC

I now have an MVP for a WASI distribution coded up at GitHub - brettcannon/cpython at wasi-package · GitHub . But before I go and ask for a code review, I wanted to make sure I wasn’t missing anything. Below is the output from wasi package which explains what files are included in the final archive (do note that output scrolls and symlinks are not listed):

🧹 Deleting /home/brett/Repositories/python/cpython/dist ...
📝 Copying files to /home/brett/Repositories/python/cpython/dist/python-3.16.0a0-wasm32-wasip1 ...
📁    bin/
📄      python3.16d-config
📄      python3.16d.wasmtime
📁    etc/
📁      python3.16/
📄        wasmtime.toml
📁    include/
📁      python3.16/
📄        pyconfig.h
📄        **/*.h
📁    lib/
📁      python3.16/
📁        lib-wasm
📄          python3.16d.wasm
📄        LICENSE.txt
📄        files in `cat pybuilddir.txt`
📄        **/*.py
📁      pkgconfig/
📄        python*.pc
📁    share/
📁      man/
📁        man1/
📄          python*.1
🗜️  Compressing to /home/brett/Repositories/python/cpython/dist/python-3.16.0a0-wasm32-wasip1.tar.xz ...

The most important things to notice are:

  • lib/python3.16/lib-wasm/python3.16d.wasm
  • bin/python3.16d.wasmtime
  • etc/python3.16/wasmtime.toml

For python3.16d.wasm, I think that’s a reasonable place for the file.

As for python3.16d.wasmtime, it’s contents are:

#!/bin/sh

set -eu

script_dir=$(CDPATH= cd "$(dirname "$0")" && pwd -P)
root=$(CDPATH= cd "$script_dir/.." && pwd -P)
wasm_file="$root/lib/python3.16/lib-wasm/python3.16d.wasm"

exec wasmtime run \
    --argv0 "$wasm_file" \
    --config "$root/etc/python3.16/wasmtime.toml" \
    --dir "/" \
    "$wasm_file" "$@"

And for wasmtime.toml, I think that’s the right place for it (it’s just a copy of cpython/Platforms/WASI/wasmtime.toml at main · python/cpython · GitHub ).

Everything else is just copying files from the right place.

6 Likes

Isn’t there usually a lib-dynload or similar subdirectory for the extension modules? (The extension modules should be what you get from looking in that file, though I’m not sure actually reading pybuilddir.txt is the best way to find them, compared to a *.cpython-316-wasm32-wasip1.so or equivalent glob.)

Yes, but there are no extensions as WASI doesn’t support dynamic loading.

Then why include the build dir at all?

wasm32-wasip1/build/lib.wasi-wasm32-3.16 on  wasi-package via 🐍 v3.14.6
➲ ls -1
__pycache__
_missing_stdlib_info.py
_sysconfig_vars_d_wasi_wasm32-wasi.json
_sysconfigdata_d_wasi_wasm32-wasi.py
build-details.json