2020-10-30 20:09:25 +00:00
|
|
|
(building_from_sources)=
|
2020-05-08 23:28:44 +00:00
|
|
|
# Building from sources
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
Building is easiest on Linux and relatively straightforward on Mac. For Windows,
|
|
|
|
we currently recommend using the Docker image (described below) to build
|
|
|
|
Pyodide. Another option for building on Windows is to use
|
|
|
|
[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
|
|
|
|
2020-05-20 16:58:43 +00:00
|
|
|
## Build using `make`
|
|
|
|
|
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
|
|
|
|
|
|
|
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-07 14:21:33 +00:00
|
|
|
- A native Python 3.8 to run the build scripts.
|
2020-07-22 18:36:45 +00:00
|
|
|
- CMake
|
2020-05-19 16:14:56 +00:00
|
|
|
- PyYAML
|
2020-07-22 18:36:45 +00:00
|
|
|
- FreeType 2 development libraries to compile Matplotlib.
|
2020-12-28 01:17:47 +00:00
|
|
|
- Cython to compile SciPy
|
2021-01-07 18:22:38 +00:00
|
|
|
- SWIG to compile NLopt
|
2020-05-19 16:14:56 +00:00
|
|
|
- gfortran (GNU Fortran 95 compiler)
|
|
|
|
- [f2c](http://www.netlib.org/f2c/)
|
|
|
|
- [ccache](https://ccache.samba.org) (optional) *highly* recommended for much faster rebuilds.
|
|
|
|
|
|
|
|
On Mac, you will also need:
|
|
|
|
|
|
|
|
- [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)
|
2020-05-19 16:14:56 +00:00
|
|
|
- coreutils for md5sum and other essential Unix utilities (`brew install coreutils`)
|
|
|
|
- cmake (`brew install cmake`)
|
2020-12-28 01:17:47 +00:00
|
|
|
- Cython to compile SciPy (`brew install cython`)
|
2021-01-07 18:22:38 +00:00
|
|
|
- SWIG to compile NLopt (`brew install swig`)
|
2020-05-19 16:14:56 +00:00
|
|
|
- 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`)
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
After installing the build prerequisites, run from the command line:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
make
|
|
|
|
```
|
|
|
|
|
2020-05-20 16:58:43 +00:00
|
|
|
## Using Docker
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
We provide a Debian-based Docker image on Docker Hub with the dependencies
|
2021-03-14 19:45:04 +00:00
|
|
|
already installed to make it easier to build Pyodide. On top of that we provide
|
|
|
|
a pre-built image which can be used for fast custom and partial builds of
|
2021-04-06 22:11:00 +00:00
|
|
|
Pyodide. Note that building from the non pre-built the Docker image is *very*
|
2021-03-14 19:45:04 +00:00
|
|
|
slow on Mac, building on the host machine is preferred if at all possible.
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
1. Install Docker
|
|
|
|
|
2020-11-08 20:05:38 +00:00
|
|
|
2. From a git checkout of Pyodide, run `./run_docker` or `./run_docker --pre-built`
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
3. Run `make` to build.
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
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).
|
2020-11-08 20:05:38 +00:00
|
|
|
|
|
|
|
|
2021-03-14 19:45:04 +00:00
|
|
|
If running ``make`` deterministically stops at one point in each subsequent try,
|
|
|
|
increasing the maximum RAM usage available to the docker container might help
|
|
|
|
[This is different from the physical RAM capacity inside the system]. 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)).
|
2020-05-19 16:14:56 +00:00
|
|
|
|
|
|
|
You can edit the files in your source checkout on your host machine, and then
|
|
|
|
repeatedly run `make` inside the Docker environment to test your changes.
|
2020-05-08 23:28:44 +00:00
|
|
|
|
2020-10-30 20:09:25 +00:00
|
|
|
(partial-builds)=
|
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
|
|
|
|
they are case sensitive.
|
2020-05-08 23:46:59 +00:00
|
|
|
|
2021-03-03 08:11:50 +00:00
|
|
|
To build a minimal version of Pyodide, set `PYODIDE_PACKAGES="micropip"`. The
|
2020-12-10 19:37:08 +00:00
|
|
|
packages micropip and distutils are always automatically included (but an empty
|
2021-03-14 19:45:04 +00:00
|
|
|
`PYODIDE_PACKAGES` is interpreted as unset). As a shorthand for this, one can
|
|
|
|
say `make minimal`.
|
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
|
|
|
|
|
|
|
Following environment variables additionally impact the build,
|
2021-03-14 19:45:04 +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:
|
2020-12-18 12:23:45 +00:00
|
|
|
`https://cdn.jsdelivr.net/pyodide/dev/full/`
|
2021-03-14 19:45:04 +00:00
|
|
|
- `EXTRA_CFLAGS` : Add extra compilation flags.
|
|
|
|
- `EXTRA_LDFLAGS` : Add extra linker flags.
|
|
|
|
|
|
|
|
Setting `EXTRA_CFLAGS="-D DEBUG_F"` provides detailed diagnostic information
|
|
|
|
whenever error branches are taken inside of the Pyodide core code. These error
|
|
|
|
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.
|