Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Tools/wasm/build_wasi.sh
12 views
1
#!/usr/bin/bash
2
3
set -e -x
4
5
# Quick check to avoid running configure just to fail in the end.
6
if [ -f Programs/python.o ]; then
7
echo "Can't do an out-of-tree build w/ an in-place build pre-existing (i.e., found Programs/python.o)" >&2
8
exit 1
9
fi
10
11
if [ ! -f Modules/Setup.local ]; then
12
touch Modules/Setup.local
13
fi
14
15
# TODO: check if `make` and `pkgconfig` are installed
16
# TODO: detect if wasmtime is installed
17
18
# Create the "build" Python.
19
mkdir -p builddir/build
20
pushd builddir/build
21
../../configure -C
22
make -s -j 4 all
23
export PYTHON_VERSION=`./python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")'`
24
popd
25
26
# Create the "host"/WASI Python.
27
export CONFIG_SITE="$(pwd)/Tools/wasm/config.site-wasm32-wasi"
28
export HOSTRUNNER="wasmtime run --mapdir /::$(pwd) --env PYTHONPATH=/builddir/wasi/build/lib.wasi-wasm32-$PYTHON_VERSION $(pwd)/builddir/wasi/python.wasm --"
29
30
mkdir -p builddir/wasi
31
pushd builddir/wasi
32
../../Tools/wasm/wasi-env \
33
../../configure \
34
-C \
35
--host=wasm32-unknown-wasi \
36
--build=$(../../config.guess) \
37
--with-build-python=../build/python
38
make -s -j 4 all
39
# Create a helper script for executing the host/WASI Python.
40
printf "#!/bin/sh\nexec $HOSTRUNNER \"\$@\"\n" > run_wasi.sh
41
chmod 755 run_wasi.sh
42
./run_wasi.sh --version
43
popd
44
45
46