summaryrefslogtreecommitdiffstats
path: root/Tools/wasm/build_wasi.sh
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2023-06-02 22:15:41 (GMT)
committerGitHub <noreply@github.com>2023-06-02 22:15:41 (GMT)
commit70dc2fb9732ba3848ad3ae511a9d3195b1378915 (patch)
tree5a9fe66e70cabe65a59237a72c9824d41a30b69b /Tools/wasm/build_wasi.sh
parente01b04c9075c6468ed57bc883693ec2a06a6dd8e (diff)
downloadcpython-70dc2fb9732ba3848ad3ae511a9d3195b1378915.zip
cpython-70dc2fb9732ba3848ad3ae511a9d3195b1378915.tar.gz
cpython-70dc2fb9732ba3848ad3ae511a9d3195b1378915.tar.bz2
GH-102404, GH-100956: Document how to do a WASI build (GH-105251)
Also includes a reference shell script to implements what is documented.
Diffstat (limited to 'Tools/wasm/build_wasi.sh')
-rwxr-xr-xTools/wasm/build_wasi.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/Tools/wasm/build_wasi.sh b/Tools/wasm/build_wasi.sh
new file mode 100755
index 0000000..4363062
--- /dev/null
+++ b/Tools/wasm/build_wasi.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/bash
+
+set -e -x
+
+# Quick check to avoid running configure just to fail in the end.
+if [ -f Programs/python.o ]; then
+ echo "Can't do an out-of-tree build w/ an in-place build pre-existing (i.e., found Programs/python.o)" >&2
+ exit 1
+fi
+
+if [ ! -f Modules/Setup.local ]; then
+ touch Modules/Setup.local
+fi
+
+# TODO: check if `make` and `pkgconfig` are installed
+# TODO: detect if wasmtime is installed
+
+# Create the "build" Python.
+mkdir -p builddir/build
+pushd builddir/build
+../../configure -C
+make -s -j 4 all
+export PYTHON_VERSION=`./python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")'`
+popd
+
+# Create the "host"/WASI Python.
+export CONFIG_SITE="$(pwd)/Tools/wasm/config.site-wasm32-wasi"
+export HOSTRUNNER="wasmtime run --mapdir /::$(pwd) --env PYTHONPATH=/builddir/wasi/build/lib.wasi-wasm32-$PYTHON_VERSION $(pwd)/builddir/wasi/python.wasm --"
+
+mkdir -p builddir/wasi
+pushd builddir/wasi
+../../Tools/wasm/wasi-env \
+ ../../configure \
+ -C \
+ --host=wasm32-unknown-wasi \
+ --build=$(../../config.guess) \
+ --with-build-python=../build/python
+make -s -j 4 all
+# Create a helper script for executing the host/WASI Python.
+printf "#!/bin/sh\nexec $HOSTRUNNER \"\$@\"\n" > run_wasi.sh
+chmod 755 run_wasi.sh
+./run_wasi.sh --version
+popd
+