@@ -377,14 +377,15 @@ host/runtime as a *guest*.
377377
378378.. note ::
379379
380- The instructions below assume a Unix-based OS due to cross-compilation for
381- CPython being designed for ``./configure `` / ``make ``.
380+ The instructions below assume a Unix-based OS (including macOS) due to
381+ cross-compilation for CPython being designed for ``./configure `` / ``make ``.
382382
383383To build for WASI, you will need to cross-compile CPython. This requires a C
384384compiler just like building for :ref: `Unix <unix-compiling >` as well as:
385385
3863861. A C compiler that can target WebAssembly (for example, `WASI SDK `_)
3873872. A WASI host/runtime (for example, Wasmtime _)
388+ 3. Python 3.11 or newer to run the build script (``tomllib `` is required)
388389
389390All of this is provided in the WASI :ref: `dev container <using-a-container >`
390391(which you can select as an alternative container when using a
@@ -399,6 +400,49 @@ known to work.
399400 and their versions specified in the container and build scripts are
400401 tested via a :ref: `buildbot <buildbots >`.
401402
403+ Installing prerequisites (Linux)
404+ '''''''''''''''''''''''''''''''''
405+
406+ Install Wasmtime via the `official installer <https://wasmtime.dev >`__ or your
407+ system package manager. Download the `WASI SDK `_ release archive for your
408+ platform, extract it, and set the ``WASI_SDK_PATH `` environment variable:
409+
410+ .. code-block :: shell
411+
412+ export WASI_SDK_PATH=/path/to/wasi-sdk
413+
414+ Installing prerequisites (macOS)
415+ '''''''''''''''''''''''''''''''''
416+
417+ Install Wasmtime via Homebrew:
418+
419+ .. code-block :: shell
420+
421+ brew install wasmtime
422+
423+ Download the `WASI SDK `_ release archive for macOS (``arm64-macos `` for Apple
424+ Silicon, ``x86_64-macos `` for Intel). Before extracting, remove the macOS
425+ quarantine attribute to prevent Gatekeeper from blocking the compiler binaries:
426+
427+ .. code-block :: shell
428+
429+ xattr -d com.apple.quarantine wasi-sdk-* .tar.gz
430+ sudo tar -xzf wasi-sdk-* .tar.gz -C /opt
431+ sudo mv /opt/wasi-sdk-* -macos /opt/wasi-sdk
432+
433+ Then add to your shell profile (e.g. ``~/.zshrc ``):
434+
435+ .. code-block :: shell
436+
437+ export WASI_SDK_PATH=/opt/wasi-sdk
438+
439+ .. note ::
440+
441+ macOS ships with Python 3.9, which is too old to run the build script.
442+ Use a newer Python via Homebrew (``brew install python ``) or
443+ `uv <https://docs.astral.sh/uv/ >`__
444+ (``uv run --python 3.13 -- python3 Platforms/WASI build ... ``).
445+
402446Building for WASI requires doing a cross-build where you have a *build * Python
403447to help produce a WASI build of CPython (technically it's a "host x host"
404448cross-build because the build Python is also the target Python while the host
@@ -407,11 +451,16 @@ to have a version of Python for the build system to use and another that's the
407451build you ultimately care about (that is, the build Python is not meant for use
408452by you directly, only the build system).
409453
410- The easiest way to get a debug build of CPython for WASI is to use the
411- ``Tools/wasm/wasi.py build `` command (which should be run w/ a recent version of
412- Python you have installed on your machine):
454+ The easiest way to get a debug build of CPython for WASI is to run the
455+ following command with Python 3.11 or newer:
413456
414- .. tab :: Python 3.14+
457+ .. tab :: Python 3.15+
458+
459+ .. code-block :: shell
460+
461+ python3 Platforms/WASI build --quiet -- --config-cache --with-pydebug
462+
463+ .. tab :: Python 3.14
415464
416465 .. code-block :: shell
417466
@@ -424,14 +473,22 @@ Python you have installed on your machine):
424473 python3 Tools/wasm/wasi.py build --quiet -- --config-cache --with-pydebug
425474
426475 That single command will configure and build both the build Python and the
427- WASI build in ``cross-build/build `` and ``cross-build/wasm32-wasi ``,
476+ WASI build in ``cross-build/<host-triple> `` and ``cross-build/wasm32-wasip1 ``,
428477respectively.
429478
430479You can also do each configuration and build step separately; the command above
431480is a convenience wrapper around the following commands:
432481
482+ .. tab :: Python 3.15+
483+
484+ .. code-block :: shell
485+
486+ $ python3 Platforms/WASI configure-build-python --quiet -- --config-cache --with-pydebug
487+ $ python3 Platforms/WASI make-build-python --quiet
488+ $ python3 Platforms/WASI configure-host --quiet -- --config-cache
489+ $ python3 Platforms/WASI make-host --quiet
433490
434- .. tab :: Python 3.14+
491+ .. tab :: Python 3.14
435492
436493 .. code-block :: shell
437494
@@ -454,8 +511,8 @@ is a convenience wrapper around the following commands:
454511 The ``configure-host `` command infers the use of ``--with-pydebug `` from the
455512 build Python.
456513
457- Running the separate commands after `` wasi build `` is useful if you, for example ,
458- only want to run the ``make-host `` step after making code changes.
514+ Running the separate commands after the `` build `` subcommand is useful if you,
515+ for example, only want to run the ``make-host `` step after making code changes.
459516
460517Once everything is complete, there will be a
461518``cross-build/wasm32-wasip1/python.sh `` helper file which you can use to run the
0 commit comments