From 27a0e1c1e7b211cb0b9456efc3d94db6b93310fd Mon Sep 17 00:00:00 2001
From: Christian Heimes <christian@python.org>
Date: Wed, 15 Jun 2022 11:25:02 +0200
Subject: [PATCH 1/3] gh-84461: Document how to install SDKs manually

---
 Tools/wasm/README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/Tools/wasm/README.md b/Tools/wasm/README.md
index 3b7a7aecc33eae..4dfd385ee3cda3 100644
--- a/Tools/wasm/README.md
+++ b/Tools/wasm/README.md
@@ -338,3 +338,84 @@ Feature detection flags:
 * ``__wasm_bulk_memory__``
 * ``__wasm_atomics__``
 * ``__wasm_mutable_globals__``
+
+## Install SDKs and dependencies manually
+
+In some cases (e.g. build bots) you may prefer to install build dependencies
+directly on the system instead of using the container image. Total disk size
+of SDKs and cached libraries is about 1.6 GB.
+
+### Install OS dependencies
+
+```shell
+# Debian/Ubuntu
+apt update
+apt install -y git make xz-utils bzip2 curl python3-minimal ccache
+```
+
+```shell
+# Fedora
+dnf install -y git make xz bzip2 which ccache
+```
+
+### Install [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html)
+
+**NOTE**: Follow the on-screen instructions how to add the SDK to ``PATH``.
+
+```shell
+git clone https://github.com/emscripten-core/emsdk.git /opt/emsdk
+/opt/emsdk/emsdk install latest
+/opt/emsdk/emsdk activate latest
+```
+
+### Optionally: pre-build and cache static libraries
+
+Emscripten SDK provides static builds of core libraries without PIC
+(position-independent code). Python builds with ``dlopen`` support require
+PIC. To populate the build cache, run:
+
+```
+. /opt/emsdk/emsdk_env.sh
+embuilder build --force zlib bzip2
+embuilder build --force --pic \
+    zlib bzip2 libc-mt libdlmalloc-mt libsockets-mt \
+    libstubs libcompiler_rt libcompiler_rt-mt crtbegin libhtml5 \
+    libc++-mt-noexcept libc++abi-mt-noexcept \
+    libal libGL-mt libstubs-debug libc-mt-debug
+```
+
+### Install [WASI-SDK](https://github.com/WebAssembly/wasi-sdk)
+
+**NOTE**: WASI-SDK's clang may show a warning on Fedora:
+``/lib64/libtinfo.so.6: no version information available``,
+[RHBZ#1875587](https://bugzilla.redhat.com/show_bug.cgi?id=1875587).
+
+```shell
+export WASI_VERSION=16
+export WASI_VERSION_FULL=${WASI_VERSION}.0
+curl -sSf -L -O https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
+mkdir -p /opt/wasi-sdk
+tar --strip-components=1 -C /opt/wasi-sdk -xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
+rm -f wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
+```
+
+### Install [wasmtime](https://github.com/bytecodealliance/wasmtime) WASI runtime
+
+**NOTE**: wasmtime 0.37 has a bug. Newer versions should be fine again.
+
+```shell
+curl -sSf -L -o ~/install-wasmtime.sh https://wasmtime.dev/install.sh
+chmod +x ~/install-wasmtime.sh
+~/install-wasmtime.sh --version v0.36.0
+ln -srf -t /usr/local/bin/ ~/.wasmtime/bin/wasmtime
+```
+
+### Install [WASIX](https://github.com/singlestore-labs/wasix)
+
+```shell
+git clone https://github.com/singlestore-labs/wasix.git ~/wasix
+make -C ~/wasix
+mkdir -p /opt/wasix/include /opt/wasix/lib
+cp -R ~/wasix/include/* /opt/wasix/include/
+cp ~/wasix/libwasix.a /opt/wasix/lib/
+```

From fd040fd91727cacabe0d42b2f049cc3d30c7e342 Mon Sep 17 00:00:00 2001
From: Christian Heimes <christian@python.org>
Date: Wed, 15 Jun 2022 14:35:41 +0200
Subject: [PATCH 2/3] Use my tested fork with nicer Makefile

---
 Tools/wasm/README.md | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/Tools/wasm/README.md b/Tools/wasm/README.md
index 4dfd385ee3cda3..38a734b89d5fc3 100644
--- a/Tools/wasm/README.md
+++ b/Tools/wasm/README.md
@@ -374,7 +374,7 @@ Emscripten SDK provides static builds of core libraries without PIC
 (position-independent code). Python builds with ``dlopen`` support require
 PIC. To populate the build cache, run:
 
-```
+```shell
 . /opt/emsdk/emsdk_env.sh
 embuilder build --force zlib bzip2
 embuilder build --force --pic \
@@ -413,9 +413,6 @@ ln -srf -t /usr/local/bin/ ~/.wasmtime/bin/wasmtime
 ### Install [WASIX](https://github.com/singlestore-labs/wasix)
 
 ```shell
-git clone https://github.com/singlestore-labs/wasix.git ~/wasix
-make -C ~/wasix
-mkdir -p /opt/wasix/include /opt/wasix/lib
-cp -R ~/wasix/include/* /opt/wasix/include/
-cp ~/wasix/libwasix.a /opt/wasix/lib/
+git clone -b cpython https://github.com/tiran/wasix.git ~/wasix
+make install -C ~/wasix
 ```

From cec8b059de8aa3e31caca8d16f32b103869525a7 Mon Sep 17 00:00:00 2001
From: Christian Heimes <christian@python.org>
Date: Wed, 15 Jun 2022 20:26:30 +0200
Subject: [PATCH 3/3] Use upstream main for WASIX

Co-authored-by: Brett Cannon <brett@python.org>
---
 Tools/wasm/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Tools/wasm/README.md b/Tools/wasm/README.md
index 38a734b89d5fc3..4a711a6eb56271 100644
--- a/Tools/wasm/README.md
+++ b/Tools/wasm/README.md
@@ -413,6 +413,6 @@ ln -srf -t /usr/local/bin/ ~/.wasmtime/bin/wasmtime
 ### Install [WASIX](https://github.com/singlestore-labs/wasix)
 
 ```shell
-git clone -b cpython https://github.com/tiran/wasix.git ~/wasix
+git clone https://github.com/singlestore-labs/wasix.git ~/wasix
 make install -C ~/wasix
 ```