2020-10-30 20:09:25 +00:00
|
|
|
(building_from_sources)=
|
2021-07-26 23:00:27 +00:00
|
|
|
|
2020-05-08 23:28:44 +00:00
|
|
|
# Building from sources
|
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
```{warning}
|
|
|
|
If you are building the latest development version of Pyodide from the `main`
|
|
|
|
branch, please make sure to follow the build instructions from the dev
|
|
|
|
version of the documentation at
|
|
|
|
[pyodide.org/en/latest/](https://pyodide.org/en/latest/development/building-from-sources.html)
|
|
|
|
```
|
|
|
|
|
|
|
|
Building on any operating system is easiest using the Pyodide Docker image. This approach works
|
|
|
|
with any native operating system as long as Docker is installed. You can also build on your
|
|
|
|
native Linux OS if the correct build prerequisites are installed. Building on MacOS is
|
|
|
|
possible, but there are known issues as of version 0.18 that you will need to work around.
|
|
|
|
It is not possible to build on Windows, but you can use
|
2021-03-14 19:45:04 +00:00
|
|
|
[WSL2](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to create a
|
|
|
|
Linux build environment.
|
2020-05-08 23:28:44 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
## Build instructions
|
|
|
|
|
|
|
|
### Using Docker
|
|
|
|
|
|
|
|
We provide a Debian-based Docker image
|
|
|
|
([`pyodide/pyodide-env`](https://hub.docker.com/r/pyodide/pyodide-env)) on
|
|
|
|
Docker Hub with the dependencies already installed to make it easier to build
|
|
|
|
Pyodide. On top of that we provide
|
|
|
|
a pre-built image
|
|
|
|
([`pyodide/pyodide`](https://hub.docker.com/r/pyodide/pyodide)) which can be
|
|
|
|
used for fast custom and partial builds. Note that building from the non
|
|
|
|
pre-built Docker image is _very_ slow on Mac, building on the host machine
|
|
|
|
is preferred if at all possible.
|
|
|
|
|
2022-01-06 23:47:30 +00:00
|
|
|
```{note}
|
|
|
|
These Docker images are also available from the Github packages at
|
|
|
|
[`github.com/orgs/pyodide/packages`](https://github.com/orgs/pyodide/packages).
|
|
|
|
```
|
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
1. Install Docker
|
|
|
|
|
|
|
|
1. From a git checkout of Pyodide, run `./run_docker` or `./run_docker --pre-built`
|
|
|
|
|
|
|
|
1. Run `make` to build.
|
|
|
|
|
|
|
|
```{note}
|
|
|
|
You can control the resources allocated to the build by setting the env
|
|
|
|
vars `EMSDK_NUM_CORE`, `EMCC_CORES` and `PYODIDE_JOBS` (the default for each is
|
|
|
|
4).
|
|
|
|
```
|
|
|
|
|
|
|
|
If running `make` deterministically stops at some point,
|
|
|
|
increasing the maximum RAM usage available to the docker container might help.
|
|
|
|
(The RAM available to the container is different from the physical RAM capacity of the machine.)
|
|
|
|
Ideally,
|
|
|
|
at least 3 GB of RAM should be available to the docker container to build
|
|
|
|
Pyodide smoothly. These settings can be changed via Docker preferences (see
|
|
|
|
[here](https://stackoverflow.com/questions/44533319/how-to-assign-more-memory-to-docker-container)).
|
|
|
|
|
|
|
|
You can edit the files in the shared `pyodide` source folder on your host
|
|
|
|
machine (outside of Docker), and then repeatedly run `make` inside the Docker
|
|
|
|
environment to test your changes.
|
|
|
|
|
|
|
|
## Using `make`
|
2020-05-20 16:58:43 +00:00
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
Make sure the prerequisites for
|
|
|
|
[emsdk](https://github.com/emscripten-core/emsdk) are installed. Pyodide will
|
|
|
|
build a custom, patched version of emsdk, so there is no need to build it
|
|
|
|
yourself prior.
|
2020-05-19 16:14:56 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
You would need Python 3.9.5 to run the build scripts. To make sure that the
|
|
|
|
correct Python is used during build it is recommended to use a [Python virtual
|
|
|
|
environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment),
|
|
|
|
|
|
|
|
```{tabbed} Linux
|
|
|
|
|
2020-05-19 16:14:56 +00:00
|
|
|
Additional build prerequisites are:
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
- A working native compiler toolchain, enough to build
|
|
|
|
[CPython](https://devguide.python.org/setup/#linux).
|
2020-07-22 18:36:45 +00:00
|
|
|
- CMake
|
|
|
|
- FreeType 2 development libraries to compile Matplotlib.
|
2020-05-19 16:14:56 +00:00
|
|
|
- gfortran (GNU Fortran 95 compiler)
|
|
|
|
- [f2c](http://www.netlib.org/f2c/)
|
2021-07-26 23:00:27 +00:00
|
|
|
- [ccache](https://ccache.samba.org) (optional) _highly_ recommended for much faster rebuilds.
|
2021-11-15 16:22:24 +00:00
|
|
|
- (optional) SWIG to compile NLopt
|
2020-05-19 16:14:56 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
```
|
2021-09-16 20:16:07 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
```{tabbed} MacOS
|
|
|
|
|
|
|
|
To build on MacOS, you need:
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
- [Homebrew](https://brew.sh/) for installing dependencies
|
2021-03-14 19:45:04 +00:00
|
|
|
- System libraries in the root directory (
|
2021-04-06 22:11:00 +00:00
|
|
|
`sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /`
|
2021-03-14 19:45:04 +00:00
|
|
|
should do it, see https://github.com/pyenv/pyenv/issues/1219#issuecomment-428305417)
|
2021-11-15 16:22:24 +00:00
|
|
|
- coreutils for md5sum and other essential Unix utilities (`brew install coreutils`).
|
2020-05-19 16:14:56 +00:00
|
|
|
- cmake (`brew install cmake`)
|
|
|
|
- pkg-config (`brew install pkg-config`)
|
|
|
|
- openssl (`brew install openssl`)
|
|
|
|
- gfortran (`brew cask install gfortran`)
|
2021-03-14 19:45:04 +00:00
|
|
|
- f2c: Install wget (`brew install wget`), and then run the buildf2c script from
|
|
|
|
the root directory (`sudo ./tools/buildf2c`)
|
2021-11-15 16:22:24 +00:00
|
|
|
- It is also recommended installing the GNU patch (`brew install gpatch`), and
|
|
|
|
GNU sed (`brew install gnu-sed`) and [re-defining them temporarily as `patch` and
|
|
|
|
`sed`](https://formulae.brew.sh/formula/gnu-sed).
|
|
|
|
- (optional) SWIG to compile NLopt (`brew install swig`)
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
```{note}
|
|
|
|
If you encounter issues with the requirements, it is useful to check the exact
|
|
|
|
list in the
|
|
|
|
[Dockerfile](https://github.com/pyodide/pyodide/blob/main/Dockerfile) which is
|
|
|
|
tested in the CI.
|
|
|
|
```
|
2020-05-19 16:14:56 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
You can install the Python dependencies from the requirement file at the root of Pyodide folder:
|
|
|
|
`pip install -r requirements.txt`
|
2020-11-08 20:05:38 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
After installing the build prerequisites, run from the command line:
|
2020-05-19 16:14:56 +00:00
|
|
|
|
2021-11-15 16:22:24 +00:00
|
|
|
```bash
|
|
|
|
make
|
|
|
|
```
|
2020-05-08 23:28:44 +00:00
|
|
|
|
2020-10-30 20:09:25 +00:00
|
|
|
(partial-builds)=
|
2021-07-26 23:00:27 +00:00
|
|
|
|
2020-05-08 23:28:44 +00:00
|
|
|
## Partial builds
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
To build a subset of available packages in Pyodide, set the environment variable
|
|
|
|
`PYODIDE_PACKAGES` to a comma separated list of packages. For instance,
|
2020-05-08 23:28:44 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
PYODIDE_PACKAGES="toolz,attrs" make
|
|
|
|
```
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
Dependencies of the listed packages will be built automatically as well. The
|
|
|
|
package names must match the folder names in `packages/` exactly; in particular
|
2021-11-14 20:47:49 +00:00
|
|
|
they are case-sensitive.
|
2020-05-08 23:46:59 +00:00
|
|
|
|
2021-09-02 20:19:23 +00:00
|
|
|
If `PYODIDE_PACKAGES` is not set, a minimal set of packages necessairy to run
|
|
|
|
the core test suite is installed, including "micropip", "pyparsing", "pytz",
|
2021-09-21 06:47:48 +00:00
|
|
|
"packaging", "Jinja2", "regex". This is equivalent to setting
|
|
|
|
`PYODIDE_PACKAGES='core'`
|
2021-09-02 20:19:23 +00:00
|
|
|
meta-package. Other supported meta-packages are,
|
|
|
|
|
2021-11-14 20:47:49 +00:00
|
|
|
- "min-scipy-stack": includes the "core" meta-package as well as some
|
2021-09-02 20:19:23 +00:00
|
|
|
core packages from the scientific python stack and their dependencies:
|
|
|
|
"numpy", "scipy", "pandas", "matplotlib", "scikit-learn", "joblib",
|
|
|
|
"pytest". This option is non exaustive and is mainly intended to make build
|
|
|
|
faster while testing a diverse set of scientific packages.
|
|
|
|
- "\*" builds all packages
|
|
|
|
|
|
|
|
micropip and distutils are always automatically included.
|
2020-05-09 10:39:05 +00:00
|
|
|
|
2020-07-13 19:46:20 +00:00
|
|
|
## Environment variables
|
2020-06-28 13:51:46 +00:00
|
|
|
|
2021-08-03 19:34:14 +00:00
|
|
|
The following environment variables additionally impact the build:
|
2021-07-26 23:00:27 +00:00
|
|
|
|
|
|
|
- `PYODIDE_JOBS`: the `-j` option passed to the `emmake make` command when
|
|
|
|
applicable for parallel compilation. Default: 3.
|
|
|
|
- `PYODIDE_BASE_URL`: Base URL where Pyodide packages are deployed. It must end
|
|
|
|
with a trailing `/`. Default: `./` to load Pyodide packages from the same
|
|
|
|
base URL path as where `pyodide.js` is located. Example:
|
2022-01-10 23:44:13 +00:00
|
|
|
`https://cdn.jsdelivr.net/pyodide/v0.19.0/full/`
|
2021-07-26 23:00:27 +00:00
|
|
|
- `EXTRA_CFLAGS` : Add extra compilation flags.
|
|
|
|
- `EXTRA_LDFLAGS` : Add extra linker flags.
|
2021-03-14 19:45:04 +00:00
|
|
|
|
|
|
|
Setting `EXTRA_CFLAGS="-D DEBUG_F"` provides detailed diagnostic information
|
2021-11-14 20:47:49 +00:00
|
|
|
whenever error branches are taken inside the Pyodide core code. These error
|
2021-03-14 19:45:04 +00:00
|
|
|
messages are frequently helpful even when the problem is a fatal configuration
|
|
|
|
problem and Pyodide cannot even be initialized. These error branches occur also
|
|
|
|
in correctly working code, but they are relatively uncommon so in practice the
|
|
|
|
amount of noise generated isn't too large. The shorthand `make debug`
|
|
|
|
automatically sets this flag.
|
|
|
|
|
|
|
|
In certain cases, setting `EXTRA_LDFLAGS="-s ASSERTIONS=1` or `ASSERTIONS=2` can
|
|
|
|
also be helpful, but this slows down the linking and the runtime speed of
|
|
|
|
Pyodide a lot and generates a large amount of noise in the console.
|