• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/bash
2
3set -e -x
4
5# Quick check to avoid running configure just to fail in the end.
6if [ -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
9fi
10
11if [ ! -f Modules/Setup.local ]; then
12    touch Modules/Setup.local
13fi
14
15# TODO: check if `make` and `pkgconfig` are installed
16# TODO: detect if wasmtime is installed
17
18# Create the "build" Python.
19mkdir -p builddir/build
20pushd builddir/build
21../../configure -C
22make -s -j 4 all
23export PYTHON_VERSION=`./python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")'`
24popd
25
26# Create the "host"/WASI Python.
27export CONFIG_SITE="$(pwd)/Tools/wasm/config.site-wasm32-wasi"
28export HOSTRUNNER="wasmtime run --mapdir /::$(pwd) --env PYTHONPATH=/builddir/wasi/build/lib.wasi-wasm32-$PYTHON_VERSION $(pwd)/builddir/wasi/python.wasm --"
29
30mkdir -p builddir/wasi
31pushd 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
38make -s -j 4 all
39# Create a helper script for executing the host/WASI Python.
40printf "#!/bin/sh\nexec $HOSTRUNNER \"\$@\"\n" > run_wasi.sh
41chmod 755 run_wasi.sh
42./run_wasi.sh --version
43popd
44
45