Skip to content

Commit f67335b

Browse files
authored
Minor improvements to the Emscripten instructions (#1795)
* Minor improvements to the Emscripten instructions * Remove incorrect statement about ccache * Add note about nvm * link to nvm * Document `--host-runner` argument as alternative to nvm * lint
1 parent 6c41828 commit f67335b

1 file changed

Lines changed: 38 additions & 23 deletions

File tree

getting-started/setup-building.rst

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -522,39 +522,52 @@ The simplest way to build Emscripten is to run:
522522

523523
.. code-block:: sh
524524
525-
python3 Platforms/emscripten build all --emsdk-cache=./cross-build/emsdk
525+
export EMSDK_CACHE=$PWD/cross-build/emsdk
526+
python3 Platforms/emscripten install-emscripten
527+
python3 Platforms/emscripten build all
526528
527-
This will:
529+
``install-emscripten`` downloads and installs the version of the Emscripten SDK
530+
required, placing it in the ``EMSDK_CACHE`` directory.
531+
``build all`` will:
528532

529533
1. Build a copy of Python that can run on the host machine (the "build" python);
530-
2. Download a copy of the Emscripten SDK matching the version required by the
531-
version of Python being compiled;
532-
3. Ensure that a required version of Node is installed;
533-
4. Download the code for all the binary dependencies of Python (such as
534-
``libFFI`` and ``xz``), and compile them for Emscripten; and
535-
5. Build a copy of Python that can run on Emscripten (the "host" python).
536-
537-
If you omit the ``--emsdk-cache`` environment variable, the build script will
534+
2. Use nvm_ to ensure that the needed version of Node is installed;
535+
3. Download the code for all the binary dependencies of Python (such as
536+
``libffi`` and ``mpdecimal``), and compile them for Emscripten; and
537+
4. Build a copy of Python that can run on Emscripten (the "host" python).
538+
539+
The built binary dependencies are cached inside the Emscripten cache directory.
540+
Once built for a given Emscripten version, they will not be rebuilt on
541+
subsequent runs unless there is a change in the version or build script for the
542+
dependency.
543+
544+
It is assumed that nvm_ is installed in ``${HOME}/.nvm``. If you don't have nvm
545+
installed or don't want to use it, you can pass ``--host-runner node`` to the
546+
``build`` command. The argument should either be the name of an executable that
547+
can be found on the ``PATH`` or a relative or absolute path to an executable.
548+
549+
If you omit the ``EMSDK_CACHE`` environment variable, the build script will
538550
assume that the current environment has the Emscripten tools available. You are
539551
responsible for downloading and activating those tools in your environment. The
540552
version of Emscripten and Node that is required to build Python is defined in
541553
the :cpy-file:`Platforms/emscripten/config.toml` configuration file.
542554

543-
There are three environment variables that can be used to control the operation of
555+
There are two environment variables that can be used to control the operation of
544556
the ``Platforms/emscripten`` build script:
545557

546-
* ``EMSDK_CACHE`` controls the location of the emscripten SDK. You can use this instead
547-
environment variable instead of passing the ``--emsdk-cache`` flag.
548-
* ``CACHE_DIR`` defines the location where downloaded artefacts, such
549-
as precompiled ``libFFI`` and ``xz`` binaries, will be stored.
550-
* ``CROSS_BUILD_DIR`` defines the name of the ``cross-build`` directory
551-
that will be used for builds. This can be useful if you need to maintain
552-
builds of multiple versions of Python.
558+
* ``EMSDK_CACHE`` (or the ``--emsdk-cache`` flag) controls the location of the
559+
Emscripten SDK cache directory. You can use this environment variable instead
560+
of passing the ``--emsdk-cache`` flag. When set, the build script will
561+
validate that the required Emscripten version is present in the cache and will
562+
exit with an error if it is not; run ``install-emscripten`` to populate the
563+
cache.
564+
* ``CROSS_BUILD_DIR`` (or the ``--cross-build-dir`` flag) defines the location
565+
of the ``cross-build`` directory that will be used for builds. This can be
566+
useful if you need to maintain builds of multiple versions of Python
567+
side by side.
553568

554569
It is possible (but not necessary) to enable ``ccache`` for Emscripten builds
555-
by setting the ``EM_COMPILER_WRAPPER`` environment, but this step will only
556-
take effect if it is done **after** ``emsdk_env.sh`` is sourced (otherwise, the
557-
sourced script removes the environment variable):
570+
by setting the ``EM_COMPILER_WRAPPER`` environment variable:
558571

559572
.. code-block:: sh
560573
@@ -571,8 +584,9 @@ Emscripten build in ``cross-build/build`` and
571584
``cross-build/wasm32-emscripten/build/python/``, respectively.
572585

573586
The ``Platforms/emscripten`` script has a number of other entry points that allow for
574-
fine-grained execution of each part of an iOS build; run ``python3
575-
Platforms/emscripten --help`` for more details.
587+
fine-grained execution of each part of an Emscripten build; run
588+
``python3 Platforms/emscripten --help`` for more details.
589+
576590

577591
Once the build is complete, you can run Python code using:
578592

@@ -592,6 +606,7 @@ through web browsers) are available in the CPython repository at
592606

593607
.. _Emscripten: https://emscripten.org/
594608
.. _WebAssembly: https://webassembly.org
609+
.. _nvm: https://github.com/nvm-sh/nvm#intro
595610

596611
Android
597612
-------

0 commit comments

Comments
 (0)